Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
FinalPriceBox.php
Go to the documentation of this file.
1 <?php
7 
19 
20 class FinalPriceBox extends \Magento\Catalog\Pricing\Render\FinalPriceBox
21 {
25  private $lowestPriceOptionsProvider;
26 
39  public function __construct(
40  Context $context,
44  ConfigurableOptionsProviderInterface $configurableOptionsProvider,
45  array $data = [],
46  LowestPriceOptionsProviderInterface $lowestPriceOptionsProvider = null,
47  SalableResolverInterface $salableResolver = null,
48  MinimalPriceCalculatorInterface $minimalPriceCalculator = null
49  ) {
50  parent::__construct(
51  $context,
53  $price,
55  $data,
56  $salableResolver,
57  $minimalPriceCalculator
58  );
59  $this->lowestPriceOptionsProvider = $lowestPriceOptionsProvider ?:
60  ObjectManager::getInstance()->get(LowestPriceOptionsProviderInterface::class);
61  }
62 
68  public function hasSpecialPrice()
69  {
70  $product = $this->getSaleableItem();
71  foreach ($this->lowestPriceOptionsProvider->getProducts($product) as $subProduct) {
72  $regularPrice = $subProduct->getPriceInfo()->getPrice(RegularPrice::PRICE_CODE)->getValue();
73  $finalPrice = $subProduct->getPriceInfo()->getPrice(FinalPrice::PRICE_CODE)->getValue();
74  if ($finalPrice < $regularPrice) {
75  return true;
76  }
77  }
78  return false;
79  }
80 }
__construct(Context $context, SaleableInterface $saleableItem, PriceInterface $price, RendererPool $rendererPool, ConfigurableOptionsProviderInterface $configurableOptionsProvider, array $data=[], LowestPriceOptionsProviderInterface $lowestPriceOptionsProvider=null, SalableResolverInterface $salableResolver=null, MinimalPriceCalculatorInterface $minimalPriceCalculator=null)