Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/CartFee.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [])
Expand Down
6 changes: 3 additions & 3 deletions src/Contracts/LaraCartContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Coupons/Fixed.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [])
Expand Down
4 changes: 2 additions & 2 deletions src/Coupons/Percentage.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class Percentage implements CouponContract
/**
* Percentage constructor.
*
* @param $code
* @param $value
* @param $code
* @param $value
* @param array $options
*
* @throws \Exception
Expand Down
11 changes: 6 additions & 5 deletions src/LaraCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/CouponTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function maxDiscount($maxDiscount, $discount, $throwErrors = true)
*
* @param Carbon $startDate
* @param Carbon $endDate
* @param $throwErrors
* @param $throwErrors
*
* @throws CouponException
*
Expand Down
4 changes: 2 additions & 2 deletions tests/Coupons/Fixed.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [])
Expand Down
30 changes: 28 additions & 2 deletions tests/CouponsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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));
}

/**
Expand Down Expand Up @@ -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));
}
}
4 changes: 2 additions & 2 deletions tests/FeesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down