Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ConfiguredPriceBox.php
Go to the documentation of this file.
1 <?php
8 
21 
26 {
30  private $configuredPriceSelection;
31 
42  public function __construct(
43  Context $context,
47  array $data = [],
48  SalableResolverInterface $salableResolver = null,
49  MinimalPriceCalculatorInterface $minimalPriceCalculator = null,
50  ConfiguredPriceSelection $configuredPriceSelection = null
51  ) {
52  $this->configuredPriceSelection = $configuredPriceSelection
54  ->get(ConfiguredPriceSelection::class);
55  parent::__construct(
56  $context,
58  $price,
60  $data,
61  $salableResolver,
62  $minimalPriceCalculator
63  );
64  }
65 
71  protected function _prepareLayout()
72  {
74  $price = $this->getPrice();
76  $renderBlock = $this->getRenderBlock();
77  if ($renderBlock && $renderBlock->getItem() instanceof ItemInterface) {
78  $price->setItem($renderBlock->getItem());
79  } elseif ($renderBlock
80  && $renderBlock->getParentBlock()
81  && $renderBlock->getParentBlock()->getItem() instanceof ItemInterface
82  ) {
83  $price->setItem($renderBlock->getParentBlock()->getItem());
84  }
85  return parent::_prepareLayout();
86  }
87 
91  public function getPriceType($priceCode)
92  {
93  $price = $this->saleableItem->getPriceInfo()->getPrice($priceCode);
94  $item = $this->getData('item');
95  if ($price instanceof ConfiguredPriceInterface
96  && $item instanceof ItemInterface
97  ) {
98  $price->setItem($item);
99  }
100 
101  return $price;
102  }
103 
107  public function getConfiguredPrice(): PriceInterface
108  {
110  $configuredPrice = $this->getPrice();
111  if (empty($this->configuredPriceSelection->getSelectionPriceList($configuredPrice))) {
112  // If there was no selection we must show minimal regular price
113  return $this->getSaleableItem()->getPriceInfo()->getPrice(FinalPrice::PRICE_CODE);
114  }
115 
116  return $configuredPrice;
117  }
118 
122  public function getConfiguredRegularPrice(): PriceInterface
123  {
125  $configuredPrice = $this->getPriceType(ConfiguredPriceInterface::CONFIGURED_REGULAR_PRICE_CODE);
126  if (empty($this->configuredPriceSelection->getSelectionPriceList($configuredPrice))) {
127  // If there was no selection we must show minimal regular price
128  return $this->getSaleableItem()->getPriceInfo()->getPrice(RegularPrice::PRICE_CODE);
129  }
130 
131  return $configuredPrice;
132  }
133 
139  public function hasSpecialPrice(): bool
140  {
141  if ($this->price->getPriceCode() == ConfiguredPriceInterface::CONFIGURED_PRICE_CODE) {
142  $displayRegularPrice = $this->getConfiguredRegularPrice()->getAmount()->getValue();
143  $displayFinalPrice = $this->getConfiguredPrice()->getAmount()->getValue();
144 
145  return $displayFinalPrice < $displayRegularPrice;
146  }
147 
148  return parent::hasSpecialPrice();
149  }
150 }
getData($key='', $index=null)
Definition: DataObject.php:119
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__construct(Context $context, SaleableInterface $saleableItem, PriceInterface $price, RendererPool $rendererPool, array $data=[], SalableResolverInterface $salableResolver=null, MinimalPriceCalculatorInterface $minimalPriceCalculator=null, ConfiguredPriceSelection $configuredPriceSelection=null)
$configuredPrice