PHP code example of nethask / cart

1. Go to this page and download the library: Download nethask/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 / cart example snippets


use Moltin\Cart\Cart;
use Moltin\Cart\Storage\Session;
use Moltin\Cart\Identifier\Cookie;

$cart = new Cart(new Session, new Cookie);

$cart->insert(array(
    'id'       => 'foo',
    'name'     => 'bar',
    'price'    => 100,
    'quantity' => 1
));

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