3 – Laravel Shopping Cart Package

aravel Facade and Service Provider for Moltin\Cart

Installation

To use, simply install the package via Composer and then add the following to your app/config/app.php to the service providers array:

'Moltin\Cart\CartServiceProvider',

Then add to the aliases array the following:

'Cart' => 'Moltin\Cart\Facade',

You should then be good to go and be able to access the cart using the following static interface:

// Format array of required info for item to be added to basket...
$items = array(
    'id' => 1,
    'name' => 'Juicy Picnic Hamper',
    'price' => 120.00,
    'quantity' => 1
);

// Make the insert...
Cart::insert($items);

// Let's see what we have have in there...
dd(Cart::totalItems());

Config settings (Optional)

Publish the config file with php artisan vendor:publish

return array(
    'storage' => 'session', //session, cache

    // Cache
    // Laravel documentation for more information
    'cache_prefix' => 'moltin_cart_',
    'cache_expire' => '-1', //in minutes, -1  permanent caching

    // Identifier
    // With a requestcookie (choose for storage: cache, the session will be expired), the cart could be reloaded from a http request, example: the customer could save his cart link (email, hyperlink) and reopen this later.
    // If there is no request, the cookie will be loaded.
    'identifier' => 'cookie', //cookie, requestcookie

    //Request Cookie
    'requestid' => 'CartID', //http input request identifier, example: your customer/backoffice could reload the cart in your shop controller, /public/shop?CartID=871f0bc18ca76e68bf7c3adf8f9426ef
);