Skip to content

Commit

Permalink
add meta data
Browse files Browse the repository at this point in the history
  • Loading branch information
n1crack committed Jun 3, 2023
1 parent 30cc50e commit dddb540
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class Cart implements \Serializable
*/
private StorageInterface $storage;

/**
* @var array $meta
*/
private array $meta;

/**
* @var
*/
Expand All @@ -52,6 +57,7 @@ public function __construct(StorageInterface $storage, $dispatcher, $config)

$this->conditionsOrder = $this->storage->get('cart:conditionsOrder') ?? config('cart.condition_order.cart');
$this->itemConditionsOrder = $this->storage->get('cart:itemConditionsOrder') ?? config('cart.condition_order.item');
$this->meta = $this->storage->get('cart:meta') ?? [];
}

public function clone(StorageInterface $storage, $dispatcher = null, $config = null): Cart
Expand Down Expand Up @@ -333,6 +339,20 @@ public function setItemConditionsOrder(array $itemConditionsOrder): void
$this->items()->each->setItemConditionsOrder($itemConditionsOrder);
}

/**
* @param string[] $itemConditionsOrder
*/
public function setMeta(string $key, mixed $data): void
{
$this->meta[$key] = $data;
$this->storage->put('cart:meta', $this->meta);
}

public function getMeta(string $key, mixed $default): mixed
{
return $this->meta[$key] ?? $default;
}

private function updateItemStorage()
{
$this->updateConditionPrice();
Expand Down

0 comments on commit dddb540

Please sign in to comment.