diff --git a/CHANGELOG.md b/CHANGELOG.md index db68d6a985..a9443676af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- Fixed a PHP error that could occur when calculating order totals. ([#3802](https://github.com/craftcms/commerce/issues/3802)) - Fixed a bug where a product’s default price was showing incorrectly on the Products index page. ([#3807](https://github.com/craftcms/commerce/issues/3807)) - Fixed a bug where inline-editable Matrix fields weren’t saving content on product variants. ([#3805](https://github.com/craftcms/commerce/issues/3805)) - Fixed a bug where order errors weren't showing on the Edit Order page. diff --git a/src/elements/Order.php b/src/elements/Order.php index 19870f64c9..63ed535063 100644 --- a/src/elements/Order.php +++ b/src/elements/Order.php @@ -1700,7 +1700,8 @@ public function updateOrderPaidInformation(): void $justPaid = $paidInFull && $this->datePaid == null; $justAuthorized = $authorizedInFull && $this->dateAuthorized == null; - $canComplete = ($this->getTotalAuthorized() + $this->getTotalPaid()) > 0; + $completeTotal = $this->_getTeller()->add($this->getTotalAuthorized(), $this->getTotalPaid()); + $canComplete = $this->_getTeller()->greaterThan($completeTotal, 0); // If it is no longer paid in full, set datePaid to null if (!$paidInFull) { @@ -2662,7 +2663,7 @@ public function getPaidStatusHtml(): string */ public function getTotal(): float { - return Currency::round($this->getItemSubtotal() + $this->getAdjustmentsTotal()); + return (float)$this->_getTeller()->add($this->getItemSubtotal(), $this->getAdjustmentsTotal()); } /** @@ -2670,18 +2671,19 @@ public function getTotal(): float */ public function getTotalPrice(): float { - $total = $this->getItemSubtotal() + $this->getAdjustmentsTotal(); // Don't get the pre-rounded total. + $total = (float)$this->_getTeller()->add($this->getItemSubtotal(), $this->getAdjustmentsTotal()); + // Don't get the pre-rounded total. $strategy = $this->getStore()->getMinimumTotalPriceStrategy(); if ($strategy === Store::MINIMUM_TOTAL_PRICE_STRATEGY_ZERO) { - return Currency::round(max(0, $total)); + return (float)$this->_getTeller()->max(0, $total); } if ($strategy === Store::MINIMUM_TOTAL_PRICE_STRATEGY_SHIPPING) { - return Currency::round(max($this->getTotalShippingCost(), $total)); + return (float)$this->_getTeller()->max($this->getTotalShippingCost(), $total); } - return Currency::round($total); + return $total; } public function getItemTotal(): float diff --git a/src/models/LineItem.php b/src/models/LineItem.php index ddd3938ee1..a671fc2c2f 100755 --- a/src/models/LineItem.php +++ b/src/models/LineItem.php @@ -703,7 +703,8 @@ public function getSubtotal(): float */ public function getTotal(): float { - return $this->getSubtotal() + $this->getAdjustmentsTotal(); + $teller = Plugin::getInstance()->getCurrencies()->getTeller($this->order->currency); + return (float)$teller->add($this->getSubtotal(), $this->getAdjustmentsTotal()); } /**