diff --git a/src/CartFee.php b/src/CartFee.php index 1f06eba4..eff38cba 100644 --- a/src/CartFee.php +++ b/src/CartFee.php @@ -21,8 +21,8 @@ class CartFee /** * CartFee constructor. * - * @param $amount - * @param $taxable + * @param $amount + * @param $taxable * @param array $options */ public function __construct($amount, $taxable = false, $options = []) diff --git a/src/Contracts/LaraCartContract.php b/src/Contracts/LaraCartContract.php index 231d2960..3d87681b 100644 --- a/src/Contracts/LaraCartContract.php +++ b/src/Contracts/LaraCartContract.php @@ -84,7 +84,7 @@ public function addLine($itemID, $name = null, $qty = 1, $price = '0.00', $optio /** * Creates a CartItem and then adds it to cart. * - * @param $itemID + * @param $itemID * @param null $name * @param int $qty * @param string $price @@ -203,8 +203,8 @@ public function getFee($name); * Allows to charge for additional fees that may or may not be taxable * ex - service fee , delivery fee, tips. * - * @param $name - * @param $amount + * @param $name + * @param $amount * @param bool|false $taxable * @param array $options */ diff --git a/src/Coupons/Fixed.php b/src/Coupons/Fixed.php index ab37b8ef..6e512da2 100644 --- a/src/Coupons/Fixed.php +++ b/src/Coupons/Fixed.php @@ -16,8 +16,8 @@ class Fixed implements CouponContract /** * Fixed constructor. * - * @param $code - * @param $value + * @param $code + * @param $value * @param array $options */ public function __construct($code, $value, $options = []) diff --git a/src/Coupons/Percentage.php b/src/Coupons/Percentage.php index a8a8553a..214adc28 100644 --- a/src/Coupons/Percentage.php +++ b/src/Coupons/Percentage.php @@ -21,8 +21,8 @@ class Percentage implements CouponContract /** * Percentage constructor. * - * @param $code - * @param $value + * @param $code + * @param $value * @param array $options * * @throws \Exception diff --git a/src/LaraCart.php b/src/LaraCart.php index a0922b1a..a66abcca 100644 --- a/src/LaraCart.php +++ b/src/LaraCart.php @@ -161,9 +161,10 @@ private function updateDiscounts() $coupon->discounted = 0; foreach ($this->getItems() as $item) { 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); + $discount = $this->formatMoney($coupon->discount($item->subTotalPerItem(false)), null, null, false); + $coupon->discounted += $discount; + array_push($item->discounted, $discount); } } } @@ -379,10 +380,10 @@ public function find($data) switch (count($matches)) { case 0: return; - break; + break; case 1: return $matches[0]; - break; + break; default: return $matches; } @@ -756,7 +757,7 @@ public static function formatMoney($number, $locale = null, $currencyCode = null // When prices in cents needs to be formatted, divide by 100 to allow formatting in whole units if (config('laracart.prices_in_cents', false) === true && $format) { $number = $number / 100; - // When prices in cents do not need to be formatted then cast to integer and round the price + // When prices in cents do not need to be formatted then cast to integer and round the price } elseif (config('laracart.prices_in_cents', false) === true && !$format) { $number = (int) round($number); } else { diff --git a/src/Traits/CouponTrait.php b/src/Traits/CouponTrait.php index 5ab261ef..4da8c69a 100644 --- a/src/Traits/CouponTrait.php +++ b/src/Traits/CouponTrait.php @@ -98,7 +98,7 @@ public function maxDiscount($maxDiscount, $discount, $throwErrors = true) * * @param Carbon $startDate * @param Carbon $endDate - * @param $throwErrors + * @param $throwErrors * * @throws CouponException * diff --git a/tests/Coupons/Fixed.php b/tests/Coupons/Fixed.php index d9cb9835..b06c1855 100644 --- a/tests/Coupons/Fixed.php +++ b/tests/Coupons/Fixed.php @@ -20,8 +20,8 @@ class Fixed implements CouponContract /** * Fixed constructor. * - * @param $code - * @param $value + * @param $code + * @param $value * @param array $options */ public function __construct($code, $value, $options = []) diff --git a/tests/CouponsTest.php b/tests/CouponsTest.php index 63a08f7e..0ed33678 100644 --- a/tests/CouponsTest.php +++ b/tests/CouponsTest.php @@ -235,7 +235,7 @@ public function testSetDiscountOnItem() $this->assertNotNull($item->coupon); $this->assertEquals('10OFF', $item->coupon->code); - $this->assertEquals(90 * 1.07, $this->laracart->total(false)); + $this->assertEquals(96.3, $this->laracart->total(false)); $this->laracart->removeCoupon('10OFF'); @@ -447,7 +447,7 @@ public function testPercentageCouponOnMultipleQtyItems() $percentCoupon->setDiscountOnItem($item); - $this->assertEquals(18, $this->laracart->total(false) - $this->laracart->taxTotal(false)); + $this->assertEquals(18, $this->laracart->netTotal(false)); } /** @@ -520,4 +520,30 @@ public function testCouponOnSubItems() $this->assertEquals(0, $this->laracart->total(false)); } + + public function testMultipleCouponTotals() + { + $this->app['config']->set('laracart.tax', .15); + $this->laracart->cart->multipleCoupons = true; + + $item = $this->addItem(1, 500); + + $fixedCoupon = new LukePOLO\LaraCart\Coupons\Fixed('60 OFF', 60); + + $this->laracart->addCoupon($fixedCoupon); + + $this->assertEquals(500, $this->laracart->subTotal(false)); + $this->assertEquals(60, $this->laracart->discountTotal(false)); + $this->assertEquals(440, $this->laracart->netTotal(false)); + $this->assertEquals(506, $this->laracart->total(false)); + + $fixedCoupon = new LukePOLO\LaraCart\Coupons\Fixed('40 OFF', 40); + $this->laracart->addCoupon($fixedCoupon); + $this->assertCount(2, $this->laracart->getCoupons()); + + $this->assertEquals(500, $this->laracart->subTotal(false)); + $this->assertEquals(60 + 40, $this->laracart->discountTotal(false)); + $this->assertEquals(400, $this->laracart->netTotal(false)); + $this->assertEquals(466, $this->laracart->total(false)); + } } diff --git a/tests/FeesTest.php b/tests/FeesTest.php index c311dec0..a69faa6e 100644 --- a/tests/FeesTest.php +++ b/tests/FeesTest.php @@ -10,7 +10,7 @@ class FeesTest extends Orchestra\Testbench\TestCase /** * Add a fee. * - * @param $name + * @param $name * @param int $fee */ private function addFee($name, $fee = 10) @@ -24,7 +24,7 @@ private function addFee($name, $fee = 10) /** * Add a fee with tax. * - * @param $name + * @param $name * @param int $fee */ private function addFeeTax($name, $fee = 100, $tax = 0.21)