Skip to content

Commit

Permalink
Merge pull request magento#772 from magento-engcom/532
Browse files Browse the repository at this point in the history
MSI: 532: Adapt AdaptAssignStatusToProductPlugin to complex products
  • Loading branch information
Valeriy Nayda authored Mar 27, 2018
2 parents fad57a1 + 55fb404 commit c7a3a18
Showing 1 changed file with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}

/**
Expand All @@ -45,6 +54,7 @@ public function __construct(
* @param Product $product
* @param int|null $status
* @return void
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundAssignStatusToProduct(
Expand All @@ -53,18 +63,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;
}

if (null === $product->getSku()) {
return;
}
if (null === $status) {
$stockId = $this->getStockIdForCurrentWebsite->execute();

$stockId = $this->getStockIdForCurrentWebsite->execute();

if ($this->defaultStockProvider->getId() !== $stockId && null === $status) {
$status = (int)$this->isProductSalable->execute($product->getSku(), $stockId);
}
$proceed($product, $status);
Expand Down

0 comments on commit c7a3a18

Please sign in to comment.