Added fields for created and updated at

Added getters
needs testing
This commit is contained in:
Patrick Henninger
2019-02-18 16:02:56 +01:00
parent f8445b4d45
commit 698098139b
2 changed files with 41 additions and 2 deletions

View File

@@ -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",

View File

@@ -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;
}
}