Skip to content

Commit

Permalink
Feature/fix coupon rounding (#299)
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisoderwald authored Jul 29, 2021
1 parent 167e5c0 commit abbe06a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/CartItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,9 @@ public function total()
for ($qty = 0; $qty < $this->qty; $qty++) {
$total += LaraCart::formatMoney($this->subTotalPerItem(false) + array_sum($this->taxSummary()[$qty]), null, null, false);
}
// TODO - mabye keep this in...
// $total -= $this->getDiscount(false);

$total -= $this->getDiscount(false);

if ($total < 0) {
$total = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Coupons/Percentage.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function __construct($code, $value, $options = [])
public function discount($price)
{
if ($this->canApply()) {
return $price * $this->value;
return ($price * $this->value);
}

return 0;
Expand Down
8 changes: 4 additions & 4 deletions src/LaraCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private function updateDiscounts()
if ($item->coupon) {
$item->coupon->discounted = 0;
for ($qty = 0; $qty < $item->qty; $qty++) {
$item->coupon->discounted += $item->discounted[$qty] = $this->formatMoney($item->coupon->discount($item->subTotalPerItem(false)), null, null, false);
$item->coupon->discounted += $item->discounted[$qty] = $item->coupon->discount($item->subTotalPerItem(false));
}
}
}
Expand All @@ -163,15 +163,15 @@ private function updateDiscounts()
if (!$item->coupon) {
$item->discounted = [];
for ($qty = 0; $qty < $item->qty; $qty++) {
$coupon->discounted += $item->discounted[$qty] = $this->formatMoney($coupon->discount($item->subTotalPerItem(false)), null, null, false);
$coupon->discounted += $item->discounted[$qty] = $coupon->discount($item->subTotalPerItem(false));
}
}
}

if (config('laracart.discount_fees', false)) {
// go through each fee and discount
foreach ($this->getFees() as $fee) {
$coupon->discounted = $fee->discounted = $this->formatMoney($coupon->discount($fee->amount), null, null, false);
$coupon->discounted = $fee->discounted = $coupon->discount($fee->amount);
}
}
}
Expand Down Expand Up @@ -675,7 +675,7 @@ public function total($format = true)
{
$total = $this->itemTotals(false);
$total += $this->feeSubTotal(false) + $this->feeTaxTotal(false);
$total -= $this->discountTotal(false);
// $total -= $this->discountTotal(false);

return $this->formatMoney($total, null, null, $format);
}
Expand Down

0 comments on commit abbe06a

Please sign in to comment.