ksdev/shopping-cart
Composer 安装命令:
composer require ksdev/shopping-cart
包简介
Shopping cart
关键字:
README 文档
README
Original source: http://www.peachpit.com/articles/article.aspx?p=1962481 by Larry Ullman. See the article for description and compare source code for changes.
Install
Via Composer
$ composer require ksdev/shopping-cart
Usage
use Ksdev\ShoppingCart\Cart; use Ksdev\ShoppingCart\Currency; use Ksdev\ShoppingCart\Item; $cart = new Cart(new Currency('PLN')); $tax = '23.00'; // Tax is optional $item1 = new Item('SKU1', 'Item 1', '100.00', $tax); $item2 = new Item('SKU2', 'Item 2', '200.00', $tax); $item3 = new Item('SKU3', 'Item 3', '300.00', $tax); $cart->addItem($item1); $cart->addItem($item2); $cart->addItem($item3); if (!$cart->isEmpty()) { foreach ($cart as $arr) { $item = $arr['item']; var_dump($item->getSku()); // E.g. string(4) "SKU1" var_dump($item->getName()); // E.g. string(6) "Item 1" var_dump($item->getPrice()); // E.g. string(6) "100.00" var_dump($item->getTax()); // E.g. string(5) "23.00" var_dump($arr['qty']); // E.g. int(1) } } var_dump($cart->total()); // string(6) "600.00" var_dump($cart->getCurrency()->getCode()); // string(3) "PLN" $item4 = new Item('SKU1', 'Item 1', '100.00', $tax); // Same as $item1 $cart->addItem($item4); var_dump($cart->total()); // string(6) "700.00" var_dump($cart->count()); // int(4); also: count($cart) var_dump($cart->countUnique()); // int(3) $cart->updateItem($item2, 3); // 3 is the new quantity var_dump($cart->count()); // int(6) var_dump($cart->countUnique()); // int(3) $cart->updateItem($item2, 0); // Removes the item from the cart var_dump($cart->count()); // int(3) var_dump($cart->countUnique()); // int(2) $cart->deleteItem($item1); // Removes the item from the cart var_dump($cart->count()); // int(1) var_dump($cart->countUnique()); // int(1) var_dump($cart->getItem('SKU3')); // Get item by Stock Keeping Unit /* array(2) { 'item' => class Ksdev\ShoppingCart\Item#270 (3) { protected $sku => string(4) "SKU3" protected $name => string(6) "Item 3" protected $price => string(6) "300.00" protected $tax => string(5) "23.00" } 'qty' => int(1) } */
Testing
$ composer test
Credits
- Larry Ullman
License
The MIT License (MIT). Please see License File for more information.
ksdev/shopping-cart 适用场景与选型建议
ksdev/shopping-cart 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 112 次下载、GitHub Stars 达 2, 最近一次更新时间为 2015 年 08 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cart」 「shopping-cart」 「ksdev」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ksdev/shopping-cart 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ksdev/shopping-cart 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ksdev/shopping-cart 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Parser for the mBank MT940 daily statement export file format.
Retrieve average currency exchange rates from the NBP website and convert an amount from one currency to another.
Laravel 11 and above Shopping cart
Shopping Cart library for Laravel 5 that uses Database instead of Sessions
Admin Hub for GetCandy. A modern headless e-commerce solution for Laravel PHP framework.
AvoRed Laravel E commerce Assets Manager
统计信息
- 总下载量: 112
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 26
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-08-01