taskinbirtan / ecommerce.cart
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/taskinbirtan/ecommerce.cart
Requires (Dev)
- laravel/framework: ^10.0
 - orchestra/testbench: ^8.36
 - pestphp/pest: ^2.36
 - pestphp/pest-plugin-laravel: ^2.4
 
This package is not auto-updated.
Last update: 2025-10-21 18:28:14 UTC
README
This package is a modular and extensible library designed to strengthen cart management within the Laravel ecosystem. It is classified under the following headings:
- Core Cart: Functions to add, remove, update quantity, and clear cart items.
 - Persistence Layer: Durable storage via a migration for 
cart_itemswith a JSON-enabledoptionscolumn and theCartItemmodel. - Interface & Contracts: Abstractions through 
CartInterface,ProductResolverInterface, andTaxCalculatorInterface. - Events System: 
ItemAdded,ItemUpdated,ItemRemoved, andCartClearedevents. - Calculators: Subtotal, tax, and total calculation via 
DefaultCartCalculatorandDefaultTaxCalculator. - Configurable Resolver: Configure the model and tax rate (
tax_rate) inconfig/cart.php. - Actions: Extendable action framework with examples like 
MailActionfor sending emails. - Facade & Helpers: Provides a 
Cartfacade and helper functions. 
📦 Features
- 
Cart Management
- Add/remove/update/clear items (
addItem,removeItem,updateQuantity,clear) - List items (
items) and calculate total (total) 
 - Add/remove/update/clear items (
 - 
Database Support
cart_itemstable:cart_id(UUID),item_id,quantity,unit_price,options(JSON), timestamps
 - 
Event Dispatch
ItemAdded,ItemUpdated,ItemRemoved,CartCleared
 - 
Actions
- Example 
MailAction—send email with sender, recipient, subject, and content parameters 
 - Example 
 - 
Configuration
- Configure model and 
tax_rateviaconfig/cart.php 
 - Configure model and 
 - 
Calculators
DefaultCartCalculator: subtotal, tax, and grand totalDefaultTaxCalculator: percentage-based tax calculation
 - 
Facade
- Provides the 
Cartfacade 
 - Provides the 
 
⚙️ Installation
- 
Require the package via Composer:
composer require taskinbirtan/ecommerce.cart
 - 
Register the service provider and facade (if auto-discovery is disabled) in
config/app.php:Taskinbirtan\EcommerceCart\CartServiceProvider::class, 'Cart' => Taskinbirtan\EcommerceCart\Facades\Cart::class,
 - 
Publish the configuration file:
php artisan vendor:publish --provider="Taskinbirtan\EcommerceCart\CartServiceProvider" --tag=config - 
Run the migrations:
php artisan migrate
 
Note: The default migration file is named
1919_05_19_commemorate_ataturk.phpin honor of Atatürk and to celebrate Youth and Sports Day, commemorating the beginning of the Turkish War of Independence and marking the date this project was initiated.
⚙️ Configuration
config/cart.php:
return [ 'product_model' => App\\Models\\Product::class, 'tax_rate' => 18, // percentage ];
🛠️ Usage
Add an Item to the Cart
use Cart; Cart::addItem($productId, $quantity = 1, ['color' => 'red']);
Remove an Item
Cart::removeItem($productId);
Update Quantity
Cart::updateQuantity($productId, $newQuantity);
Clear the Cart
Cart::clear();
List Items and Calculate Total
$items = Cart::items(); $total = Cart::total();
🔔 Events
You can listen to the following events to react to cart changes:
Taskinbirtan\EcommerceCart\Events\ItemAddedTaskinbirtan\EcommerceCart\Events\ItemUpdatedTaskinbirtan\EcommerceCart\Events\ItemRemovedTaskinbirtan\EcommerceCart\Events\CartCleared
Example listener:
public function handle(ItemAdded $event) { // $event->item }
📋 Test
This package can be tested with Pest & PHPUnit:
vendor/bin/pest
📝 Roadmap
In future versions, we aim to cover e-commerce components beyond Cart with the following modules:
- Product Catalog: CRUD operations, detail pages, variation support (color, size, etc.)
 - Category Management: Multi-level category/ subcategory hierarchy and category-based filtering
 - Inventory & Stock Tracking: Warehouse-based stock management, critical stock alerts
 - Order Management: Creating orders, status updates, and customer notifications
 - Payment Integrations: Stripe, PayPal, local banks, and installment options
 - Shipping & Logistics: Carrier API integration, shipment tracking
 - Coupons & Discounts: Percentage- and amount-based promo codes, usage rules
 - Customer Accounts: Registration/login, profile, address book, order history
 - Invoicing & Returns: PDF invoice generation, return request management
 - Multi-Language & Multi-Currency: Localization infrastructure, currency rate updates
 - Reporting & Analytics: Sales, customer, and stock reports with graphical displays
 - Search & Filtering Infrastructure: Elasticsearch/Algolia integration, advanced filters
 - UI/UX Components: Responsive theme and demo components (Tailwind, jQuery)
 - Security & Performance: Rate limiting, cache (Redis), scalable architecture recommendations
 
🤝 Contributing
- Fork the repository
 - Create a new branch (
git checkout -b feature/fooBar) - Commit your changes (
git commit -am 'Add some fooBar') - Push to the branch (
git push origin feature/fooBar) - Open a pull request
 
☕ Buy Me a Coffee
If you like this package and want to support its development, you can buy me a coffee! ☕
📝 License
MIT © taskinbirtan