Download the PHP package ashraam/laravel-simple-cart without Composer
On this page you can find all versions of the php package ashraam/laravel-simple-cart. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ashraam/laravel-simple-cart
More information about ashraam/laravel-simple-cart
Files in ashraam/laravel-simple-cart
Package laravel-simple-cart
Short Description Simple session based cart for Laravel 12
License MIT
Homepage https://github.com/ashraam/laravelsimplecart
Informations about the package laravel-simple-cart
Laravel Simple Cart
Laravel Simple Cart is a lightweight, session-based shopping cart implementation designed specifically for Laravel 10/11/12 applications. It provides a simple yet comprehensive solution for adding e-commerce cart functionality without requiring database storage.
Features
- Session-based Storage: No database required. Uses Laravel sessions
- Item Management: Add, remove, and update cart items with ease
- Product Variants: Support for product options (size, color, etc.)
- Meta Data Support: Additional item information (images, categories, descriptions)
- VAT Handling: Built-in VAT calculation and management with configurable rates
- Modifiers System: Fees and discounts at the cart level
- Multiple Cart Instances: Support for different cart instances
- Price Calculations: Automatic subtotal, VAT, fees, discounts, and total
- Exception Handling: Custom exceptions for validation
- Well Tested: Comprehensive test suite with Pest PHP
- Laravel 10/11/12 Compatible: Built for the latest Laravel version
Installation
You can install the package via composer:
Service Provider Auto-Discovery
This package supports Laravel's auto-discovery feature. The service provider and facade will be automatically registered.
Publishing Configuration
You can publish the configuration file with:
This will create a config/laravel-simple-cart.php
file in your application.
Usage
The package provides a simple API to manage your shopping cart:
Item Management
Adding vs Replacing Items
Understanding the difference between add()
and replace()
methods:
Common Use Cases for replace()
Updating item properties with same ID+options:
Switching between variants (different hashes):
Modifiers
Modifiers can be applied to the cart by using this API:
Events
The package dispatches several events to allow you to hook into the cart's lifecycle. All events contain the cart instance name.
Event | Description |
---|---|
Ashraam\LaravelSimpleCart\Events\ItemAdded($instance, $item) |
Dispatched when an item is added to the cart. |
Ashraam\LaravelSimpleCart\Events\ItemReplaced($instance, $item) |
Dispatched when an existing item is replaced. |
Ashraam\LaravelSimpleCart\Events\ItemQuantityUpdated($instance, $item) |
Dispatched when an item's quantity is updated. |
Ashraam\LaravelSimpleCart\Events\ItemRemoved($instance) |
Dispatched when an item is removed from the cart. |
Ashraam\LaravelSimpleCart\Events\CartCleared($instance) |
Dispatched when the cart is cleared. |
Classes and methods
Cart
You may have multiple instances of the cart by using the instance()
method of the cart.
You can apply modifiers to the cart using this api:
Cart Item
An item has a unique hash that serves as ID. This hash is composed of the item id and options. If you update the id or the options, the hash will be regenerated, so it's recommended to remove the item from the cart first, update the item, and then add it back.
CartItem available methods
Configuration
After publishing the configuration file, you'll find it at config/laravel-simple-cart.php
:
Configuration Options
default_session_key
: The session key used for the default cart instance. When you callCart::add()
without specifying an instance, this key is used.default_vat_rate
: Global VAT rate applied to all items unless overridden at the item level. Useful for single-country stores with consistent VAT rates.
Session Management
The cart uses Laravel's session system to store cart data. Here's what you need to know:
Session Storage Structure
Session Persistence
- Cart data persists as long as the user's session is active
- Session lifetime follows Laravel's
config/session.php
settings - Cart is automatically cleared when session expires
- Multiple browser tabs share the same cart data
Session Access
Performance Considerations
Session Storage Limitations
- Size Limits: Keep cart reasonable in size (recommended: <100 items)
- Serialization: Complex objects in meta data may impact performance
- Memory Usage: Large carts consume more session storage
Best Practices
When to Use Multiple Cart Instances
- User Types: Separate carts for guests vs authenticated users
- Cart Purposes: Main cart, wishlist, comparison list
- Multi-tenant: Different carts per tenant/organization
- A/B Testing: Different cart behaviors for user segments
API Reference
Complete Method Signatures
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Romain BERTOLUCCI
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
Laravel Package Boilerplate
This package was generated using the Laravel Package Boilerplate.
All versions of laravel-simple-cart with dependencies
illuminate/session Version ^10.0|^11.0|^12.0
illuminate/support Version ^10.0|^11.0|^12.0
illuminate/events Version ^10.0|^11.0|^12.0