6 declare(strict_types=1);
13 use Magento\InventoryApi\Api\Data\StockSourceLinkInterfaceFactory;
28 private $searchCriteriaBuilder;
33 private $stockSourceLinkFactory;
38 private $stockSourceLinksSave;
43 private $stockSourceLinksDelete;
48 private $getStockSourceLinks;
53 private $dataObjectHelper;
65 StockSourceLinkInterfaceFactory $stockSourceLinkFactory,
75 $this->getStockSourceLinks = $getStockSourceLinks;
85 public function process(
int $stockId, array
$linksData)
87 $linksForDelete = $this->getAssignedLinks($stockId);
97 $link = $this->stockSourceLinkFactory->create();
101 $this->dataObjectHelper->populateWithArray(
$link,
$linkData, StockSourceLinkInterface::class);
103 $linksForSave[] =
$link;
107 if (count($linksForSave) > 0) {
108 $this->stockSourceLinksSave->execute($linksForSave);
110 if (count($linksForDelete) > 0) {
111 $this->stockSourceLinksDelete->execute($linksForDelete);
121 private function getAssignedLinks(
int $stockId): array
__construct(SearchCriteriaBuilder $searchCriteriaBuilder, StockSourceLinkInterfaceFactory $stockSourceLinkFactory, StockSourceLinksSaveInterface $stockSourceLinksSave, StockSourceLinksDeleteInterface $stockSourceLinksDelete, GetStockSourceLinksInterface $getStockSourceLinks, DataObjectHelper $dataObjectHelper)