ingenius/shopcart
Composer 安装命令:
composer require ingenius/shopcart
包简介
Ingenius ShopCart Package
README 文档
README
A Laravel package for implementing shopping cart functionality with modifiers support.
Installation
composer require ingenius/shopcart
Features
- Add products to cart (supports polymorphic relationships)
- Remove products from cart
- Delete cart items
- Get cart items
- Cart modifiers system for extending functionality
- Session-based cart for guests
- User-based cart for authenticated users
Configuration
Environment Variables
PRODUCT_MODEL=Ingenius\Products\Models\Product
Note: For backward compatibility,
SHOPCART_PRODUCT_MODELis still supported butPRODUCT_MODELis preferred as it's used across all packages.
ShopCart Modifier System
The ShopCart package includes a modifier system that allows other packages to extend the cart's functionality without the ShopCart package needing to know about them.
Features
- Add custom calculations to the cart total (shipping, discounts, taxes, etc.)
- Extend the cart's JSON/array output with additional data
- Control the execution order of modifiers using priorities
- Easy to implement in other packages
How It Works
The ShopCart uses a pipeline approach with modifiers that:
- Calculate subtotals in priority order (lower numbers run first)
- Extend the
toArray()output with custom values from each modifier - Allow precise control over execution order
Creating Your Own Modifier
To create a new cart modifier in your package:
- Create a class that extends
BaseCartModifieror implementsCartModifierInterface - Set its priority to control when it runs (lower = earlier)
- Register it with the
CartModifierManagerin your package's service provider
Example Modifier
<?php namespace YourPackage\CartModifiers; use Ingenius\ShopCart\Modifiers\BaseCartModifier; use Ingenius\ShopCart\Services\ShopCart; class YourModifier extends BaseCartModifier { /** * Set priority - lower numbers run first */ public function getPriority(): int { return 50; // Run after the base item subtotal calculations } /** * Modify the subtotal */ public function calculateSubtotal(ShopCart $cart, float $currentSubtotal): float { // Your custom calculation logic here $yourModification = 10.00; // Store data for use in extendCartArray $this->yourData = $yourModification; // Return modified subtotal return $currentSubtotal + $yourModification; } /** * Add data to the cart array */ public function extendCartArray(ShopCart $cart, array $cartArray): array { $cartArray['your_data'] = [ 'amount' => $this->yourData, 'other_info' => 'Custom information' ]; return $cartArray; } protected $yourData; }
Registering Your Modifier
In your package's service provider:
<?php namespace YourPackage\Providers; use Illuminate\Support\ServiceProvider; use Ingenius\ShopCart\Services\CartModifierManager; use YourPackage\CartModifiers\YourModifier; class YourPackageServiceProvider extends ServiceProvider { public function boot(): void { // Register your cart modifier $this->app->afterResolving(CartModifierManager::class, function (CartModifierManager $manager) { $manager->register(new YourModifier()); }); } }
Command Line Tools
The ShopCart package includes command line tools to help you manage and debug cart modifiers.
Listing Registered Cart Modifiers
To view all registered cart modifiers and their priorities, use the following command:
php artisan shopcart:modifiers
Usage
// Usage examples will go here
Testing
composer test
License
The MIT License (MIT). Please see License File for more information.
ingenius/shopcart 适用场景与选型建议
ingenius/shopcart 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 82 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 07 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 ingenius/shopcart 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ingenius/shopcart 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 82
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-07-24