Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/Darryldecode/Cart/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ class Cart
*/
protected $currentItemId;

protected $cachedContent;

protected $cachedConditions;

/**
* our object constructor
*
Expand All @@ -88,6 +92,8 @@ public function __construct($session, $events, $instanceName, $session_key, $con
$this->sessionKeyCartConditions = $this->sessionKey . '_cart_conditions';
$this->config = $config;
$this->currentItem = null;
$this->cachedContent = null;
$this->cachedConditions = null;
$this->fireEvent('created');
}

Expand Down Expand Up @@ -397,7 +403,11 @@ public function condition($condition)
*/
public function getConditions()
{
return new CartConditionCollection($this->session->get($this->sessionKeyCartConditions));
if(!$this->cachedConditions) {
$this->cachedConditions = new CartConditionCollection($this->session->get($this->sessionKeyCartConditions));
}

return $this->cachedConditions;
}

/**
Expand Down Expand Up @@ -672,9 +682,12 @@ public function getTotalQuantity()
*/
public function getContent()
{
return (new CartCollection($this->session->get($this->sessionKeyCartItems)))->reject(function($item) {
return ! ($item instanceof ItemCollection);
});
if(!$this->cachedContent){
$this->cachedContent = (new CartCollection($this->session->get($this->sessionKeyCartItems)))->reject(function ($item) {
return ! ($item instanceof ItemCollection);
});
}
return $this->cachedContent;
}

/**
Expand Down