ozdemir/aurora
Composer 安装命令:
composer require ozdemir/aurora
包简介
Shopping Cart for Laravel
README 文档
README
Aurora Cart is a flexible and feature-rich shopping cart library for Laravel.
Features
- Cart Management: Easily manage the shopping cart for both guest and authenticated users.
- Item Addition: Add items to the cart with quantity and options support.
- Item Modification: Adjust item quantity, remove items, and update options.
- Calculators: Implement custom calculators for shipping, tax, or any other additional costs.
- MetaData: Attach meta information to the entire cart or individual items.
- Snapshot and Rollback: Save and restore the cart state for scenarios like order creation.
- Validation: Validate the cart integrity using checksums.
Installation
Install the package using Composer:
composer require ozdemir/aurora
Configuration
To configure Aurora Cart, publish the configuration file:
php artisan vendor:publish --tag="aurora-config"
This will create a cart.php file in your config directory. Here's an example configuration file with explanations:
// config/cart.php use Ozdemir\Aurora\Cart; use Ozdemir\Aurora\Generators\GenerateChecksum; use Ozdemir\Aurora\Generators\GenerateSessionKey; use Ozdemir\Aurora\Storages\SessionStorage; return [ 'instance' => 'cart', 'cart_class' => Cart::class, 'storage' => SessionStorage::class, 'cache_store' => env('CART_STORE', config('cache.default')), 'monetary' => [ 'precision' => env('CART_CURRENCY_PRECISION', 2), ], 'session_key_generator' => GenerateSessionKey::class, 'checksum_generator' => GenerateChecksum::class, 'calculate_using' => [ // Custom calculators go here ], ];
Basic Usage
// Create a product class implementing the Sellable interface class SellableProduct implements Sellable { use SellableTrait; } // Adding an item to the cart $product = new SellableProduct(); // Replace with your actual product model $cartItem = new CartItem($product, quantity: 2); Cart::add($cartItem); // Retrieving cart information $total = Cart::total(); $itemCount = Cart::count(); $items = Cart::items(); $itemQuantity = Cart::quantity(); // total quantity // Adding an item with options to the cart Cart::add( (new CartItem($product, quantity: 1))->withOption('color', 'blue') ->withOption('material', 'metal', price: 5) ->withOption('size', 'large', weight: 4) ); // Updating item quantity Cart::update($cartItem->hash(), quantity: 3); // Removing an item from the cart Cart::remove($cartItem->hash());
Aurora Cart supports custom calculators for calculating totals. You can add your custom calculators to the config/cart.php file under the calculate_using key.
Example
return [ // ... 'calculate_using' => [ // discounts etc.. ShippingCalculator::class TaxCalculator::class ], ];
class ShippingCalculator { public function handle($payload, Closure $next) { [$price, $breakdowns] = $payload; $shippingPrice = Shipping::first()->amount; $price = $price + $shippingPrice; $breakdowns[] = [ 'type' => 'shipping', 'amount' => $shippingPrice, // any additional values.. ]; return $next([$price, $breakdowns]); } }
class TaxCalculator { public function handle($payload, Closure $next) { [$price, $breakdowns] = $payload; $taxPrice = Tax::first()->amount; $price = $price + $taxPrice; $breakdowns[] = [ 'type' => 'tax', 'amount' => $taxPrice, // any additional values.. ]; return $next([$price, $breakdowns]); } }
Now, your cart will use these custom calculators to calculate totals, including shipping and tax. Adjust the logic in the calculators based on your specific business requirements.
Breakdowns
You can retrieve the breakdowns of your cart using the Cart::breakdowns() method. Breakdowns provide a detailed summary of how the total amount is calculated, including contributions from various components such as shipping, tax, and any custom calculators you've added.
Example
$breakdowns = Cart::breakdowns(); // Output the breakdowns print_r($breakdowns);
The breakdowns() method returns an array where each element represents a breakdown item. Each breakdown item typically includes a label and value, providing transparency into how different factors contribute to the overall total.
Here's a hypothetical example output:
Array ( [0] => Array ( [label] => Shipping [value] => 10 ) [1] => Array ( [label] => Tax [value] => 15 ) // Additional breakdown items based on your custom calculators // ... )
Adjust the output format and contents as needed for your specific use case.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
License
The MIT License (MIT). Please see License File for more information.
ozdemir/aurora 适用场景与选型建议
ozdemir/aurora 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 46 次下载、GitHub Stars 达 3, 最近一次更新时间为 2023 年 06 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cart」 「laravel」 「shopping」 「laravel-cart」 「ozdemir」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ozdemir/aurora 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ozdemir/aurora 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ozdemir/aurora 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Laravel 11 and above Shopping cart
Admin Hub for GetCandy. A modern headless e-commerce solution for Laravel PHP framework.
universal shopping basket
Google Shopping Feed API (with ns problem fixed)
A PHP (and Laravel) package to interface with the Snipcart api.
Yii2 extension that adds shopping cart functions
统计信息
- 总下载量: 46
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 27
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-06-17