Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AdaptAssignStatusToProductPlugin.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
17 
22 {
26  private $getStockIdForCurrentWebsite;
27 
31  private $isProductSalable;
32 
36  private $defaultStockProvider;
37 
41  private $getProductIdsBySkus;
42 
49  public function __construct(
50  GetStockIdForCurrentWebsite $getStockIdForCurrentWebsite,
51  IsProductSalableInterface $isProductSalable,
52  DefaultStockProviderInterface $defaultStockProvider,
53  GetProductIdsBySkusInterface $getProductIdsBySkus
54  ) {
55  $this->getStockIdForCurrentWebsite = $getStockIdForCurrentWebsite;
56  $this->isProductSalable = $isProductSalable;
57  $this->defaultStockProvider = $defaultStockProvider;
58  $this->getProductIdsBySkus = $getProductIdsBySkus;
59  }
60 
70  public function aroundAssignStatusToProduct(
71  Stock $subject,
72  callable $proceed,
74  $status = null
75  ) {
76  if (null === $product->getSku()) {
77  return;
78  }
79 
80  try {
81  $this->getProductIdsBySkus->execute([$product->getSku()]);
82 
83  if (null === $status) {
84  $stockId = $this->getStockIdForCurrentWebsite->execute();
85  $status = (int)$this->isProductSalable->execute($product->getSku(), $stockId);
86  }
87 
88  $proceed($product, $status);
89  } catch (NoSuchEntityException $e) {
90  return;
91  }
92  }
93 }
__construct(GetStockIdForCurrentWebsite $getStockIdForCurrentWebsite, IsProductSalableInterface $isProductSalable, DefaultStockProviderInterface $defaultStockProvider, GetProductIdsBySkusInterface $getProductIdsBySkus)
$status
Definition: order_status.php:8