mirror of
https://github.com/wearepixel/laravel-cart.git
synced 2026-11-14 13:51:44 +00:00
fix: serialize conditions to arrays before storage; type \$events
- serializeConditions() now maps CartCondition objects to arrays via
toArray() before passing to the driver, preventing json_encode()
producing {} for object values in the DatabaseDriver
- Add Dispatcher type hint to \$events property and constructor parameter
- Add database round-trip test for cart-level conditions
- Fix CartConditionsTest to retrieve condition objects from the cart
rather than relying on object-reference side-effects that no longer
hold after proper serialization
This commit is contained in:
+4
-3
@@ -10,13 +10,14 @@
|
||||
use Wearepixel\Cart\Exceptions\InvalidItemException;
|
||||
use Wearepixel\Cart\Exceptions\UnknownModelException;
|
||||
use Wearepixel\Cart\Exceptions\InvalidConditionException;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Wearepixel\Cart\Drivers\Contracts\CartDriver;
|
||||
|
||||
class Cart
|
||||
{
|
||||
protected CartDriver $driver;
|
||||
|
||||
protected $events;
|
||||
protected Dispatcher $events;
|
||||
|
||||
protected string $instanceName;
|
||||
|
||||
@@ -24,7 +25,7 @@ class Cart
|
||||
|
||||
protected mixed $currentItemId;
|
||||
|
||||
public function __construct(CartDriver $driver, $events, string $instanceName, array $config)
|
||||
public function __construct(CartDriver $driver, Dispatcher $events, string $instanceName, array $config)
|
||||
{
|
||||
$this->driver = $driver;
|
||||
$this->events = $events;
|
||||
@@ -581,7 +582,7 @@ private function serializeItems(CartCollection $cart): array
|
||||
|
||||
private function serializeConditions(CartConditionCollection $conditions): array
|
||||
{
|
||||
return $conditions->all();
|
||||
return $conditions->map(fn(CartCondition $c) => $c->toArray())->all();
|
||||
}
|
||||
|
||||
protected function itemHasConditions(ItemCollection $item): bool
|
||||
|
||||
Reference in New Issue
Block a user