PHP code example of nethask / laravel-cart

1. Go to this page and download the library: Download nethask/laravel-cart library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nethask / laravel-cart example snippets


'Moltin\Cart\CartServiceProvider',

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

// Format array of 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());


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
);

Cart::insert(array(
    'id'       => 'foo',
    'name'     => 'bar',
    'price'    => 100,
    'quantity' => 1,
    'tax'      => 20
));

foreach (Cart::contents() as $item) {
    $item->name = 'Foo';
    $item->quantity = 1;
}

foreach (Cart::contents() as $item) {
    $item->remove();
}

Cart::destroy()

Cart::contents();

Cart::contents(true);

Cart::totalItems();

Cart::totalItems(true);

$cart->total();

Cart::total(false);

Cart::has($itemIdentifier);

Cart::item($itemIdentifier);

$item->total();

$item->total(false);

if ($item->hasOptions()) {
    // We have options
}

$item->remove();

$item->toArray();