/** * {@inheritdoc} */ public function toHtml() { if (!$this->config->isEnabled()) { return ''; } return parent::toHtml(); }
/** * @param \Magento\Catalog\Model\Product $product * @return array */ protected function getVisibilities($product) { /** @var \Magento\Catalog\Model\Product[] $collection */ $collection = $product->getTypeInstance()->getAssociatedProducts($product) ?: []; $visibilities = []; /** @var \Magento\Catalog\Model\Product $item */ foreach ($collection as $item) { if ($this->msrpData->canApplyMsrp($item)) { $visibilities[] = $item->getMsrpDisplayActualPriceType() == TypePrice::TYPE_USE_CONFIG ? $this->config->getDisplayActualPriceType() : $item->getMsrpDisplayActualPriceType(); } } return $visibilities; }
public function testSetQuoteCanApplyMsrpIfMsrpDisabled() { $quoteId = 100; $eventMock = $this->getMock('\\Magento\\Framework\\Event', ['getQuote'], [], '', false); $quoteMock = $this->getMock('\\Magento\\Quote\\Model\\Quote', ['getAllAddresses', 'getId'], [], '', false); $observerMock = $this->getMock('\\Magento\\Framework\\Event\\Observer', [], [], '', false); $observerMock->expects($this->once())->method('getEvent')->willReturn($eventMock); $eventMock->expects($this->once())->method('getQuote')->willReturn($quoteMock); $this->configMock->expects($this->once())->method('isEnabled')->willReturn(false); $this->msrpMock->expects($this->once())->method('setCanApplyMsrp')->with($quoteId, false); $quoteMock->expects($this->once())->method('getId')->willReturn($quoteId); $this->observer->execute($observerMock); }
/** * Set Quote information about MSRP price enabled * * @param \Magento\Framework\Event\Observer $observer * @return void */ public function execute(\Magento\Framework\Event\Observer $observer) { /** @var $quote \Magento\Quote\Model\Quote */ $quote = $observer->getEvent()->getQuote(); $canApplyMsrp = false; if ($this->config->isEnabled()) { foreach ($quote->getAllAddresses() as $address) { if ($this->canApplyMsrp->isCanApplyMsrp($address)) { $canApplyMsrp = true; break; } } } $this->msrp->setCanApplyMsrp($quote->getId(), $canApplyMsrp); }
/** * @return string */ protected function _toHtml() { /** @var \Magento\Checkout\Block\Cart\AbstractCart $originalBlock */ $originalBlock = $this->getLayout()->getBlock($this->getOriginalBlockName()); $quote = $originalBlock->getQuote(); if (!$quote->hasCanApplyMsrp() && $this->config->isEnabled()) { $quote->collectTotals(); } if ($quote->getCanApplyMsrp()) { $originalBlock->setTemplate(''); return parent::_toHtml(); } else { return ''; } }
/** * @param bool $isMsrpEnabled * @param bool $canApplyMsrp * @dataProvider setQuoteCanApplyMsrpDataProvider */ public function testSetQuoteCanApplyMsrp($isMsrpEnabled, $canApplyMsrp) { $eventMock = $this->getMockBuilder('Magento\\Framework\\Event')->disableOriginalConstructor()->setMethods(['getQuote'])->getMock(); $quoteMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote')->disableOriginalConstructor()->setMethods(['__wakeup', 'setCanApplyMsrp', 'getAllAddresses'])->getMock(); $observerMock = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock(); $observerMock->expects($this->once())->method('getEvent')->will($this->returnValue($eventMock)); $eventMock->expects($this->once())->method('getQuote')->will($this->returnValue($quoteMock)); $this->configMock->expects($this->once())->method('isEnabled')->will($this->returnValue($isMsrpEnabled)); $quoteMock->expects($this->once())->method('setCanApplyMsrp')->with($canApplyMsrp); $addressMock1 = $this->getMockBuilder('Magento\\Customer\\Model\\Address\\AbstractAddress')->disableOriginalConstructor()->setMethods(['__wakeup'])->getMockForAbstractClass(); $addressMock1->setCanApplyMsrp($canApplyMsrp); $addressMock2 = $this->getMockBuilder('Magento\\Customer\\Model\\Address\\AbstractAddress')->disableOriginalConstructor()->setMethods(['__wakeup'])->getMockForAbstractClass(); $addressMock2->setCanApplyMsrp(false); $quoteMock->expects($this->any())->method('getAllAddresses')->will($this->returnValue([$addressMock1, $addressMock2])); $this->observer->execute($observerMock); }
/** * Customize msrp display actual price field * * @return $this */ protected function customizeMsrpDisplayActualPrice() { $msrpDisplayPath = $this->getElementArrayPath($this->meta, self::FIELD_MSRP_DISPLAY_ACTUAL_PRICE); if ($msrpDisplayPath) { if (!$this->msrpConfig->isEnabled()) { $this->meta = $this->arrayManager->remove($this->arrayManager->slicePath($msrpDisplayPath, 0, -2), $this->meta); } } return $this; }
/** * Customize msrp display actual price field * * @return $this */ protected function customizeMsrpDisplayActualPrice() { $msrpDisplayPath = $this->arrayManager->findPath(static::FIELD_MSRP_DISPLAY_ACTUAL_PRICE, $this->meta, null, 'children'); if ($msrpDisplayPath) { if (!$this->msrpConfig->isEnabled()) { $this->meta = $this->arrayManager->remove($this->arrayManager->slicePath($msrpDisplayPath, 0, -2), $this->meta); } } return $this; }
/** * Check if can apply Minimum Advertise price to product * in specific visibility * * @param int|Product $product * @param int|null $visibility Check displaying price in concrete place (by default generally) * @return bool * * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function canApplyMsrp($product, $visibility = null) { if (!$this->config->isEnabled()) { return false; } if (is_numeric($product)) { $product = $this->productRepository->getById($product, false, $this->storeManager->getStore()->getId()); } $result = $this->msrp->canApplyToProduct($product); if ($result && $visibility !== null) { $productPriceVisibility = $product->getMsrpDisplayActualPriceType(); if ($productPriceVisibility == Type\Price::TYPE_USE_CONFIG) { $productPriceVisibility = $this->config->getDisplayActualPriceType(); } $result = $productPriceVisibility == $visibility; } if ($product->getTypeInstance()->isComposite($product) && (!$result || $visibility !== null)) { $isEnabledInOptions = $this->productOptions->isEnabled($product, $visibility); if ($isEnabledInOptions !== null) { $result = $isEnabledInOptions; } } return $result; }
public function testIsMsrpEnabled() { $this->config->expects($this->once())->method('isEnabled')->will($this->returnValue(true)); $this->assertTrue($this->object->isMsrpEnabled()); }
/** * Check if Minimum Advertised Price is enabled * * @return bool */ public function isMsrpEnabled() { return $this->config->isEnabled(); }
/** * @return string */ public function getExplanationMessageWhatsThis() { return $this->config->getExplanationMessageWhatsThis(); }