PHP code example of darkflamed / moltin-cart

1. Go to this page and download the library: Download darkflamed/moltin-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/ */

    

darkflamed / moltin-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, file

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

    // Filesystem
    // Folder Name inside the Storage Path
    'storage_folder_name' => 'moltin_cart',

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