fix: prevent save() on array after clear() with database driver

This commit is contained in:
Joel Male
2026-06-13 14:18:55 +10:00
parent fce7125c5f
commit 6ba50a1c48
2 changed files with 21 additions and 4 deletions
+2 -4
View File
@@ -159,10 +159,8 @@ public function clear()
$deleted = $this->session->delete();
$this->session = [
$this->itemsKey => [],
$this->conditionsKey => [],
];
$this->session[$this->itemsKey] = [];
$this->session[$this->conditionsKey] = [];
return $deleted;
}
+19
View File
@@ -123,4 +123,23 @@
expect($this->cart->getContent()->count())->toEqual(0, 'Cart content should be 0');
expect(MockCartModel::all()->count())->toEqual(0, 'The carts database table should have 0 rows');
});
test('can clear cart conditions after clearing the cart', function () {
$condition = new CartCondition([
'name' => '10% Off',
'type' => 'coupon',
'target' => 'subtotal',
'value' => '-10%',
]);
$this->cart->add(1, 'Sample Item', 100.99, 2, []);
$this->cart->condition($condition);
$this->cart->clear();
// This was throwing "Call to a member function save() on array"
// because clear() replaced $this->session with a plain array
expect(fn () => $this->cart->clearCartConditions())->not->toThrow(Error::class);
expect($this->cart->getConditions())->toBeEmpty();
});
});