razorisuru/shopping-cart
Composer 安装命令:
composer require razorisuru/shopping-cart
包简介
The ShoppingCart package provides a simple and flexible solution for managing a shopping cart in Laravel applications. It uses sessions to store cart items, allowing you to easily add, update, remove, and clear items. With support for custom attributes, price calculations, and total cost computation
README 文档
README
ShoppingCart is a simple and lightweight package for managing a shopping cart in Laravel applications using sessions. This package is ideal for e-commerce platforms or any project requiring shopping cart functionality.
Features
- Add items to the cart with quantity, price, and custom attributes.
- Update or remove items from the cart.
- Calculate the total cost of items in the cart.
- Clear all items in the cart.
- Session-based for seamless integration.
Installation
-
Clone the repository:
composer require razorisuru/shopping-cart
-
Configure Composer to use the token (Optional):
composer config --global github-oauth.github.com your-personal-access-token
Usage
Declare the cart:
use razorisuru\ShoppingCart\Cart; class ProductController extends Controller { protected $cart; public function __construct() { $this->cart = new Cart(); // Initialize an instance of the Cart class } }
-
Adding Items to the Cart:
$this->cart->add($userId = 1, $itemId = 101, $quantity = 2, $price = 10.50, $attributes = ['color' => 'red']);
-
Getting All Cart Items:
$this->items = $cart->getAll($userId = 1);
-
Updating an Item's Quantity:
$this->cart->update(1, 1, 5); // Update item with USERID 1, PRODUCTID 1 to have a quantity of 5
-
Removing an Item:
$this->cart->remove($userId = 1, $itemId = 101);
-
Clearing the Cart:
$this->cart->clear($userId = 1);
-
Calculating Total Cost:
$this->cart->total($userId = 1);
-
Counting the user cart items:
$this->cart->countQuantity($userId = 1);
-
Counting the user cart Product Count:
$this->cart->countProducts($userId = 1);
Requirements PHP 8.0 or newer Laravel 8 or newer illuminate/support
Contributing
Contributions are welcome! To contribute:
- Fork the repository.
- Create a feature branch:
git checkout -b feature-name. - Commit your changes:
git commit -m 'Add some feature'. - Push to the branch:
git push origin feature-name. - Open a pull request.
License
This project is open-sourced software licensed under the MIT license.
razorisuru/shopping-cart 适用场景与选型建议
razorisuru/shopping-cart 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 01 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cart」 「user」 「session」 「laravel」 「shopping」 「razorisuru」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 razorisuru/shopping-cart 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 razorisuru/shopping-cart 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 razorisuru/shopping-cart 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Secure session middleware for Slim 3 framework
Laravel 11 and above Shopping cart
Non-I/O blocking PHP SessionHandler implementation using Nette/Caching with DI Extension for Nette framework
Admin Hub for GetCandy. A modern headless e-commerce solution for Laravel PHP framework.
universal shopping basket
Magento - Clean up session extension
统计信息
- 总下载量: 10
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-01-09