allow vendord
All checks were successful
Build, Push and Deploy / build-and-push (push) Successful in 3m3s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 16s
Build, Push and Deploy / deploy-staging (push) Successful in 32s
Build, Push and Deploy / deploy-production (push) Has been skipped
Build, Push and Deploy / cleanup (push) Successful in 1s

This commit is contained in:
2026-03-30 14:54:57 +07:00
parent 66aed7c4e8
commit b5e3a778ce
21316 changed files with 2777892 additions and 13 deletions

View File

@@ -0,0 +1,43 @@
<?php
namespace Gloudemans\Shoppingcart;
trait CanBeBought
{
/**
* Get the identifier of the Buyable item.
*
* @return int|string
*/
public function getBuyableIdentifier($options = null)
{
return method_exists($this, 'getKey') ? $this->getKey() : $this->id;
}
/**
* Get the description or title of the Buyable item.
*
* @return string
*/
public function getBuyableDescription($options = null)
{
if(property_exists($this, 'name')) return $this->name;
if(property_exists($this, 'title')) return $this->title;
if(property_exists($this, 'description')) return $this->description;
return null;
}
/**
* Get the price of the Buyable item.
*
* @return float
*/
public function getBuyablePrice($options = null)
{
if(property_exists($this, 'price')) return $this->price;
return null;
}
}

View File

@@ -0,0 +1,578 @@
<?php
namespace Gloudemans\Shoppingcart;
use Closure;
use Illuminate\Support\Collection;
use Illuminate\Session\SessionManager;
use Illuminate\Database\DatabaseManager;
use Illuminate\Contracts\Events\Dispatcher;
use Gloudemans\Shoppingcart\Contracts\Buyable;
use Gloudemans\Shoppingcart\Exceptions\UnknownModelException;
use Gloudemans\Shoppingcart\Exceptions\InvalidRowIDException;
use Gloudemans\Shoppingcart\Exceptions\CartAlreadyStoredException;
class Cart
{
const DEFAULT_INSTANCE = 'default';
/**
* Instance of the session manager.
*
* @var \Illuminate\Session\SessionManager
*/
protected $session;
/**
* Instance of the event dispatcher.
*
* @var \Illuminate\Contracts\Events\Dispatcher
*/
private $events;
/**
* Holds the current cart instance.
*
* @var string
*/
private $instance;
/**
* Cart constructor.
*
* @param \Illuminate\Session\SessionManager $session
* @param \Illuminate\Contracts\Events\Dispatcher $events
*/
public function __construct(SessionManager $session, Dispatcher $events)
{
$this->session = $session;
$this->events = $events;
$this->instance(self::DEFAULT_INSTANCE);
}
/**
* Set the current cart instance.
*
* @param string|null $instance
* @return \Gloudemans\Shoppingcart\Cart
*/
public function instance($instance = null)
{
$instance = $instance ?: self::DEFAULT_INSTANCE;
$this->instance = sprintf('%s.%s', 'cart', $instance);
return $this;
}
/**
* Get the current cart instance.
*
* @return string
*/
public function currentInstance()
{
return str_replace('cart.', '', $this->instance);
}
/**
* Add an item to the cart.
*
* @param mixed $id
* @param mixed $name
* @param int|float $qty
* @param float $price
* @param array $options
* @param float $taxrate
* @return \Gloudemans\Shoppingcart\CartItem
*/
public function add($id, $name = null, $qty = null, $price = null, array $options = [], $taxrate = null)
{
if ($this->isMulti($id)) {
return array_map(function ($item) {
return $this->add($item);
}, $id);
}
if ($id instanceof CartItem) {
$cartItem = $id;
} else {
$cartItem = $this->createCartItem($id, $name, $qty, $price, $options, $taxrate);
}
$content = $this->getContent();
if ($content->has($cartItem->rowId)) {
$cartItem->qty += $content->get($cartItem->rowId)->qty;
}
$content->put($cartItem->rowId, $cartItem);
$this->events->dispatch('cart.added', $cartItem);
$this->session->put($this->instance, $content);
return $cartItem;
}
/**
* Update the cart item with the given rowId.
*
* @param string $rowId
* @param mixed $qty
* @return \Gloudemans\Shoppingcart\CartItem
*/
public function update($rowId, $qty)
{
$cartItem = $this->get($rowId);
if ($qty instanceof Buyable) {
$cartItem->updateFromBuyable($qty);
} elseif (is_array($qty)) {
$cartItem->updateFromArray($qty);
} else {
$cartItem->qty = $qty;
}
$content = $this->getContent();
if ($rowId !== $cartItem->rowId) {
$content->pull($rowId);
if ($content->has($cartItem->rowId)) {
$existingCartItem = $this->get($cartItem->rowId);
$cartItem->setQuantity($existingCartItem->qty + $cartItem->qty);
}
}
if ($cartItem->qty <= 0) {
$this->remove($cartItem->rowId);
return;
} else {
$content->put($cartItem->rowId, $cartItem);
}
$this->events->dispatch('cart.updated', $cartItem);
$this->session->put($this->instance, $content);
return $cartItem;
}
/**
* Remove the cart item with the given rowId from the cart.
*
* @param string $rowId
* @return void
*/
public function remove($rowId)
{
$cartItem = $this->get($rowId);
$content = $this->getContent();
$content->pull($cartItem->rowId);
$this->events->dispatch('cart.removed', $cartItem);
$this->session->put($this->instance, $content);
}
/**
* Get a cart item from the cart by its rowId.
*
* @param string $rowId
* @return \Gloudemans\Shoppingcart\CartItem
*/
public function get($rowId)
{
$content = $this->getContent();
if ( ! $content->has($rowId))
throw new InvalidRowIDException("The cart does not contain rowId {$rowId}.");
return $content->get($rowId);
}
/**
* Destroy the current cart instance.
*
* @return void
*/
public function destroy()
{
$this->session->remove($this->instance);
}
/**
* Get the content of the cart.
*
* @return \Illuminate\Support\Collection
*/
public function content()
{
if (is_null($this->session->get($this->instance))) {
return new Collection([]);
}
return $this->session->get($this->instance);
}
/**
* Get the number of items in the cart.
*
* @return int|float
*/
public function count()
{
$content = $this->getContent();
return $content->sum('qty');
}
/**
* Get the total price of the items in the cart.
*
* @param int $decimals
* @param string $decimalPoint
* @param string $thousandSeperator
* @return string
*/
public function total($decimals = null, $decimalPoint = null, $thousandSeperator = null)
{
$content = $this->getContent();
$total = $content->reduce(function ($total, CartItem $cartItem) {
return $total + ($cartItem->qty * $cartItem->priceTax);
}, 0);
return $this->numberFormat($total, $decimals, $decimalPoint, $thousandSeperator);
}
/**
* Get the total tax of the items in the cart.
*
* @param int $decimals
* @param string $decimalPoint
* @param string $thousandSeperator
* @return float
*/
public function tax($decimals = null, $decimalPoint = null, $thousandSeperator = null)
{
$content = $this->getContent();
$tax = $content->reduce(function ($tax, CartItem $cartItem) {
return $tax + ($cartItem->qty * $cartItem->tax);
}, 0);
return $this->numberFormat($tax, $decimals, $decimalPoint, $thousandSeperator);
}
/**
* Get the subtotal (total - tax) of the items in the cart.
*
* @param int $decimals
* @param string $decimalPoint
* @param string $thousandSeperator
* @return float
*/
public function subtotal($decimals = null, $decimalPoint = null, $thousandSeperator = null)
{
$content = $this->getContent();
$subTotal = $content->reduce(function ($subTotal, CartItem $cartItem) {
return $subTotal + ($cartItem->qty * $cartItem->price);
}, 0);
return $this->numberFormat($subTotal, $decimals, $decimalPoint, $thousandSeperator);
}
/**
* Search the cart content for a cart item matching the given search closure.
*
* @param \Closure $search
* @return \Illuminate\Support\Collection
*/
public function search(Closure $search)
{
$content = $this->getContent();
return $content->filter($search);
}
/**
* Associate the cart item with the given rowId with the given model.
*
* @param string $rowId
* @param mixed $model
* @return void
*/
public function associate($rowId, $model)
{
if(is_string($model) && ! class_exists($model)) {
throw new UnknownModelException("The supplied model {$model} does not exist.");
}
$cartItem = $this->get($rowId);
$cartItem->associate($model);
$content = $this->getContent();
$content->put($cartItem->rowId, $cartItem);
$this->session->put($this->instance, $content);
}
/**
* Set the tax rate for the cart item with the given rowId.
*
* @param string $rowId
* @param int|float $taxRate
* @return void
*/
public function setTax($rowId, $taxRate)
{
$cartItem = $this->get($rowId);
$cartItem->setTaxRate($taxRate);
$content = $this->getContent();
$content->put($cartItem->rowId, $cartItem);
$this->session->put($this->instance, $content);
}
/**
* Store an the current instance of the cart.
*
* @param mixed $identifier
* @return void
*/
public function store($identifier)
{
$content = $this->getContent();
$this->getConnection()
->table($this->getTableName())
->where('identifier', $identifier)
->where('instance', $this->currentInstance())
->delete();
$this->getConnection()->table($this->getTableName())->insert([
'identifier' => $identifier,
'instance' => $this->currentInstance(),
'content' => serialize($content),
'created_at'=> new \DateTime()
]);
$this->events->dispatch('cart.stored');
}
/**
* Restore the cart with the given identifier.
*
* @param mixed $identifier
* @return void
*/
public function restore($identifier)
{
if( ! $this->storedCartWithIdentifierExists($identifier)) {
return;
}
$stored = $this->getConnection()->table($this->getTableName())
->where('instance', $this->currentInstance())
->where('identifier', $identifier)->first();
$storedContent = unserialize(data_get($stored, 'content'));
$currentInstance = $this->currentInstance();
$this->instance(data_get($stored, 'instance'));
$content = $this->getContent();
foreach ($storedContent as $cartItem) {
$content->put($cartItem->rowId, $cartItem);
}
$this->events->dispatch('cart.restored');
$this->session->put($this->instance, $content);
$this->instance($currentInstance);
}
/**
* Deletes the stored cart with given identifier
*
* @param mixed $identifier
*/
public function deleteStoredCart($identifier) {
$this->getConnection()
->table($this->getTableName())
->where('identifier', $identifier)
->delete();
}
/**
* Magic method to make accessing the total, tax and subtotal properties possible.
*
* @param string $attribute
* @return float|null
*/
public function __get($attribute)
{
if($attribute === 'total') {
return $this->total();
}
if($attribute === 'tax') {
return $this->tax();
}
if($attribute === 'subtotal') {
return $this->subtotal();
}
return null;
}
/**
* Get the carts content, if there is no cart content set yet, return a new empty Collection
*
* @return \Illuminate\Support\Collection
*/
protected function getContent()
{
$content = $this->session->has($this->instance)
? $this->session->get($this->instance)
: new Collection;
return $content;
}
/**
* Create a new CartItem from the supplied attributes.
*
* @param mixed $id
* @param mixed $name
* @param int|float $qty
* @param float $price
* @param array $options
* @param float $taxrate
* @return \Gloudemans\Shoppingcart\CartItem
*/
private function createCartItem($id, $name, $qty, $price, array $options, $taxrate)
{
if ($id instanceof Buyable) {
$cartItem = CartItem::fromBuyable($id, $qty ?: []);
$cartItem->setQuantity($name ?: 1);
$cartItem->associate($id);
} elseif (is_array($id)) {
$cartItem = CartItem::fromArray($id);
$cartItem->setQuantity($id['qty']);
} else {
$cartItem = CartItem::fromAttributes($id, $name, $price, $options);
$cartItem->setQuantity($qty);
}
if(isset($taxrate) && is_numeric($taxrate)) {
$cartItem->setTaxRate($taxrate);
} else {
$cartItem->setTaxRate(config('cart.tax'));
}
return $cartItem;
}
/**
* Check if the item is a multidimensional array or an array of Buyables.
*
* @param mixed $item
* @return bool
*/
private function isMulti($item)
{
if ( ! is_array($item)) return false;
return is_array(head($item)) || head($item) instanceof Buyable;
}
/**
* @param $identifier
* @return bool
*/
protected function storedCartWithIdentifierExists($identifier)
{
return $this->getConnection()->table($this->getTableName())->where('identifier', $identifier)->where('instance', $this->currentInstance())->exists();
}
/**
* Get the database connection.
*
* @return \Illuminate\Database\Connection
*/
protected function getConnection()
{
$connectionName = $this->getConnectionName();
return app(DatabaseManager::class)->connection($connectionName);
}
/**
* Get the database table name.
*
* @return string
*/
protected function getTableName()
{
return config('cart.database.table', 'shoppingcart');
}
/**
* Get the database connection name.
*
* @return string
*/
private function getConnectionName()
{
$connection = config('cart.database.connection');
return is_null($connection) ? config('database.default') : $connection;
}
/**
* Get the Formated number
*
* @param $value
* @param $decimals
* @param $decimalPoint
* @param $thousandSeperator
* @return string
*/
private function numberFormat($value, $decimals, $decimalPoint, $thousandSeperator)
{
if(is_null($decimals)){
$decimals = is_null(config('cart.format.decimals')) ? 2 : config('cart.format.decimals');
}
if(is_null($decimalPoint)){
$decimalPoint = is_null(config('cart.format.decimal_point')) ? '.' : config('cart.format.decimal_point');
}
if(is_null($thousandSeperator)){
$thousandSeperator = is_null(config('cart.format.thousand_seperator')) ? ',' : config('cart.format.thousand_seperator');
}
return number_format($value, $decimals, $decimalPoint, $thousandSeperator);
}
}

View File

@@ -0,0 +1,420 @@
<?php
namespace Gloudemans\Shoppingcart;
use Illuminate\Contracts\Support\Arrayable;
use Gloudemans\Shoppingcart\Contracts\Buyable;
use Illuminate\Contracts\Support\Jsonable;
use Illuminate\Support\Arr;
class CartItem implements Arrayable, Jsonable
{
/**
* The rowID of the cart item.
*
* @var string
*/
public $rowId;
/**
* The ID of the cart item.
*
* @var int|string
*/
public $id;
/**
* The quantity for this cart item.
*
* @var int|float
*/
public $qty;
/**
* The name of the cart item.
*
* @var string
*/
public $name;
/**
* The price without TAX of the cart item.
*
* @var float
*/
public $price;
/**
* The options for this cart item.
*
* @var array
*/
public $options;
/**
* The FQN of the associated model.
*
* @var string|null
*/
private $associatedModel = null;
/**
* The tax rate for the cart item.
*
* @var int|float
*/
private $taxRate = 0;
/**
* Is item saved for later.
*
* @var boolean
*/
private $isSaved = false;
/**
* CartItem constructor.
*
* @param int|string $id
* @param string $name
* @param float $price
* @param array $options
*/
public function __construct($id, $name, $price, array $options = [])
{
if(empty($id)) {
throw new \InvalidArgumentException('Please supply a valid identifier.');
}
if(empty($name)) {
throw new \InvalidArgumentException('Please supply a valid name.');
}
if(strlen($price) < 0 || ! is_numeric($price)) {
throw new \InvalidArgumentException('Please supply a valid price.');
}
$this->id = $id;
$this->name = $name;
$this->price = floatval($price);
$this->options = new CartItemOptions($options);
$this->rowId = $this->generateRowId($id, $options);
}
/**
* Returns the formatted price without TAX.
*
* @param int $decimals
* @param string $decimalPoint
* @param string $thousandSeperator
* @return string
*/
public function price($decimals = null, $decimalPoint = null, $thousandSeperator = null)
{
return $this->numberFormat($this->price, $decimals, $decimalPoint, $thousandSeperator);
}
/**
* Returns the formatted price with TAX.
*
* @param int $decimals
* @param string $decimalPoint
* @param string $thousandSeperator
* @return string
*/
public function priceTax($decimals = null, $decimalPoint = null, $thousandSeperator = null)
{
return $this->numberFormat($this->priceTax, $decimals, $decimalPoint, $thousandSeperator);
}
/**
* Returns the formatted subtotal.
* Subtotal is price for whole CartItem without TAX
*
* @param int $decimals
* @param string $decimalPoint
* @param string $thousandSeperator
* @return string
*/
public function subtotal($decimals = null, $decimalPoint = null, $thousandSeperator = null)
{
return $this->numberFormat($this->subtotal, $decimals, $decimalPoint, $thousandSeperator);
}
/**
* Returns the formatted total.
* Total is price for whole CartItem with TAX
*
* @param int $decimals
* @param string $decimalPoint
* @param string $thousandSeperator
* @return string
*/
public function total($decimals = null, $decimalPoint = null, $thousandSeperator = null)
{
return $this->numberFormat($this->total, $decimals, $decimalPoint, $thousandSeperator);
}
/**
* Returns the formatted tax.
*
* @param int $decimals
* @param string $decimalPoint
* @param string $thousandSeperator
* @return string
*/
public function tax($decimals = null, $decimalPoint = null, $thousandSeperator = null)
{
return $this->numberFormat($this->tax, $decimals, $decimalPoint, $thousandSeperator);
}
/**
* Returns the formatted tax.
*
* @param int $decimals
* @param string $decimalPoint
* @param string $thousandSeperator
* @return string
*/
public function taxTotal($decimals = null, $decimalPoint = null, $thousandSeperator = null)
{
return $this->numberFormat($this->taxTotal, $decimals, $decimalPoint, $thousandSeperator);
}
/**
* Set the quantity for this cart item.
*
* @param int|float $qty
*/
public function setQuantity($qty)
{
if(empty($qty) || ! is_numeric($qty))
throw new \InvalidArgumentException('Please supply a valid quantity.');
$this->qty = $qty;
}
/**
* Update the cart item from a Buyable.
*
* @param \Gloudemans\Shoppingcart\Contracts\Buyable $item
* @return void
*/
public function updateFromBuyable(Buyable $item)
{
$this->id = $item->getBuyableIdentifier($this->options);
$this->name = $item->getBuyableDescription($this->options);
$this->price = $item->getBuyablePrice($this->options);
$this->priceTax = $this->price + $this->tax;
}
/**
* Update the cart item from an array.
*
* @param array $attributes
* @return void
*/
public function updateFromArray(array $attributes)
{
$this->id = Arr::get($attributes, 'id', $this->id);
$this->qty = Arr::get($attributes, 'qty', $this->qty);
$this->name = Arr::get($attributes, 'name', $this->name);
$this->price = Arr::get($attributes, 'price', $this->price);
$this->priceTax = $this->price + $this->tax;
$this->options = new CartItemOptions(Arr::get($attributes, 'options', $this->options));
$this->rowId = $this->generateRowId($this->id, $this->options->all());
}
/**
* Associate the cart item with the given model.
*
* @param mixed $model
* @return \Gloudemans\Shoppingcart\CartItem
*/
public function associate($model)
{
$this->associatedModel = is_string($model) ? $model : get_class($model);
return $this;
}
/**
* Set the tax rate.
*
* @param int|float $taxRate
* @return \Gloudemans\Shoppingcart\CartItem
*/
public function setTaxRate($taxRate)
{
$this->taxRate = $taxRate;
return $this;
}
/**
* Set saved state.
*
* @param bool $bool
* @return \Gloudemans\Shoppingcart\CartItem
*/
public function setSaved($bool)
{
$this->isSaved = $bool;
return $this;
}
/**
* Get an attribute from the cart item or get the associated model.
*
* @param string $attribute
* @return mixed
*/
public function __get($attribute)
{
if(property_exists($this, $attribute)) {
return $this->{$attribute};
}
if ($attribute === 'priceTax') {
return number_format(($this->price + $this->tax), 2, '.', '');
}
if ($attribute === 'subtotal') {
return number_format(($this->qty * $this->price), 2, '.', '');
}
if ($attribute === 'total') {
return number_format(($this->qty * $this->priceTax), 2, '.', '');
}
if ($attribute === 'tax') {
return number_format(($this->price * ($this->taxRate / 100)), 2, '.', '');
}
if ($attribute === 'taxTotal') {
return number_format(($this->tax * $this->qty), 2, '.', '');
}
if($attribute === 'model' && isset($this->associatedModel)) {
return with(new $this->associatedModel)->find($this->id);
}
return null;
}
/**
* Create a new instance from a Buyable.
*
* @param \Gloudemans\Shoppingcart\Contracts\Buyable $item
* @param array $options
* @return \Gloudemans\Shoppingcart\CartItem
*/
public static function fromBuyable(Buyable $item, array $options = [])
{
return new self($item->getBuyableIdentifier($options), $item->getBuyableDescription($options), $item->getBuyablePrice($options), $options);
}
/**
* Create a new instance from the given array.
*
* @param array $attributes
* @return \Gloudemans\Shoppingcart\CartItem
*/
public static function fromArray(array $attributes)
{
$options = Arr::get($attributes, 'options', []);
return new self($attributes['id'], $attributes['name'], $attributes['price'], $options);
}
/**
* Create a new instance from the given attributes.
*
* @param int|string $id
* @param string $name
* @param float $price
* @param array $options
* @return \Gloudemans\Shoppingcart\CartItem
*/
public static function fromAttributes($id, $name, $price, array $options = [])
{
return new self($id, $name, $price, $options);
}
/**
* Generate a unique id for the cart item.
*
* @param string $id
* @param array $options
* @return string
*/
protected function generateRowId($id, array $options)
{
ksort($options);
return md5($id . serialize($options));
}
/**
* Get the instance as an array.
*
* @return array
*/
public function toArray()
{
return [
'rowId' => $this->rowId,
'id' => $this->id,
'name' => $this->name,
'qty' => $this->qty,
'price' => $this->price,
'options' => $this->options->toArray(),
'tax' => $this->tax,
'isSaved' => $this->isSaved,
'subtotal' => $this->subtotal
];
}
/**
* Convert the object to its JSON representation.
*
* @param int $options
* @return string
*/
public function toJson($options = 0)
{
if (isset($this->associatedModel)){
return json_encode(array_merge($this->toArray(), ['model' => $this->model]), $options);
}
return json_encode($this->toArray(), $options);
}
/**
* Get the formatted number.
*
* @param float $value
* @param int $decimals
* @param string $decimalPoint
* @param string $thousandSeperator
* @return string
*/
private function numberFormat($value, $decimals = null, $decimalPoint = null, $thousandSeperator = null)
{
if (is_null($decimals)){
$decimals = is_null(config('cart.format.decimals')) ? 2 : config('cart.format.decimals');
}
if (is_null($decimalPoint)){
$decimalPoint = is_null(config('cart.format.decimal_point')) ? '.' : config('cart.format.decimal_point');
}
if (is_null($thousandSeperator)){
$thousandSeperator = is_null(config('cart.format.thousand_seperator')) ? ',' : config('cart.format.thousand_seperator');
}
return number_format($value, $decimals, $decimalPoint, $thousandSeperator);
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace Gloudemans\Shoppingcart;
use Illuminate\Support\Collection;
class CartItemOptions extends Collection
{
/**
* Get the option by the given key.
*
* @param string $key
* @return mixed
*/
public function __get($key)
{
return $this->get($key);
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace Gloudemans\Shoppingcart\Contracts;
interface Buyable
{
/**
* Get the identifier of the Buyable item.
*
* @return int|string
*/
public function getBuyableIdentifier($options = null);
/**
* Get the description or title of the Buyable item.
*
* @return string
*/
public function getBuyableDescription($options = null);
/**
* Get the price of the Buyable item.
*
* @return float
*/
public function getBuyablePrice($options = null);
}

View File

@@ -0,0 +1,7 @@
<?php
namespace Gloudemans\Shoppingcart\Exceptions;
use RuntimeException;
class CartAlreadyStoredException extends RuntimeException {}

View File

@@ -0,0 +1,7 @@
<?php
namespace Gloudemans\Shoppingcart\Exceptions;
use RuntimeException;
class InvalidRowIDException extends RuntimeException {}

View File

@@ -0,0 +1,7 @@
<?php
namespace Gloudemans\Shoppingcart\Exceptions;
use RuntimeException;
class UnknownModelException extends RuntimeException {}

View File

@@ -0,0 +1,16 @@
<?php
namespace Gloudemans\Shoppingcart\Facades;
use Illuminate\Support\Facades\Facade;
class Cart extends Facade {
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'cart';
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace Gloudemans\Shoppingcart;
use Illuminate\Auth\Events\Logout;
use Illuminate\Session\SessionManager;
use Illuminate\Support\ServiceProvider;
class ShoppingcartServiceProvider extends ServiceProvider
{
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app->bind('cart', 'Gloudemans\Shoppingcart\Cart');
$config = __DIR__ . '/../config/cart.php';
$this->mergeConfigFrom($config, 'cart');
$this->publishes([__DIR__ . '/../config/cart.php' => config_path('cart.php')], 'config');
$this->app['events']->listen(Logout::class, function () {
if ($this->app['config']->get('cart.destroy_on_logout')) {
$this->app->make(SessionManager::class)->forget('cart');
}
});
if ( ! class_exists('CreateShoppingcartTable')) {
// Publish the migration
$timestamp = date('Y_m_d_His', time());
$this->publishes([
__DIR__.'/../database/migrations/0000_00_00_000000_create_shoppingcart_table.php' => database_path('migrations/'.$timestamp.'_create_shoppingcart_table.php'),
], 'migrations');
}
}
}