Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AdaptGetProductStockStatusBySkuPlugin.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
15 
20 {
24  private $isProductSalable;
25 
29  private $storeManager;
30 
34  private $stockResolver;
35 
41  public function __construct(
42  IsProductSalableInterface $isProductSalable,
43  StoreManagerInterface $storeManager,
44  StockResolverInterface $stockResolver
45  ) {
46  $this->isProductSalable = $isProductSalable;
47  $this->storeManager = $storeManager;
48  $this->stockResolver = $stockResolver;
49  }
50 
60  StockRegistryInterface $subject,
61  callable $proceed,
62  $productSku,
63  $scopeId = null
64  ): int {
65  $websiteCode = null === $scopeId
66  ? $this->storeManager->getWebsite()->getCode()
67  : $this->storeManager->getWebsite($scopeId)->getCode();
68  $stockId = $this->stockResolver->execute(SalesChannelInterface::TYPE_WEBSITE, $websiteCode)->getStockId();
69 
70  return (int)$this->isProductSalable->execute($productSku, $stockId);
71  }
72 }
$storeManager
__construct(IsProductSalableInterface $isProductSalable, StoreManagerInterface $storeManager, StockResolverInterface $stockResolver)
aroundGetProductStockStatusBySku(StockRegistryInterface $subject, callable $proceed, $productSku, $scopeId=null)
if(!isset($_GET['website_code'])) $websiteCode
Definition: website.php:11