Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ProductView.php
Go to the documentation of this file.
1 <?php
7 
9 
11 {
15  private $stockRegistry;
16 
20  public function __construct(
21  StockRegistryInterface $stockRegistry
22  ) {
23  $this->stockRegistry = $stockRegistry;
24  }
25 
31  public function afterGetQuantityValidators(
32  \Magento\Catalog\Block\Product\View $block,
33  array $validators
34  ) {
35  $stockItem = $this->stockRegistry->getStockItem(
36  $block->getProduct()->getId(),
37  $block->getProduct()->getStore()->getWebsiteId()
38  );
39 
40  $params = [];
41  $params['minAllowed'] = (float)$stockItem->getMinSaleQty();
42  if ($stockItem->getMaxSaleQty()) {
43  $params['maxAllowed'] = (float)$stockItem->getMaxSaleQty();
44  }
45  if ($stockItem->getQtyIncrements() > 0) {
46  $params['qtyIncrements'] = (float)$stockItem->getQtyIncrements();
47  }
48  $validators['validate-item-quantity'] = $params;
49 
50  return $validators;
51  }
52 }
$block
Definition: block.php:8
__construct(StockRegistryInterface $stockRegistry)
Definition: ProductView.php:20
afterGetQuantityValidators(\Magento\Catalog\Block\Product\View $block, array $validators)
Definition: ProductView.php:31
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18