购物车会话管理器

v1.0.0 2017-06-02 12:56 UTC

This package is not auto-updated.

Last update: 2024-09-26 06:40:31 UTC


README

使用会话管理购物车项。

安装

运行 composer require abstracteverything/cart 或在 composer.json 文件中添加

{
    "require": {
        "abstracteverything/cart": "dev-master"
    }
}

并运行 composer update

AbstractEverything\Cart\CartServiceProvider 添加到 providers 数组中。

使用 php artisan vendor:publish 导出配置文件。

使用

// Add cart items:

$cart->add(123abc, 'Grapes', 12.50, 2, [
    'variety' => 'green',
    'type' => 'seedless',
]);

// Add more than one item to the cart

$cart->addMany([
    [
        'id' => 'item1',
        'name' => 'Test item 1',
        'price' => 123,
        'quantity' => 1,
        'options' => [],
    ],
    [
        'id' => 'item2',
        'name' => 'Test item 2',
        'price' => 234,
        'quantity' => 2,
        'options' => [],
    ],
]);

// Find cart item by its id:

$cart->find(123abc);

// Get all the items in the cart:

$cart->all();

// Calculate total price of all items:

$cart->subtotal();

// Calculate the total tax of all items:

$cart->tax();

// Calculate total price with tax of all items:

$cart->subtotalWithTax();

// Remove an item by its id:

$cart->remove(123);

// Count the number of items in the cart:

$cart->count();

// Remove all items from the cart:

$cart->clear();