PHP code example of mustang / shoppingcart

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

    

mustang / shoppingcart example snippets


// redis相关配置
'redis' => [
    'host' => '127.0.0.1',
    'port' => 6379,
    'auth' => '',
    'db_id' => 4
]

// 购物车存储介质配置,如不配置默认使用redis。
'cart' => [
    'driver' => 'redis'
]

/**
 * 获取购物车全数据
 * 商品数据(商品 id|SKU id)&对应数量
 * @param int $uid 用户ID
 * @param null $zone 分片
 * @return array
 */
ShoppingCart::cartList($uid, $zone=null);

/**
 * 购物车添加/减少商品
 * @param int $gid 商品|sku id
 * @param int $gnum 操作数量
 * @param int $uid 用户id
 * @param null $zone 分片
 * @return bool
 */
ShoppingCart::cartOper($gid, $gnum, $uid, $zone=null);

/**
 * 更新购物车中单件商品的SKU
 * @param $gid int 目标商品|SKU id
 * @param $old_gid int 原商品|SKU id
 * @param $uid int 用户id
 * @param $zone null 分片
 */
 ShoppingCart::cartUpdateSku($gid, $old_gid, $uid, $zone=null);

/**
 * 从购物车中删除单种商品
 * @param int $gid 商品标识
 * @param int $uid 用户id
 * @param null $zone 分片
 */
ShoppingCart::cartDelSingle($gid, $uid, $zone=null);

/**
 * 清空购物车
 * @param int $uid 用户id
 * @param null $zone 分片
 */
ShoppingCart::cartClearAll($uid, $zone=null);

/**
 * 购物车是否存在某商品
 * @param $gid int 商品标识
 * @param $uid int 用户id
 * @param $zone null
 * @return bool
 */
ShoppingCart::cartExistsGoods($gid, $uid, $zone=null)