anam / phpcart
简单、无框架依赖的购物车框架
v1.1.0
2019-02-25 10:40 UTC
Requires
- php: >=5.4.0
- illuminate/support: ~5.0
- symfony/http-foundation: ~3.0|~4.0
Requires (Dev)
- phpunit/phpunit: ^6.4
This package is auto-updated.
Last update: 2024-09-26 12:47:14 UTC
README
简单、无框架依赖的购物车框架。
功能
- 简单API
- 支持多个购物车实例
- 无框架依赖
要求
- PHP 5.4+
安装
PHPCart可以通过Composer获取。
$ composer require anam/phpcart
Laravel集成
使用以下为PHPCart定制的laravel包。
https://github.com/anam-hossain/lara-phpcart
使用方法
添加商品
添加方法需要id
、name
、price
和quantity
键。然而,您可以传递应用程序所需的所有数据。
use Anam\Phpcart\Cart; $cart = new Cart(); $cart->add([ 'id' => 1001, 'name' => 'Skinny Jeans', 'quantity' => 1, 'price' => 90 ]);
更新商品
$cart->update([ 'id' => 1001, 'name' => 'Hoodie' ]);
更新数量
$cart->updateQty(1001, 3);
更新价格
$cart->updatePrice(1001, 30);
移除商品
$cart->remove(1001);
获取所有商品
$cart->getItems(); // or $cart->items();
获取一个商品
$cart->get(1001);
确定商品是否在购物车中
$cart->has(1001);
获取购物车中商品的总数
$cart->count();
获取购物车中商品的总数量
$cart->totalQuantity();
总计
$cart->getTotal();
清空购物车
$cart->clear();
多个购物车
PHPCart支持多个购物车实例,因此您可以在同一页面上拥有任意数量的购物车实例而不会发生冲突。
$cart = new Cart('cart1'); // or $cart->setCart('cart2'); $cart->add([ 'id' => 1001, 'name' => 'Skinny Jeans', 'quantity' => 1, 'price' => 90 ]); //or $cart->named('cart3')->add([ 'id' => 1001, 'name' => 'Jeans', 'quantity' => 2, 'price' => 100 ]);