mirror of
https://github.com/wearepixel/laravel-cart.git
synced 2026-11-14 22:01:48 +00:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
489b2723d5 | ||
|
|
d3f673d52f |
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "wearepixel/laravel-cart",
|
||||
"version": "1.0.11",
|
||||
"version": "1.0.8",
|
||||
"description": "A cart implementation for Laravel",
|
||||
"keywords": [
|
||||
"laravel",
|
||||
|
||||
+9
-7
@@ -406,6 +406,9 @@ public function removeCartCondition($conditionName)
|
||||
|
||||
$conditions->pull($conditionName);
|
||||
|
||||
// reset indexes
|
||||
$conditions = $conditions->values();
|
||||
|
||||
$this->saveConditions($conditions);
|
||||
}
|
||||
|
||||
@@ -458,6 +461,9 @@ public function removeItemCondition($itemId, $conditionName)
|
||||
}
|
||||
}
|
||||
|
||||
// reset indexes
|
||||
$item['conditions'] = array_values($item['conditions']);
|
||||
|
||||
$this->update($itemId, [
|
||||
'conditions' => $item['conditions'],
|
||||
]);
|
||||
@@ -598,14 +604,10 @@ public function getTotal(): int|float
|
||||
return Helpers::formatValue($subTotal, $this->config['format_numbers'], $this->config);
|
||||
}
|
||||
|
||||
$index = 0;
|
||||
|
||||
$conditionsForTotal->each(function (CartCondition $condition) use ($subTotal, &$total, &$index) {
|
||||
$toBeCalculated = ($index > 0) ? $total : $subTotal;
|
||||
$conditionsForTotal->each(function (CartCondition $condition) use ($subTotal, &$total) {
|
||||
$toBeCalculated = $total > 0 ? $total : $subTotal;
|
||||
|
||||
$total = $condition->applyCondition($toBeCalculated);
|
||||
|
||||
$index++;
|
||||
});
|
||||
|
||||
return Helpers::formatValue($total, $this->config['format_numbers'], $this->config);
|
||||
@@ -734,7 +736,7 @@ protected function addItem($id, $item)
|
||||
/**
|
||||
* save the cart
|
||||
*
|
||||
* @param $cart CartCollection
|
||||
* @param $cart CartCollection
|
||||
*/
|
||||
protected function save($cart)
|
||||
{
|
||||
|
||||
@@ -10,11 +10,11 @@
|
||||
$events->shouldReceive('dispatch');
|
||||
|
||||
$this->cart = new Cart(
|
||||
new SessionMock(),
|
||||
new SessionMock,
|
||||
$events,
|
||||
'cart',
|
||||
'SAMPLESESSIONKEY',
|
||||
require(__DIR__ . '/../Helpers/ConfigConditionsMock.php')
|
||||
require (__DIR__ . '/../Helpers/ConfigConditionsMock.php')
|
||||
);
|
||||
});
|
||||
|
||||
@@ -119,7 +119,7 @@
|
||||
|
||||
// now we should have only 1 condition left on that item
|
||||
expect($this->cart->getConditions())->toHaveCount(1, 'Item should have one condition left');
|
||||
expect($this->cart->getConditions()->first()->getName())->toEqual('Mother\'s Day Gift Pack');
|
||||
expect($this->cart->getConditions()[0]->getName())->toEqual('Mother\'s Day Gift Pack');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1310,7 +1310,7 @@
|
||||
|
||||
// now we should have only 1 condition left on that item
|
||||
expect($this->cart->get(1)['conditions'])->toHaveCount(1, 'Item should have one condition left');
|
||||
expect($this->cart->get(1)['conditions'][1]->getName())->toEqual('Mother\'s Day Gift Pack');
|
||||
expect($this->cart->get(1)['conditions'][0]->getName())->toEqual('Mother\'s Day Gift Pack');
|
||||
});
|
||||
|
||||
test('can add item with multiple negative item conditions', function () {
|
||||
|
||||
Reference in New Issue
Block a user