Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
Data Class Reference
Inheritance diagram for Data:
AbstractHelper

Public Member Functions

 __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)
 
 canApplyMsrp ($product, $visibility=null)
 
 getMsrpPriceMessage ($product)
 
 isShowPriceOnGesture ($product)
 
 isShowBeforeOrderConfirm ($product)
 
 isMinimalPriceLessMsrp ($product)
 
- Public Member Functions inherited from AbstractHelper
 __construct (Context $context)
 
 isModuleOutputEnabled ($moduleName=null)
 

Protected Attributes

 $storeManager
 
 $productOptions
 
 $config
 
 $priceCurrency
 
 $productRepository
 
- Protected Attributes inherited from AbstractHelper
 $_moduleName
 
 $_request
 
 $_moduleManager
 
 $_logger
 
 $_urlBuilder
 
 $_httpHeader
 
 $_eventManager
 
 $_remoteAddress
 
 $urlEncoder
 
 $urlDecoder
 
 $scopeConfig
 
 $_cacheConfig
 

Additional Inherited Members

- Protected Member Functions inherited from AbstractHelper
 _getRequest ()
 
 _getModuleName ()
 
 _getUrl ($route, $params=[])
 

Detailed Description

Msrp data helper

Definition at line 18 of file Data.php.

Constructor & Destructor Documentation

◆ __construct()

__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 
)
Parameters
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 at line 54 of file Data.php.

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  }

Member Function Documentation

◆ canApplyMsrp()

canApplyMsrp (   $product,
  $visibility = null 
)

Check if can apply Minimum Advertise price to product in specific visibility

Parameters
int | Product$product
int | null$visibilityCheck displaying price in concrete place (by default generally)
Returns
bool

@SuppressWarnings(PHPMD.CyclomaticComplexity)

Definition at line 82 of file Data.php.

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  }

◆ getMsrpPriceMessage()

getMsrpPriceMessage (   $product)

Get Msrp message for price

Parameters
Product$product
Returns
string

Definition at line 115 of file Data.php.

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  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
canApplyMsrp($product, $visibility=null)
Definition: Data.php:82
__()
Definition: __.php:13
$message

◆ isMinimalPriceLessMsrp()

isMinimalPriceLessMsrp (   $product)
Parameters
int | Product$product
Returns
bool|float

Definition at line 150 of file Data.php.

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  }
$price

◆ isShowBeforeOrderConfirm()

isShowBeforeOrderConfirm (   $product)
Parameters
int | Product$product
Returns
bool

Definition at line 141 of file Data.php.

142  {
143  return $this->canApplyMsrp($product, Type::TYPE_BEFORE_ORDER_CONFIRM);
144  }
canApplyMsrp($product, $visibility=null)
Definition: Data.php:82

◆ isShowPriceOnGesture()

isShowPriceOnGesture (   $product)

Check is product need gesture to show price

Parameters
int | Product$product
Returns
bool

Definition at line 132 of file Data.php.

133  {
134  return $this->canApplyMsrp($product, Type::TYPE_ON_GESTURE);
135  }
canApplyMsrp($product, $visibility=null)
Definition: Data.php:82

Field Documentation

◆ $config

$config
protected

Definition at line 33 of file Data.php.

◆ $priceCurrency

$priceCurrency
protected

Definition at line 38 of file Data.php.

◆ $productOptions

$productOptions
protected

Definition at line 28 of file Data.php.

◆ $productRepository

$productRepository
protected

Definition at line 43 of file Data.php.

◆ $storeManager

$storeManager
protected

Definition at line 23 of file Data.php.


The documentation for this class was generated from the following file: