一个购物车插件

分享链接: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查询不到)
    }
}
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 1
playmaker

支持 组合产品吗?

4年前 评论

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