PHP code example of jsnlib / cart

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

    

jsnlib / cart example snippets

 
session_start();
$cart = new Jsnlib\Cart('jsnlibCart');

$ary = 
[
    'primaryid' => 'JSN5000000',
    'name'      => 'A款衣服',
    'price'     => 399,
    'quantity'  => 2,
    'option'    =>      
    [
        'productid' => 'A00001',
        'size'      => 'XL',
    ]
];
$cart->insert($ary);

$ary = 
[
    'primaryid' => 'JSN5000003',
    'quantity'  => 12
];
$cart->update($ary);

$cart->isnew('JSN5000003'); 

$cart->delete('JSN5000003');

$cart->get('JSN5000000');

$cart->insert(
[
    'primaryid' => '0001',
    'name'      => 'A款衣服',
    'price'     => 100,
    'quantity'  => 10,
    'option'    =>      
    [
        'size'      => 's',
    ]
]);

$cart->insert(
[
    'primaryid' => '0002',
    'name'      => 'B款衣服',
    'price'     => 200,
    'quantity'  => 10,
    'option'    =>      
    [
        'size'      => 'xl',
    ]
]);

$cart->find(['quantity' => 10]); // A款衣服 + B款衣服
$cart->find(['option' => ['size' => 'xl']]); // B款衣服

$cart->truncate();

$cart->order();

$cart->order(['Transport']);

$cart->total();

$cart->total(['Transport']);