public function testGetProduct() { $this->assertNotEmpty($this->_block->getProduct()->getId()); $this->assertEquals($this->_product->getId(), $this->_block->getProduct()->getId()); /** @var $objectManager \Magento\TestFramework\ObjectManager */ $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $objectManager->get('Magento\\Framework\\Registry')->unregister('product'); $this->_block->setProductId(1); $this->assertEquals($this->_product->getId(), $this->_block->getProduct()->getId()); }
/** * @param \Magento\Catalog\Block\Product\View $block * @param array $validators * @return array */ public function afterGetQuantityValidators(\Magento\Catalog\Block\Product\View $block, array $validators) { $stockItem = $this->stockRegistry->getStockItem($block->getProduct()->getId(), $block->getProduct()->getStore()->getWebsiteId()); $params = []; $params['minAllowed'] = max((double) $stockItem->getQtyMinAllowed(), 1); if ($stockItem->getQtyMaxAllowed()) { $params['maxAllowed'] = $stockItem->getQtyMaxAllowed(); } if ($stockItem->getQtyIncrements() > 0) { $params['qtyIncrements'] = (double) $stockItem->getQtyIncrements(); } $validators['validate-item-quantity'] = $params; return $validators; }
/** * {@inheritdoc} */ public function getProduct() { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getProduct'); if (!$pluginInfo) { return parent::getProduct(); } else { return $this->___callPlugins('getProduct', func_get_args(), $pluginInfo); } }