mirror of
https://github.com/wearepixel/laravel-cart.git
synced 2026-11-14 22:01:48 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e49ebe02e0 | ||
|
|
28b451583d | ||
|
|
3673f360b7 | ||
|
|
f6447ad4d9 |
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "wearepixel/laravel-cart",
|
||||
"version": "1.0.3",
|
||||
"version": "1.0.4",
|
||||
"description": "A cart implementation for Laravel",
|
||||
"keywords": [
|
||||
"laravel",
|
||||
|
||||
@@ -145,12 +145,6 @@ public function getCalculatedValue($totalOrSubTotalOrPrice = null): int|float
|
||||
*/
|
||||
protected function apply($totalOrSubTotalOrPrice, $conditionValue)
|
||||
{
|
||||
if ($totalOrSubTotalOrPrice <= 0) {
|
||||
$this->parsedRawValue = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// if value has a percentage sign on it, we will get first
|
||||
// its percentage then we will evaluate again if the value
|
||||
// has a minus or plus sign so we can decide what to do with the
|
||||
|
||||
@@ -825,6 +825,96 @@
|
||||
|
||||
expect($this->cart->getConditions()->count())->toEqual(0, 'Cart should have no conditions now');
|
||||
});
|
||||
|
||||
test('calculate the subtotal correctly when one condition makes it $0, and the other adds $10', function () {
|
||||
$this->cart->add([
|
||||
[
|
||||
'id' => 456,
|
||||
'name' => 'Sample Item 1',
|
||||
'price' => 67.99,
|
||||
'quantity' => 1,
|
||||
'attributes' => [],
|
||||
],
|
||||
[
|
||||
'id' => 568,
|
||||
'name' => 'Sample Item 2',
|
||||
'price' => 69.25,
|
||||
'quantity' => 1,
|
||||
'attributes' => [],
|
||||
],
|
||||
]);
|
||||
|
||||
expect($this->cart->getSubTotal())->toEqual(137.24, 'Cart should have sub total of 137.24');
|
||||
expect($this->cart->getTotal())->toEqual(137.24, 'Cart should have total of 137.24');
|
||||
|
||||
// add conditions
|
||||
$couponCode = new CartCondition([
|
||||
'name' => 'Coupon code',
|
||||
'type' => 'discount',
|
||||
'target' => 'subtotal',
|
||||
'order' => '1',
|
||||
'value' => '-100%',
|
||||
]);
|
||||
|
||||
$shipping = new CartCondition([
|
||||
'name' => 'Shipping',
|
||||
'type' => 'shipping',
|
||||
'target' => 'subtotal',
|
||||
'order' => '2',
|
||||
'value' => '10',
|
||||
]);
|
||||
|
||||
$this->cart->condition($couponCode);
|
||||
$this->cart->condition($shipping);
|
||||
|
||||
expect($this->cart->getSubTotal())->toEqual(10.00, 'Cart should have sub total of 10.00');
|
||||
expect($this->cart->getTotal())->toEqual(10.00, 'Cart should have a total of 10.00');
|
||||
});
|
||||
|
||||
test('calculate the subtotal correctly when one condition makes it $0 (with dollars), and the other adds $10', function () {
|
||||
$this->cart->add([
|
||||
[
|
||||
'id' => 456,
|
||||
'name' => 'Sample Item 1',
|
||||
'price' => 67.99,
|
||||
'quantity' => 1,
|
||||
'attributes' => [],
|
||||
],
|
||||
[
|
||||
'id' => 568,
|
||||
'name' => 'Sample Item 2',
|
||||
'price' => 69.25,
|
||||
'quantity' => 1,
|
||||
'attributes' => [],
|
||||
],
|
||||
]);
|
||||
|
||||
expect($this->cart->getSubTotal())->toEqual(137.24, 'Cart should have sub total of 137.24');
|
||||
expect($this->cart->getTotal())->toEqual(137.24, 'Cart should have total of 137.24');
|
||||
|
||||
// add conditions
|
||||
$couponCode = new CartCondition([
|
||||
'name' => 'Coupon code',
|
||||
'type' => 'discount',
|
||||
'target' => 'subtotal',
|
||||
'order' => '1',
|
||||
'value' => '-137.24',
|
||||
]);
|
||||
|
||||
$shipping = new CartCondition([
|
||||
'name' => 'Shipping',
|
||||
'type' => 'shipping',
|
||||
'target' => 'subtotal',
|
||||
'order' => '2',
|
||||
'value' => '10',
|
||||
]);
|
||||
|
||||
$this->cart->condition($couponCode);
|
||||
$this->cart->condition($shipping);
|
||||
|
||||
expect($this->cart->getSubTotal())->toEqual(10.00, 'Cart should have sub total of 10.00');
|
||||
expect($this->cart->getTotal())->toEqual(10.00, 'Cart should have a total of 10.00');
|
||||
});
|
||||
});
|
||||
|
||||
describe('item level conditions', function () {
|
||||
|
||||
Reference in New Issue
Block a user