6 declare(strict_types=1);
28 private $resourceConnection;
33 private $getProductTypesBySkus;
38 private $isSourceItemManagementAllowedForProductType;
43 private $defaultSourceProvider;
48 private $setDataToLegacyStockItem;
53 private $bulkZeroLegacyStockItem;
73 $this->getProductTypesBySkus = $getProductTypesBySkus;
74 $this->isSourceItemManagementAllowedForProductType = $isSourceItemManagementAllowedForProductType;
76 $this->setDataToLegacyStockItem = $setDataToLegacyStockItem;
77 $this->bulkZeroLegacyStockItem = $bulkZeroLegacyStockItem;
85 private function getSourceItemData(
string $sku,
string $source): ?array
87 $connection = $this->resourceConnection->getConnection();
108 private function transferInventory(
110 string $originSource,
111 string $destinationSource
113 $connection = $this->resourceConnection->getConnection();
116 $orgSourceItem = $this->getSourceItemData($sku, $originSource);
117 $dstSourceItem = $this->getSourceItemData($sku, $destinationSource);
122 $finalQuantity = $orgSourceItemQty + $dstSourceItemQty;
124 if ($orgSourceItem !==
null) {
126 }
elseif ($dstSourceItemQty !==
null) {
137 if ($dstSourceItem ===
null) {
142 }
elseif ($orgSourceItem !==
null) {
150 if ($destinationSource === $this->defaultSourceProvider->getCode()) {
151 $this->setDataToLegacyStockItem->execute($sku, $finalQuantity,
$status);
161 private function clearSource(array
$skus,
string $source,
bool $unassign)
163 $connection = $this->resourceConnection->getConnection();
182 if (
$source === $this->defaultSourceProvider->getCode()) {
183 $this->bulkZeroLegacyStockItem->execute(
$skus);
198 string $originSource,
199 string $destinationSource,
200 bool $unassignFromOrigin
202 $connection = $this->resourceConnection->getConnection();
203 $types = $this->getProductTypesBySkus->execute(
$skus);
206 foreach ($types as $sku =>
$type) {
207 if ($this->isSourceItemManagementAllowedForProductType->execute(
$type)) {
208 $this->transferInventory($sku, $originSource, $destinationSource);
212 $this->clearSource(
$skus, $originSource, $unassignFromOrigin);
elseif(isset( $params[ 'redirect_parent']))
foreach($websiteCodes as $websiteCode) $skus
__construct(ResourceConnection $resourceConnection, GetProductTypesBySkusInterface $getProductTypesBySkus, IsSourceItemManagementAllowedForProductTypeInterface $isSourceItemManagementAllowedForProductType, DefaultSourceProviderInterface $defaultSourceProvider, SetDataToLegacyStockItem $setDataToLegacyStockItem, BulkZeroLegacyStockItem $bulkZeroLegacyStockItem)
const STATUS_OUT_OF_STOCK
const TABLE_NAME_SOURCE_ITEM
execute(array $skus, string $originSource, string $destinationSource, bool $unassignFromOrigin)