| Current Path : /var/www/clients/client3/web2/web/vendor/magento/module-bundle/Pricing/Price/ |
| Current File : /var/www/clients/client3/web2/web/vendor/magento/module-bundle/Pricing/Price/DiscountCalculator.php |
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Bundle\Pricing\Price;
use Magento\Catalog\Model\Product;
/**
* Class DiscountCalculator
*/
class DiscountCalculator
{
/**
* Apply percentage discount
*
* @param Product $product
* @param float|null $value
* @return float|null
*/
public function calculateDiscount(Product $product, $value = null)
{
if ($value === null) {
$value = $product->getPriceInfo()->getPrice(FinalPrice::PRICE_CODE)->getValue();
}
$discount = null;
foreach ($product->getPriceInfo()->getPrices() as $price) {
if ($price instanceof DiscountProviderInterface && $price->getDiscountPercent()) {
$discount = min($price->getDiscountPercent(), $discount ?: $price->getDiscountPercent());
}
}
return (null !== $discount) ? $discount/100 * $value : $value;
}
}