一个购物车插件

分享链接:https://github.com/china-david/laravel-car...
一个简单的购物车插件

use Tanwen\Cart\Facades\Cart;  //加载facades

try {
    Cart::add(商品ID, (+-)数量, 店铺ID(可选 ));
    return $this->_ajaxResponse(0, '添加成功');
}catch (CartMessageException $exception){
    return $this->_ajaxResponse(1, $exception->getMessage());
}

$items = Cart::items(); 获取购物车商品

$items = Cart::items(function($item){
    $item 等同下面的$item
}); //获取购物车商品,过滤function返回不为true的数据

foreach($items as $shop_id => $data){
    foreach($data as $goods_id => $item){
        $item->quantity //商品数量
        $item->getPrice() //商品价格
        $item->getTotal() //商品小计
        $item->model(); //获取配置的商品Eloquent
        $item->hasValidity(); //判断商品是否有效
        $item->getStatus(); //string: 正常、库存不足、 商品无效或已下架(model查询不到)
    }
}
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 1
playmaker

支持 组合产品吗?

2年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!