From 13735d2f895ab0c939681c41b3e4379c5bbe7aaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=BCleyman=20=C3=96zg=C3=BCr=20=C3=96zarpac=C4=B1?= Date: Mon, 1 May 2023 05:03:28 +0300 Subject: [PATCH 1/2] added cached content and cached conditions --- src/Darryldecode/Cart/Cart.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Darryldecode/Cart/Cart.php b/src/Darryldecode/Cart/Cart.php index 503dce7..9c1dd77 100644 --- a/src/Darryldecode/Cart/Cart.php +++ b/src/Darryldecode/Cart/Cart.php @@ -69,6 +69,10 @@ class Cart */ protected $currentItemId; + protected $cachedContent = null; + + protected $cachedConditions = null; + /** * our object constructor * @@ -397,7 +401,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 +680,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; } /** From fb0830a35538148433d587d36a929e94f6260f10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=BCleyman=20=C3=96zg=C3=BCr=20=C3=96zarpac=C4=B1?= Date: Mon, 1 May 2023 05:06:50 +0300 Subject: [PATCH 2/2] initialized cached condition and content in constructor --- src/Darryldecode/Cart/Cart.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Darryldecode/Cart/Cart.php b/src/Darryldecode/Cart/Cart.php index 9c1dd77..d919b00 100644 --- a/src/Darryldecode/Cart/Cart.php +++ b/src/Darryldecode/Cart/Cart.php @@ -69,9 +69,9 @@ class Cart */ protected $currentItemId; - protected $cachedContent = null; + protected $cachedContent; - protected $cachedConditions = null; + protected $cachedConditions; /** * our object constructor @@ -92,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'); }