PHP code example of lenius / basket

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

    

lenius / basket example snippets


use Lenius\Basket\Basket;
use Lenius\Basket\Storage\Session;
use Lenius\Basket\Identifier\Cookie;

$basket = new Basket(new Session, new Cookie);

$basket->insert(new Item([
    'id'       => 'foo',
    'name'     => 'bar',
    'price'    => 100,
    'quantity' => 2,
    'weight'   => 300
]));


$basket->insert(new Item([
    'id'         => 'foo',
    'name'       => 'bar',
    'price'      => 100,
    'quantity'   => 2,
    'weight'     => 300,
    'options'    => [
       [
        'name'   => 'Size',
        'value'  => 'L',
        'weight' => 50,
        'price'  => 10
       ],
     ],
]));

$basket->insert(new Item([
    'id'       => 'mouseid',
    'name'     => 'Mouse',
    'price'    => 100,
    'quantity' => 1,
    'tax'      => 25,
    'weight'   => 200
]));

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

$basket->destroy()

$basket->contents();

$basket->contents(true);

$basket->totalItems();

$basket->total();

$basket->total(false);

$basket->has($itemIdentifier);

$basket->remove($identifier)

$basket->item($itemIdentifier);

foreach ($basket->contents() as $item) {
    if ($item->hasOptions()) {
        // We have options
    }
}

$item->weight();

$item->toArray();