Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
FinalPrice.php
Go to the documentation of this file.
1 <?php
8 
11 
16 {
20  const PRICE_CODE = 'final_price';
21 
25  protected $minProduct;
26 
32  public function getValue()
33  {
34  $minProduct = $this->getMinProduct();
35  return $minProduct ?
36  $minProduct->getPriceInfo()->getPrice(FinalPrice::PRICE_CODE)->getValue() :
37  0.00;
38  }
39 
45  public function getMinProduct()
46  {
47  if (null === $this->minProduct) {
48  $products = $this->product->getTypeInstance()->getAssociatedProducts($this->product);
49  $minPrice = null;
50  foreach ($products as $item) {
51  $product = clone $item;
52  $product->setQty(\Magento\Framework\Pricing\PriceInfoInterface::PRODUCT_QUANTITY_DEFAULT);
53  $price = $product->getPriceInfo()
54  ->getPrice(FinalPrice::PRICE_CODE)
55  ->getValue();
56  if (($price !== false) && ($price <= ($minPrice === null ? $price : $minPrice))) {
57  $this->minProduct = $product;
58  $minPrice = $price;
59  }
60  }
61  }
62  return $this->minProduct;
63  }
64 }
$price