storeManager = $storeManager; $this->productOptions = $productOptions; $this->msrp = $msrp; $this->config = $config; $this->priceCurrency = $priceCurrency; $this->productRepository = $productRepository; $this->msrpPriceCalculator = $msrpPriceCalculator ?: ObjectManager::getInstance()->get(MsrpPriceCalculatorInterface::class); } /** * 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) * @throws \Magento\Framework\Exception\NoSuchEntityException */ 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; } /** * Get Msrp message for price * * @param Product $product * @return string * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function getMsrpPriceMessage($product) { $message = ""; if ($this->canApplyMsrp($product, Type::TYPE_IN_CART)) { $message = __('To see product price, add this item to your cart. You can always remove it later.'); } elseif ($this->canApplyMsrp($product, Type::TYPE_BEFORE_ORDER_CONFIRM)) { $message = __('See price before order confirmation.'); } return $message; } /** * Check is product need gesture to show price * * @param int|Product $product * @return bool * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function isShowPriceOnGesture($product) { return $this->canApplyMsrp($product, Type::TYPE_ON_GESTURE); } /** * Check if we should show MAP proce before order confirmation * * @param int|Product $product * @return bool * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function isShowBeforeOrderConfirm($product) { return $this->canApplyMsrp($product, Type::TYPE_BEFORE_ORDER_CONFIRM); } /** * Check if any MAP price is larger than as low as value. * * @param int|Product $product * @return bool * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function isMinimalPriceLessMsrp($product) { if (is_numeric($product)) { $product = $this->productRepository->getById($product, false, $this->storeManager->getStore()->getId()); } $msrp = $this->msrpPriceCalculator->getMsrpPriceValue($product); $price = $product->getPriceInfo()->getPrice(\Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE); if ($msrp) { $msrp = $this->priceCurrency->convertAndRound($msrp); } return $msrp > $price->getValue(); } }