示例#1
0
 /**
  * {@inheritdoc}
  */
 public function toHtml()
 {
     if (!$this->config->isEnabled()) {
         return '';
     }
     return parent::toHtml();
 }
 /**
  * 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);
 }
示例#3
0
 /**
  * @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 '';
     }
 }
 /**
  * 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;
 }
示例#5
0
 /**
  * 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;
 }
示例#6
0
 /**
  * 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;
 }
示例#7
0
 /**
  * Check if Minimum Advertised Price is enabled
  *
  * @return bool
  */
 public function isMsrpEnabled()
 {
     return $this->config->isEnabled();
 }