Skip to content

Commit

Permalink
Merge pull request #211 from lukepolo/bug/dont-caulculate-discount-twice
Browse files Browse the repository at this point in the history
Bug/dont caulculate discount twice
  • Loading branch information
lukepolo authored Oct 16, 2017
2 parents e9e0492 + 0922ed4 commit 2552123
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 170 deletions.
330 changes: 165 additions & 165 deletions build/logs/clover.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/CartItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public function getDiscount($format = true)
public function tax($amountNotTaxable = 0)
{
if (!$this->taxable) {
$amountNotTaxable = $amountNotTaxable + ($this->price * $this->qty);
$amountNotTaxable = $this->price * $this->qty;
}

if (config('laracart.tax_by_item')) {
Expand Down
2 changes: 1 addition & 1 deletion src/LaraCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ public function taxTotal($format = true, $withFees = true)
} else {
$itemPrice = $item->subTotal(false);
if (($discounted + $itemPrice) > $totalDiscount) {
$totalTax += config('laracart.discountTaxable', true) ? $item->tax($totalDiscount - $discounted) : $item->tax();
$totalTax += config('laracart.discountTaxable', true) ? $item->tax() : $item->tax($totalDiscount - $discounted);
}

$discounted += $itemPrice;
Expand Down
2 changes: 1 addition & 1 deletion src/config/laracart.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
|--------------------------------------------------------------------------
|
*/
'discountTaxable' => true,
'discountTaxable' => false,

/*
|--------------------------------------------------------------------------
Expand Down
7 changes: 5 additions & 2 deletions tests/CouponsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,12 @@ public function testSetDiscountOnItem()

$item = $this->addItem();

$this->app['config']->set('laracart.discountTaxable', true);

$this->assertEquals('54.57', $this->laracart->total(false));

$this->app['config']->set('laracart.discountTaxable', false);

$this->assertEquals('55.27', $this->laracart->total(false));

$this->laracart->removeCoupon('10OFF');
Expand Down Expand Up @@ -283,9 +286,9 @@ public function testCouponsTaxableItem()

$this->app['config']->set('laracart.discountTaxable', false);

$this->assertEquals('0.07', $this->laracart->taxTotal(false));
$this->assertEquals('0.06', $this->laracart->taxTotal(false));

$this->assertEquals('0.87', $this->laracart->total(false));
$this->assertEquals('0.86', $this->laracart->total(false));
}

/**
Expand Down
12 changes: 12 additions & 0 deletions tests/TotalsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,16 @@ public function testTotalWithoutFees()

$this->assertEquals('5.00', $this->laracart->total(false, true, false, false));
}

public function testTaxTotalWithDiscounts()
{
$this->laracart->add(1, 'Test Product', 1, 100, ['tax' => 0.21]);

$coupon = new LukePOLO\LaraCart\Coupons\Percentage('test', 0.05, [
'name' => '5% off',
'description' => '5% off test',
]);

$this->laracart->addCoupon($coupon);
}
}

0 comments on commit 2552123

Please sign in to comment.