Skip to content

Commit

Permalink
add rounding
Browse files Browse the repository at this point in the history
  • Loading branch information
segy committed Jul 1, 2022
1 parent cd6897a commit 3aec652
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ class Cart
*/
protected $_cartModifiedCallback = true;

/** @var callable|null */
protected $totalRounding;

/** @var Decimal */
protected $roundingAmount;

/**
* Constructor.
*
Expand Down Expand Up @@ -557,9 +563,25 @@ public function getTotal($type = '~')
$total = $total->add($item);
}

if (\is_callable($this->totalRounding)) {
$newTotal = \call_user_func($this->totalRounding, $total);
$this->roundingAmount = $newTotal->sub($total);
$total = $newTotal;
}

return $total;
}

/**
* @param callable|string $type
*/
public function getRoundingAmount($type = '~'): Decimal
{
$this->getTotal($type);

return $this->roundingAmount;
}

/**
* Get taxes.
*
Expand Down

0 comments on commit 3aec652

Please # to comment.