mirror of
https://github.com/kevin-DL/LaravelShoppingcart.git
synced 2026-01-11 18:54:33 +00:00
Added fields for created and updated at
Added getters needs testing
This commit is contained in:
@@ -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",
|
||||
|
||||
40
src/Cart.php
40
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user