Browse Source

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
MrWeez 1 year ago
parent
commit
4bf534ad50
2 changed files with 8 additions and 4 deletions
  1. 7 3
      app/Models/ShopProduct.php
  2. 1 1
      themes/default/views/store/checkout.blade.php

+ 7 - 3
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);
     }
 }

+ 1 - 1
themes/default/views/store/checkout.blade.php

@@ -237,7 +237,7 @@
                 payment_method: '',
                 coupon_code: '',
                 submitted: false,
-                totalPrice: {{ $discountedprice }},
+                totalPrice: {{ $total }},
                 couponDiscountedValue: 0,