PHP code example of hahadu / think-cart-class

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

    

hahadu / think-cart-class example snippets




$cart = new Hahadu\ThinkCartClass\ThinkCartClass([
            'cartCookie' => true, //是否开启cookie ,默认为false 关闭cookie时将自动选择session

         //   'cartId' => md5($username.Request::server('http_host')), //设置购物车id 会自动加上'cartId_'前缀,
         //前缀可在项目配置文件‘cart.php’中设置

]);

$cart->getTotalItem()获取购物车商品数量

$cart->isCartEmpty()  //检查购物车是否为空

$cart->add('商品id','数量',[属性]) //添加商品

$cart->remove('商品id',[属性]) //删除单条

$cart->update('商品id','数量',[属性]) //修改购物车商品数量

$cart->getItems() //列出购物车里所有商品

$cart->clear();  //清空购物车