bni/shoppingcart

为您的PHP项目提供购物车助手

dev-master 2019-10-06 14:53 UTC

This package is not auto-updated.

Last update: 2024-09-30 22:02:53 UTC


README

无需担心您的在线商店。只需使用此工具来存储临时购物车数据

安装

composer require bni/shoppingcart

购物车使用

基本结构

[{
    "id": 1,
    "name": "Cart name",
    "items": []
}]

获取所有购物车

$cart = Cart::get();

根据条件获取购物车

$cart = Cart::where(['id' => 1])->get();
// or
$cart = Cart::where(['name' => 'My cart'])->get();

创建新的购物车

$cart = Cart::add([
    'name' => 'Shopping Cart Name'
]);

编辑购物车

$cart = Cart::where(['id' => 1])->update([
    'name' => 'New Cart name'
]);

删除购物车

$cart = Cart::where(['id' => 1])->delete();

项目使用

基本结构

[{
    ...
    "items": [
        {
            "id": 1,
            "title": "Product name",
            "attributes": {
                "weight": 250
            }
        }
    ]
}]

您可以添加自己的属性

获取所有项目

$item = Cart::where(['id' => 1])->item()->get();

获取当前项目

$item = Cart::where(['id' => 1])->item(['id' => 2])->get();

item()参数类似于where(),您可以使用id或name

添加新项目

$item = Cart::where(['id' => 1])->item()->add([
    'title' => 'Your product item',
    'attributes' => [
        'weight' => 250
    ]
]);

删除项目

$item = Cart::where(['id' => 1])->item(['id' => 2])->delete();

编辑项目

$item = Cart::where(['id' => 1])->item(['id' => 2])->update([
    'title' => 'Edited product'
]);