From b0668f01356223bc5c4de9825c4380d23e0089cf Mon Sep 17 00:00:00 2001 From: serhii balko Date: Tue, 20 Mar 2018 17:06:11 +0200 Subject: [PATCH 1/3] MSI: 532: Adapt AdaptAssignStatusToProductPlugin to complex products --- .../AdaptAssignStatusToProductPlugin.php | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/app/code/Magento/InventoryCatalog/Plugin/CatalogInventory/Helper/Stock/AdaptAssignStatusToProductPlugin.php b/app/code/Magento/InventoryCatalog/Plugin/CatalogInventory/Helper/Stock/AdaptAssignStatusToProductPlugin.php index 24058cd8ea55a..4c665a29a0fad 100644 --- a/app/code/Magento/InventoryCatalog/Plugin/CatalogInventory/Helper/Stock/AdaptAssignStatusToProductPlugin.php +++ b/app/code/Magento/InventoryCatalog/Plugin/CatalogInventory/Helper/Stock/AdaptAssignStatusToProductPlugin.php @@ -9,6 +9,7 @@ use Magento\Catalog\Model\Product; use Magento\CatalogInventory\Helper\Stock; +use Magento\InventoryCatalog\Api\DefaultStockProviderInterface; use Magento\InventorySalesApi\Api\IsProductSalableInterface; use Magento\InventoryCatalog\Model\GetStockIdForCurrentWebsite; @@ -27,16 +28,24 @@ class AdaptAssignStatusToProductPlugin */ private $isProductSalable; + /** + * @var DefaultStockProviderInterface + */ + private $defaultStockProvider; + /** * @param GetStockIdForCurrentWebsite $getStockIdForCurrentWebsite * @param IsProductSalableInterface $isProductSalable + * @param DefaultStockProviderInterface $defaultStockProvider */ public function __construct( GetStockIdForCurrentWebsite $getStockIdForCurrentWebsite, - IsProductSalableInterface $isProductSalable + IsProductSalableInterface $isProductSalable, + DefaultStockProviderInterface $defaultStockProvider ) { $this->getStockIdForCurrentWebsite = $getStockIdForCurrentWebsite; $this->isProductSalable = $isProductSalable; + $this->defaultStockProvider = $defaultStockProvider; } /** @@ -53,20 +62,13 @@ public function aroundAssignStatusToProduct( Product $product, $status = null ) { - // TODO: https://github.com/magento-engcom/msi/issues/532 - if ($product->getTypeId() !== \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE - && $product->getTypeId() !== \Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL - ) { - return; + $stockId = $this->getStockIdForCurrentWebsite->execute(); + if ($this->defaultStockProvider->getId() !== $stockId) { + if (null === $status && null !== $product->getSku()) { + $status = (int)$this->isProductSalable->execute($product->getSku(), $stockId); + } } - if (null === $product->getSku()) { - return; - } - if (null === $status) { - $stockId = $this->getStockIdForCurrentWebsite->execute(); - $status = (int)$this->isProductSalable->execute($product->getSku(), $stockId); - } $proceed($product, $status); } } From 08dc0112ffc4082ca771b941f56f01f7a666dec1 Mon Sep 17 00:00:00 2001 From: serhii balko Date: Wed, 21 Mar 2018 09:12:09 +0200 Subject: [PATCH 2/3] MSI: 532: Adapt AdaptAssignStatusToProductPlugin to complex products --- .../Helper/Stock/AdaptAssignStatusToProductPlugin.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/InventoryCatalog/Plugin/CatalogInventory/Helper/Stock/AdaptAssignStatusToProductPlugin.php b/app/code/Magento/InventoryCatalog/Plugin/CatalogInventory/Helper/Stock/AdaptAssignStatusToProductPlugin.php index 4c665a29a0fad..b74e8a2de97d2 100644 --- a/app/code/Magento/InventoryCatalog/Plugin/CatalogInventory/Helper/Stock/AdaptAssignStatusToProductPlugin.php +++ b/app/code/Magento/InventoryCatalog/Plugin/CatalogInventory/Helper/Stock/AdaptAssignStatusToProductPlugin.php @@ -29,8 +29,8 @@ class AdaptAssignStatusToProductPlugin private $isProductSalable; /** - * @var DefaultStockProviderInterface - */ + * @var DefaultStockProviderInterface + */ private $defaultStockProvider; /** From 36e463d382a518103338a320b0f2df9915d6b339 Mon Sep 17 00:00:00 2001 From: Valeriy Nayda Date: Wed, 21 Mar 2018 13:11:08 +0200 Subject: [PATCH 3/3] MSI-532: Adapt AdaptAssignStatusToProductPlugin to complex products --- .../Stock/AdaptAssignStatusToProductPlugin.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/InventoryCatalog/Plugin/CatalogInventory/Helper/Stock/AdaptAssignStatusToProductPlugin.php b/app/code/Magento/InventoryCatalog/Plugin/CatalogInventory/Helper/Stock/AdaptAssignStatusToProductPlugin.php index b74e8a2de97d2..c2d0c0cb5dd38 100644 --- a/app/code/Magento/InventoryCatalog/Plugin/CatalogInventory/Helper/Stock/AdaptAssignStatusToProductPlugin.php +++ b/app/code/Magento/InventoryCatalog/Plugin/CatalogInventory/Helper/Stock/AdaptAssignStatusToProductPlugin.php @@ -54,6 +54,7 @@ public function __construct( * @param Product $product * @param int|null $status * @return void + * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function aroundAssignStatusToProduct( @@ -62,13 +63,15 @@ public function aroundAssignStatusToProduct( Product $product, $status = null ) { - $stockId = $this->getStockIdForCurrentWebsite->execute(); - if ($this->defaultStockProvider->getId() !== $stockId) { - if (null === $status && null !== $product->getSku()) { - $status = (int)$this->isProductSalable->execute($product->getSku(), $stockId); - } + if (null === $product->getSku()) { + return; } + $stockId = $this->getStockIdForCurrentWebsite->execute(); + + if ($this->defaultStockProvider->getId() !== $stockId && null === $status) { + $status = (int)$this->isProductSalable->execute($product->getSku(), $stockId); + } $proceed($product, $status); } }