Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Calculator.php
Go to the documentation of this file.
1 <?php
8 
11 
16 {
20  protected $amountFactory;
21 
26  {
27  $this->amountFactory = $amountFactory;
28  }
29 
41  public function getAmount($amount, SaleableInterface $saleableItem, $exclude = null, $context = [])
42  {
43  $baseAmount = $fullAmount = $amount;
44  $previousAdjustments = 0;
45  $adjustments = [];
46  foreach ($saleableItem->getPriceInfo()->getAdjustments() as $adjustment) {
47  $code = $adjustment->getAdjustmentCode();
48  $toExclude = false;
49  if (!is_array($exclude)) {
50  if ($exclude === true || ($exclude !== null && $code === $exclude)) {
51  $toExclude = true;
52  }
53  } else {
54  if (in_array($code, $exclude)) {
55  $toExclude = true;
56  }
57  }
58  if ($adjustment->isIncludedInBasePrice()) {
59  $adjust = $adjustment->extractAdjustment($baseAmount, $saleableItem, $context);
60  $baseAmount -= $adjust;
61  $fullAmount = $adjustment->applyAdjustment($fullAmount, $saleableItem, $context);
62  $adjust = $fullAmount - $baseAmount - $previousAdjustments;
63  if (!$toExclude) {
64  $adjustments[$code] = $adjust;
65  }
66  } elseif ($adjustment->isIncludedInDisplayPrice($saleableItem)) {
67  if ($toExclude) {
68  continue;
69  }
70  $newAmount = $adjustment->applyAdjustment($fullAmount, $saleableItem, $context);
71  $adjust = $newAmount - $fullAmount;
72  $adjustments[$code] = $adjust;
73  $fullAmount = $newAmount;
74  $previousAdjustments += $adjust;
75  }
76  }
77 
78  return $this->amountFactory->create($fullAmount, $adjustments);
79  }
80 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
getAmount($amount, SaleableInterface $saleableItem, $exclude=null, $context=[])
Definition: Calculator.php:41
__construct(AmountFactory $amountFactory)
Definition: Calculator.php:25
$baseAmount
Definition: tax.phtml:46
$amount
Definition: order.php:14
$code
Definition: info.phtml:12