diff --git a/composer.json b/composer.json index d2b0ad4..ff0757c 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,8 @@ "require": { "illuminate/support": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*", "illuminate/session": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*", - "illuminate/events": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*" + "illuminate/events": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*", + "nesbot/carbon": "^1.26.3" }, "require-dev": { "phpunit/phpunit": "~5.0|~6.0|~7.0", diff --git a/src/Cart.php b/src/Cart.php index 01c7ec9..429cc32 100644 --- a/src/Cart.php +++ b/src/Cart.php @@ -12,6 +12,7 @@ use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Database\DatabaseManager; use Illuminate\Session\SessionManager; use Illuminate\Support\Collection; +use Carbon\Carbon; class Cart { @@ -38,6 +39,20 @@ class Cart */ private $instance; + /** + * Holds the creation date of the cart + * + * @var mixed + */ + private $createdAt; + + /** + * Holds the update date of the cart + * + * @var mixed + */ + private $updatedAt; + /** * Defines the discount percentage. * @@ -580,7 +595,7 @@ class Cart 'identifier' => $identifier, 'instance' => $this->currentInstance(), 'content' => serialize($content), - 'created_at' => date('Y-m-d H:i:s'), + 'created_at' => $this->createdAt ?: date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s'), ]); @@ -625,6 +640,9 @@ class Cart $this->instance($currentInstance); + $this->createdAt = Carbon::parse(data_get($stored, 'created_at')); + $this->updatedAt = Carbon::parse(data_get($stored, 'updated_at')); + $this->getConnection()->table($this->getTableName()) ->where('identifier', $identifier)->delete(); } @@ -803,4 +821,24 @@ class Cart return number_format($value, $decimals, $decimalPoint, $thousandSeperator); } + + /** + * Get the creation date of the cart (db context). + * + * @return \Carbon\Carbon|null + */ + private function createdAt() + { + return $this->createdAt; + } + + /** + * Get the lats update date of the cart (db context). + * + * @return \Carbon\Carbon|null + */ + private function updatedAt() + { + return $this->createdAt; + } }