一个购物车插件
分享链接: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查询不到)
}
}
支持 组合产品吗?