diff --git a/src/Darryldecode/Cart/Cart.php b/src/Darryldecode/Cart/Cart.php index 503dce7..d919b00 100644 --- a/src/Darryldecode/Cart/Cart.php +++ b/src/Darryldecode/Cart/Cart.php @@ -69,6 +69,10 @@ class Cart */ protected $currentItemId; + protected $cachedContent; + + protected $cachedConditions; + /** * our object constructor * @@ -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'); } @@ -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; } /** @@ -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; } /**