/**
  * @param \Magento\Quote\Model\Quote\Address $address
  * @return bool
  */
 public function isCanApplyMsrp($address)
 {
     $canApplyMsrp = false;
     foreach ($address->getAllItems() as $item) {
         if (!$item->getParentItemId() && $this->msrpHelper->isShowBeforeOrderConfirm($item->getProductId()) && $this->msrpHelper->isMinimalPriceLessMsrp($item->getProductId())) {
             $canApplyMsrp = true;
             break;
         }
     }
     return $canApplyMsrp;
 }
Exemple #2
0
 /**
  * @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 testIsMinimalPriceLessMsrp()
 {
     $msrp = 120;
     $convertedFinalPrice = 200;
     $this->priceCurrencyMock->expects($this->any())->method('convertAndRound')->will($this->returnCallback(function ($arg) {
         return round(2 * $arg, 2);
     }));
     $finalPriceMock = $this->getMockBuilder('\\Magento\\Catalog\\Pricing\\Price\\FinalPrice')->disableOriginalConstructor()->getMock();
     $finalPriceMock->expects($this->any())->method('getValue')->will($this->returnValue($convertedFinalPrice));
     $priceInfoMock = $this->getMockBuilder('\\Magento\\Framework\\Pricing\\PriceInfo\\Base')->disableOriginalConstructor()->getMock();
     $priceInfoMock->expects($this->once())->method('getPrice')->with(\Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE)->will($this->returnValue($finalPriceMock));
     $this->productMock->expects($this->any())->method('getMsrp')->will($this->returnValue($msrp));
     $this->productMock->expects($this->any())->method('getPriceInfo')->will($this->returnValue($priceInfoMock));
     $result = $this->helper->isMinimalPriceLessMsrp($this->productMock);
     $this->assertTrue($result, "isMinimalPriceLessMsrp returned incorrect value");
 }
Exemple #4
0
 /**
  * Collect information about MSRP price enabled
  *
  * @param  \Magento\Quote\Model\Quote\Address $address
  * @return $this
  * @api
  */
 public function collect(\Magento\Quote\Model\Quote\Address $address)
 {
     parent::collect($address);
     $items = $this->_getAddressItems($address);
     if (!count($items)) {
         return $this;
     }
     $canApplyMsrp = false;
     foreach ($items as $item) {
         if (!$item->getParentItemId() && $this->msrpData->isShowBeforeOrderConfirm($item->getProductId()) && $this->msrpData->isMinimalPriceLessMsrp($item->getProductId())) {
             $canApplyMsrp = true;
             break;
         }
     }
     $address->setCanApplyMsrp($canApplyMsrp);
     return $this;
 }
 /**
  * @param \Magento\Catalog\Model\Product $item
  * @return array
  */
 protected function getEntryData(\Magento\Catalog\Model\Product $item)
 {
     $description = '
         <table><tr>
             <td><a href="%s"><img src="%s" alt="" border="0" align="left" height="75" width="75" /></a></td>
             <td style="text-decoration:none;">%s %s</td>
         </tr></table>
     ';
     $specialPrice = '';
     if ($item->getAllowedPriceInRss()) {
         if ($this->msrpHelper->canApplyMsrp($item)) {
             $specialPrice = '<br/><a href="' . $item->getProductUrl() . '">' . __('Click for price') . '</a>';
         } else {
             $special = '';
             if ($item->getUseSpecial()) {
                 $special = '<br />' . __('Special Expires On: %1', $this->formatDate($item->getSpecialToDate(), \IntlDateFormatter::MEDIUM));
             }
             $specialPrice = sprintf('<p>%s %s%s</p>', __('Price: %1', $this->priceCurrency->convertAndFormat($item->getPrice())), __('Special Price: %1', $this->priceCurrency->convertAndFormat($item->getFinalPrice())), $special);
         }
     }
     $description = sprintf($description, $item->getProductUrl(), $this->imageHelper->init($item, 'rss_thumbnail')->getUrl(), $this->outputHelper->productAttribute($item, $item->getDescription(), 'description'), $specialPrice);
     return ['title' => $item->getName(), 'link' => $item->getProductUrl(), 'description' => $description];
 }
 /**
  * {@inheritdoc}
  */
 protected function doGetItemData()
 {
     $imageHelper = $this->imageHelper->init($this->getProductForThumbnail(), 'mini_cart_product_thumbnail');
     return ['options' => $this->getOptionList(), 'qty' => $this->item->getQty() * 1, 'item_id' => $this->item->getId(), 'configure_url' => $this->getConfigureUrl(), 'is_visible_in_site_visibility' => $this->item->getProduct()->isVisibleInSiteVisibility(), 'product_name' => $this->item->getProduct()->getName(), 'product_url' => $this->getProductUrl(), 'product_has_url' => $this->hasProductUrl(), 'product_price' => $this->checkoutHelper->formatPrice($this->item->getCalculationPrice()), 'product_image' => ['src' => $imageHelper->getUrl(), 'alt' => $imageHelper->getLabel(), 'width' => $imageHelper->getWidth(), 'height' => $imageHelper->getHeight()], 'canApplyMsrp' => $this->msrpHelper->isShowBeforeOrderConfirm($this->item->getProduct()) && $this->msrpHelper->isMinimalPriceLessMsrp($this->item->getProduct())];
 }
 /**
  * @param Product $product
  * @return bool|float
  */
 public function isMinimalPriceLessMsrp(Product $product)
 {
     return $this->msrpData->isMinimalPriceLessMsrp($product);
 }