commit 08-2025

This commit is contained in:
Kevin Adametz 2025-08-12 18:01:59 +02:00
parent 9ae662f63e
commit 480fdc65ed
404 changed files with 65310 additions and 2600431 deletions

View file

@ -21,6 +21,7 @@ class Cart
const DEFAULT_INSTANCE = 'default';
public $items;
public $shipping_extras;
public $fees;
/**
@ -43,6 +44,7 @@ class Cart
* @var string
*/
private $instance;
private $shipping_extras_instance;
/**
* Cart constructor.
@ -54,10 +56,11 @@ class Cart
{
$this->items = new Collection;
$this->fees = new Collection;
$this->shipping_extras = new Collection;
$this->session = $session;
$this->events = $events;
$this->instance(self::DEFAULT_INSTANCE);
//$this->instance(self::DEFAULT_INSTANCE);
}
/**
@ -71,6 +74,8 @@ class Cart
$instance = $instance ?: self::DEFAULT_INSTANCE;
$this->instance = sprintf('%s.%s', 'cart', $instance);
$this->shipping_extras_instance = sprintf('%s.%s.%s', 'cart', $instance, 'shipping_extras');
return $this;
}
@ -148,6 +153,10 @@ class Cart
{
$cartItem = $this->get($rowId);
if(!$cartItem) {
return null;
}
if ($qty instanceof Buyable) {
$cartItem->updateFromBuyable($qty);
} elseif (is_array($qty)) {
@ -161,6 +170,9 @@ class Cart
if ($rowId !== $cartItem->rowId) {
if ($content->has($cartItem->rowId)) {
$existingCartItem = $this->get($cartItem->rowId);
if(!$existingCartItem) {
return null;
}
$cartItem->setQuantity($existingCartItem->qty + $cartItem->qty);
}
@ -206,6 +218,10 @@ class Cart
{
$cartItem = $this->get($rowId);
if(!$cartItem) {
return null;
}
$content = $this->getContent();
$content->pull($cartItem->rowId);
@ -235,7 +251,8 @@ class Cart
$content = $this->getContent();
if ($content->has($rowId) === false) {
throw new InvalidRowIDException("The cart does not contain rowId {$rowId}.");
// throw new InvalidRowIDException("The cart does not contain rowId {$rowId}.");
return null;
}
return $content->get($rowId);
@ -423,6 +440,10 @@ class Cart
$cartItem = $this->get($rowId);
if(!$cartItem) {
return null;
}
$cartItem->associate($model);
$content = $this->getContent();
@ -443,6 +464,10 @@ class Cart
{
$cartItem = $this->get($rowId);
if(!$cartItem) {
return null;
}
$cartItem->setTaxRate($taxRate);
$content = $this->getContent();
@ -450,7 +475,6 @@ class Cart
$content->put($cartItem->rowId, $cartItem);
$this->items = $content;
$this->session->put($this->instance, $this->toArray());
}
@ -500,7 +524,7 @@ class Cart
* @param array $eventOptions
* @return void
*/
public function restore($identifier, array $eventOptions = [], $delteStoredCart = true)
public function restore($identifier, array $eventOptions = [], $delteStoredCart = true, $instance = 'shopping')
{
if ($this->storedCartWithIdentifierExists($identifier) === false) {
return;
@ -518,8 +542,9 @@ class Cart
$currentInstance = $this->currentInstance();
$this->instance($stored->instance);
$this->instance($currentInstance);
//$this->instance($instance);
$content = $this->getContent();
// If the new approach and is array, set this class up.
@ -544,9 +569,9 @@ class Cart
$eventOptions,
]);
$this->session->put($this->instance, $content);
$this->session->put($this->instance, $this->toArray());
$this->instance($currentInstance);
// $this->instance($currentInstance);
if($delteStoredCart === true) {
$this->deleteStoredCart($identifier);
@ -687,6 +712,7 @@ class Cart
return [
'items' => $this->items,
'fees' => $this->fees,
'shipping_extras' => $this->shipping_extras,
];
}
@ -698,7 +724,7 @@ class Cart
{
$this->items = $array['items'];
$this->fees = $array['fees'];
$this->shipping_extras = $array['shipping_extras'];
return $this;
}
@ -735,8 +761,12 @@ class Cart
// dd($instance);
// If new approach, set $this variables
if (is_array($instance) === true) {
$this->items = $instance['items'];
$this->fees = $instance['fees'];
if(isset($instance['items'])){
$this->items = $instance['items'];
}
if(isset($instance['fees'])){
$this->fees = $instance['fees'];
}
}
if ($instance instanceof Collection) {
@ -746,6 +776,29 @@ class Cart
return $this->items;
}
public function getShippingExtras(): Collection
{
$instanceExists = $this->session->has($this->shipping_extras_instance);
if ($instanceExists === false) {
$this->shipping_extras = new Collection;
return $this->shipping_extras;
}
$instance = $this->session->get($this->shipping_extras_instance);
if (is_array($instance) === true) {
if(isset($instance['shipping_extras'])){
$this->shipping_extras = $instance['shipping_extras'];
}
}
if ($instance instanceof Collection) {
$this->shipping_extras = $instance;
}
return $this->shipping_extras;
}
public function putShippingExtras($content)
{
$this->session->put($this->shipping_extras_instance, $content);
}
/**
* Create a new CartItem from the supplied attributes.
*