Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Data.php
Go to the documentation of this file.
1 <?php
7 
14 
18 class Data extends AbstractHelper
19 {
23  protected $storeManager;
24 
28  protected $productOptions;
29 
33  protected $config;
34 
38  protected $priceCurrency;
39 
43  protected $productRepository;
44 
54  public function __construct(
55  Context $context,
57  \Magento\Msrp\Model\Product\Options $productOptions,
58  \Magento\Msrp\Model\Msrp $msrp,
59  \Magento\Msrp\Model\Config $config,
62  ) {
63  parent::__construct($context);
64  $this->storeManager = $storeManager;
65  $this->productOptions = $productOptions;
66  $this->msrp = $msrp;
67  $this->config = $config;
68  $this->priceCurrency = $priceCurrency;
69  $this->productRepository = $productRepository;
70  }
71 
82  public function canApplyMsrp($product, $visibility = null)
83  {
84  if (!$this->config->isEnabled()) {
85  return false;
86  }
87  if (is_numeric($product)) {
88  $product = $this->productRepository->getById($product, false, $this->storeManager->getStore()->getId());
89  }
90  $result = $this->msrp->canApplyToProduct($product);
91  if ($result && $visibility !== null) {
92  $productPriceVisibility = $product->getMsrpDisplayActualPriceType();
93  if ($productPriceVisibility == Type\Price::TYPE_USE_CONFIG) {
94  $productPriceVisibility = $this->config->getDisplayActualPriceType();
95  }
96  $result = $productPriceVisibility == $visibility;
97  }
98 
99  if ($product->getTypeInstance()->isComposite($product) && (!$result || $visibility !== null)) {
100  $isEnabledInOptions = $this->productOptions->isEnabled($product, $visibility);
101  if ($isEnabledInOptions !== null) {
102  $result = $isEnabledInOptions;
103  }
104  }
105 
106  return $result;
107  }
108 
115  public function getMsrpPriceMessage($product)
116  {
117  $message = "";
118  if ($this->canApplyMsrp($product, Type::TYPE_IN_CART)) {
119  $message = __('To see product price, add this item to your cart. You can always remove it later.');
120  } elseif ($this->canApplyMsrp($product, Type::TYPE_BEFORE_ORDER_CONFIRM)) {
121  $message = __('See price before order confirmation.');
122  }
123  return $message;
124  }
125 
133  {
134  return $this->canApplyMsrp($product, Type::TYPE_ON_GESTURE);
135  }
136 
142  {
143  return $this->canApplyMsrp($product, Type::TYPE_BEFORE_ORDER_CONFIRM);
144  }
145 
151  {
152  if (is_numeric($product)) {
153  $product = $this->productRepository->getById($product, false, $this->storeManager->getStore()->getId());
154  }
155  $msrp = $product->getMsrp();
156  $price = $product->getPriceInfo()->getPrice(\Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE);
157  if ($msrp === null) {
159  return false;
160  } else {
161  $msrp = $product->getTypeInstance()->getChildrenMsrp($product);
162  }
163  }
164  if ($msrp) {
165  $msrp = $this->priceCurrency->convertAndRound($msrp);
166  }
167  return $msrp > $price->getValue();
168  }
169 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
getMsrpPriceMessage($product)
Definition: Data.php:115
canApplyMsrp($product, $visibility=null)
Definition: Data.php:82
isMinimalPriceLessMsrp($product)
Definition: Data.php:150
__()
Definition: __.php:13
$price
$message
isShowPriceOnGesture($product)
Definition: Data.php:132
isShowBeforeOrderConfirm($product)
Definition: Data.php:141
__construct(Context $context, StoreManagerInterface $storeManager, \Magento\Msrp\Model\Product\Options $productOptions, \Magento\Msrp\Model\Msrp $msrp, \Magento\Msrp\Model\Config $config, \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency, ProductRepositoryInterface $productRepository)
Definition: Data.php:54