diff --git a/vendor/magento/module-inventory-bundle-import-export/Plugin/Import/Product/UpdateBundleProductsStockItemStatusPlugin.php b/vendor/magento/module-inventory-bundle-import-export/Plugin/Import/Product/UpdateBundleProductsStockItemStatusPlugin.php new file mode 100644 index 00000000000..22d4e5077d7 --- /dev/null +++ b/vendor/magento/module-inventory-bundle-import-export/Plugin/Import/Product/UpdateBundleProductsStockItemStatusPlugin.php @@ -0,0 +1,58 @@ +changeParentStockStatus = $changeParentStockStatus; + $this->isSingleSourceMode = $isSingleSourceMode; + } + + /** + * Allow automatic parent stock update in single source mode only + * + * @param StockItemImporterInterface $subject + * @param mixed $result + * @param array $stockData + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function afterImport( + StockItemImporterInterface $subject, + $result, + array $stockData + ): void { + if ($stockData && $this->isSingleSourceMode->execute()) { + $this->changeParentStockStatus->execute(array_column($stockData, 'product_id')); + } + } +} diff --git a/vendor/magento/module-inventory-bundle-import-export/etc/di.xml b/vendor/magento/module-inventory-bundle-import-export/etc/di.xml index 580c1c9cb14..2e96e75240c 100644 --- a/vendor/magento/module-inventory-bundle-import-export/etc/di.xml +++ b/vendor/magento/module-inventory-bundle-import-export/etc/di.xml @@ -9,4 +9,10 @@ + + + + diff --git a/vendor/magento/module-inventory-bundle-product/Plugin/InventoryApi/UpdateParentStockStatusInLegacyStockPlugin.php b/vendor/magento/module-inventory-bundle-product/Plugin/InventoryApi/UpdateParentStockStatusInLegacyStockPlugin.php new file mode 100644 index 00000000000..b47f2f96d7d --- /dev/null +++ b/vendor/magento/module-inventory-bundle-product/Plugin/InventoryApi/UpdateParentStockStatusInLegacyStockPlugin.php @@ -0,0 +1,77 @@ +getProductIdsBySkus = $getProductIdsBySkus; + $this->changeParentStockStatus = $changeParentStockStatus; + $this->isSingleSourceMode = $isSingleSourceMode; + } + + /** + * Make bundle product out of stock if all its children out of stock + * + * @param DecrementSourceItemQty $subject + * @param void $result + * @param SourceItemInterface[] $sourceItemDecrementData + * @return void + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @throws NoSuchEntityException + */ + public function afterExecute(DecrementSourceItemQty $subject, $result, array $sourceItemDecrementData): void + { + if (!$this->isSingleSourceMode->execute()) { + return; + } + $productIds = []; + $sourceItems = array_column($sourceItemDecrementData, 'source_item'); + foreach ($sourceItems as $sourceItem) { + $sku = $sourceItem->getSku(); + $productIds[] = (int)$this->getProductIdsBySkus->execute([$sku])[$sku]; + } + if ($productIds) { + $this->changeParentStockStatus->execute($productIds); + } + } +} diff --git a/vendor/magento/module-inventory-bundle-product/etc/di.xml b/vendor/magento/module-inventory-bundle-product/etc/di.xml index 622c345aecd..126e580a598 100644 --- a/vendor/magento/module-inventory-bundle-product/etc/di.xml +++ b/vendor/magento/module-inventory-bundle-product/etc/di.xml @@ -29,4 +29,8 @@ + + + diff --git a/vendor/magento/module-inventory-catalog/etc/di.xml b/vendor/magento/module-inventory-catalog/etc/di.xml index 29bb39faa6f..f72c2c38e79 100644 --- a/vendor/magento/module-inventory-catalog/etc/di.xml +++ b/vendor/magento/module-inventory-catalog/etc/di.xml @@ -24,7 +24,7 @@ + type="Magento\InventoryCatalog\Plugin\InventoryApi\SynchronizeLegacyStockAfterDecrementStockPlugin" sortOrder="50"/> diff --git a/vendor/magento/module-inventory-configurable-product/Plugin/InventoryApi/UpdateParentStockStatusInLegacyStockPlugin.php b/vendor/magento/module-inventory-configurable-product/Plugin/InventoryApi/UpdateParentStockStatusInLegacyStockPlugin.php new file mode 100644 index 00000000000..248fad4af32 --- /dev/null +++ b/vendor/magento/module-inventory-configurable-product/Plugin/InventoryApi/UpdateParentStockStatusInLegacyStockPlugin.php @@ -0,0 +1,74 @@ +getProductIdsBySkus = $getProductIdsBySkus; + $this->changeParentStockStatus = $changeParentStockStatus; + $this->isSingleSourceMode = $isSingleSourceMode; + } + + /** + * Make configurable product out of stock if all its children out of stock + * + * @param DecrementSourceItemQty $subject + * @param void $result + * @param SourceItemInterface[] $sourceItemDecrementData + * @return void + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function afterExecute(DecrementSourceItemQty $subject, $result, array $sourceItemDecrementData): void + { + if ($this->isSingleSourceMode->execute()) { + $productIds = []; + $sourceItems = array_column($sourceItemDecrementData, 'source_item'); + foreach ($sourceItems as $sourceItem) { + $sku = $sourceItem->getSku(); + $productIds[] = (int)$this->getProductIdsBySkus->execute([$sku])[$sku]; + } + if ($productIds) { + $this->changeParentStockStatus->execute($productIds); + } + } + } +} diff --git a/vendor/magento/module-inventory-configurable-product/etc/di.xml b/vendor/magento/module-inventory-configurable-product/etc/di.xml index 69a91c9de8c..58719d4c51a 100644 --- a/vendor/magento/module-inventory-configurable-product/etc/di.xml +++ b/vendor/magento/module-inventory-configurable-product/etc/di.xml @@ -47,4 +47,8 @@ + + + diff --git a/vendor/magento/module-inventory-grouped-product/Plugin/InventoryApi/UpdateParentStockStatusInLegacyStockPlugin.php b/vendor/magento/module-inventory-grouped-product/Plugin/InventoryApi/UpdateParentStockStatusInLegacyStockPlugin.php new file mode 100644 index 00000000000..334b9f11976 --- /dev/null +++ b/vendor/magento/module-inventory-grouped-product/Plugin/InventoryApi/UpdateParentStockStatusInLegacyStockPlugin.php @@ -0,0 +1,96 @@ +getProductIdsBySkus = $getProductIdsBySkus; + $this->changeParentStockStatus = $changeParentStockStatus; + $this->messageManager = $messageManager; + $this->isSingleSourceMode = $isSingleSourceMode; + } + + /** + * Make group product out of stock if all its children out of stock + * + * @param DecrementSourceItemQty $subject + * @param void $result + * @param SourceItemInterface[] $sourceItemDecrementData + * @return void + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @throws NoSuchEntityException + */ + public function afterExecute(DecrementSourceItemQty $subject, $result, array $sourceItemDecrementData): void + { + if (!$this->isSingleSourceMode->execute()) { + return; + } + + $productIds = []; + $sourceItems = array_column($sourceItemDecrementData, 'source_item'); + foreach ($sourceItems as $sourceItem) { + $sku = $sourceItem->getSku(); + $productIds[] = (int)$this->getProductIdsBySkus->execute([$sku])[$sku]; + } + try { + if ($productIds) { + foreach ($productIds as $productId) { + $this->changeParentStockStatus->execute((int)$productId); + } + } + } catch (\Exception $e) { + $this->messageManager->addExceptionMessage( + $e, + __('Something went wrong while updating the product(s) stock status.') + ); + } + } +} diff --git a/vendor/magento/module-inventory-grouped-product/etc/di.xml b/vendor/magento/module-inventory-grouped-product/etc/di.xml index 7375b46ff18..222095ef375 100644 --- a/vendor/magento/module-inventory-grouped-product/etc/di.xml +++ b/vendor/magento/module-inventory-grouped-product/etc/di.xml @@ -13,4 +13,8 @@ + + +