diff --git a/src/Cart.php b/src/Cart.php index 2a82e1f..f71b96b 100644 --- a/src/Cart.php +++ b/src/Cart.php @@ -61,6 +61,12 @@ class Cart */ protected $_cartModifiedCallback = true; + /** @var callable|null */ + protected $totalRounding; + + /** @var Decimal */ + protected $roundingAmount; + /** * Constructor. * @@ -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. *