Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DiscountCalculator.php
Go to the documentation of this file.
1 <?php
8 
10 
15 {
23  public function calculateDiscount(Product $product, $value = null)
24  {
25  if ($value === null) {
26  $value = $product->getPriceInfo()->getPrice(FinalPrice::PRICE_CODE)->getValue();
27  }
28 
29  $discount = null;
30  foreach ($product->getPriceInfo()->getPrices() as $price) {
31  if ($price instanceof DiscountProviderInterface && $price->getDiscountPercent()) {
32  $discount = min($price->getDiscountPercent(), $discount ?: $price->getDiscountPercent());
33  }
34  }
35  return (null !== $discount) ? $discount/100 * $value : $value;
36  }
37 }
calculateDiscount(Product $product, $value=null)
$price
$value
Definition: gender.phtml:16