Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ProductPriceCalculator.php
Go to the documentation of this file.
1 <?php
8 
13 {
17  private $priceCurrency;
18 
22  public function __construct(\Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency)
23  {
24  $this->priceCurrency = $priceCurrency;
25  }
26 
34  public function calculate($ruleData, $productData = null)
35  {
36  if ($productData !== null && isset($productData['rule_price'])) {
37  $productPrice = $productData['rule_price'];
38  } else {
39  $productPrice = $ruleData['default_price'];
40  }
41 
42  switch ($ruleData['action_operator']) {
43  case 'to_fixed':
44  $productPrice = min($ruleData['action_amount'], $productPrice);
45  break;
46  case 'to_percent':
47  $productPrice = $productPrice * $ruleData['action_amount'] / 100;
48  break;
49  case 'by_fixed':
50  $productPrice = max(0, $productPrice - $ruleData['action_amount']);
51  break;
52  case 'by_percent':
53  $productPrice = $productPrice * (1 - $ruleData['action_amount'] / 100);
54  break;
55  default:
56  $productPrice = 0;
57  }
58 
59  return $this->priceCurrency->round($productPrice);
60  }
61 }
__construct(\Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency)
$ruleData
Definition: tax_rule.php:26
$productData