PHP code example of pashamesh / cart

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

    

pashamesh / cart example snippets


use voku\Cart\Cart;
use voku\Cart\Storage\Session;
use voku\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)
{
    $cart->remove($item->getIdentifier());
    // or even
    $cart->remove($item);
}

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