From 4bf534ad50682c6fbd5c2226660b858fe43abed4 Mon Sep 17 00:00:00 2001 From: MrWeez <64205495+MrWeez@users.noreply.github.com> Date: Fri, 24 May 2024 10:38:31 +0300 Subject: [PATCH] Fix error 500 on the checkout page, small code refactor and total display fix (#963) * fix: replaced number_format by round because this caused error 500 on checkout * refactor: code has been made more readable * fix: incorrect display of total on checkout --- app/Models/ShopProduct.php | 10 +++++++--- themes/default/views/store/checkout.blade.php | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/Models/ShopProduct.php b/app/Models/ShopProduct.php index 12b870a2..8e8a2260 100644 --- a/app/Models/ShopProduct.php +++ b/app/Models/ShopProduct.php @@ -80,7 +80,9 @@ class ShopProduct extends Model public function getPriceAfterDiscount() { - return number_format($this->price - ($this->price * PartnerDiscount::getDiscount() / 100), 2); + $discountRate = PartnerDiscount::getDiscount() / 100; + $discountedPrice = $this->price * (1 - $discountRate); + return round($discountedPrice, 2); } /** @@ -90,7 +92,8 @@ class ShopProduct extends Model */ public function getTaxValue() { - return number_format($this->getPriceAfterDiscount() * $this->getTaxPercent() / 100, 2); + $taxValue = $this->getPriceAfterDiscount() * $this->getTaxPercent() / 100; + return round($taxValue, 2); } /** @@ -100,6 +103,7 @@ class ShopProduct extends Model */ public function getTotalPrice() { - return number_format($this->getPriceAfterDiscount() + $this->getTaxValue(), 2); + $total = $this->getPriceAfterDiscount() + $this->getTaxValue(); + return round($total, 2); } } diff --git a/themes/default/views/store/checkout.blade.php b/themes/default/views/store/checkout.blade.php index b0f91f0d..6a0d28b2 100644 --- a/themes/default/views/store/checkout.blade.php +++ b/themes/default/views/store/checkout.blade.php @@ -237,7 +237,7 @@ payment_method: '', coupon_code: '', submitted: false, - totalPrice: {{ $discountedprice }}, + totalPrice: {{ $total }}, couponDiscountedValue: 0,