Download the PHP package daikazu/flexicart without Composer
On this page you can find all versions of the php package daikazu/flexicart. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download daikazu/flexicart
More information about daikazu/flexicart
Files in daikazu/flexicart
Package flexicart
Short Description A flexible shopping cart package for Laravel
License MIT
Homepage https://github.com/daikazu/flexicart
Informations about the package flexicart
FlexiCart
A flexible shopping cart package for Laravel with support for session or database storage, conditional pricing, and custom product attributes.
Table of Contents
- Features
- Installation
- Requirements
- Publish Configuration
- Database Storage (Optional)
- Basic Usage
- Adding Items to the Cart
- Updating Items in the Cart
- Removing Items from the Cart
- Getting Cart Items and Calculations
- Understanding Conditions
- Adding Conditions
- Removing Conditions
- Marking Items as Non-Taxable
- Configuration Options
- Storage Configuration
- Session Key Configuration
- Currency and Locale Configuration
- Custom Models Configuration
- Working with Prices
- Creating Price Objects
- Price Operations
- Formatting and Conversion
- Displaying the Cart in Blade
- Database Storage Notes
- Extending the Package
- Custom Condition Class
- Custom Storage Method
- Testing
- Troubleshooting
- Changelog
- Contributing
- Security Vulnerabilities
- Credits
- License
Features
- Flexible Storage: Use session storage (default) or database storage
- Cart Item Conditions: Apply discounts, fees, or any adjustments to items
- Percentage-based adjustments (e.g., 10% discount)
- Fixed-amount adjustments (e.g., $5 off, $2 add-on fee)
- Stack multiple conditions on the same item
- Custom Product Attributes: Store any item-specific attributes (color, size, etc.)
- Global Cart Conditions: Apply conditions to the cart subtotal or only to taxable items
- Precise Price Handling: Uses Brick/Money for accurate currency calculations
- Taxable Item Support: Mark specific items as taxable or non-taxable
- Easy Integration: Simple API with Laravel Facade
- Comprehensive Tests: Unit and feature tests included
Installation
Requirements
- PHP 8.3 or higher
- Laravel 11.0 or higher
- Brick/Money package (automatically installed)
Install the Package
You can install the package via composer:
Publish Configuration
Publish the configuration file to customize the package settings:
This will publish the configuration file to config/flexicart.php
.
Database Storage (Optional)
If you want to use database storage instead of session storage, you need to run the migrations:
Then update your .env
file:
Basic Usage
Adding Items to the Cart
You can add items to the cart using the addItem
method. Items can be added as arrays or CartItem objects:
Updating Items in the Cart
Update existing items using the updateItem
method:
Removing Items from the Cart
Remove items individually or clear the entire cart:
Getting Cart Content and Calculations
Access cart items and perform calculations:
Understanding Conditions
Conditions are adjustments that can be applied to cart items or the entire cart. There are several types:
- Percentage Conditions: Apply percentage-based adjustments (e.g., 10% discount)
- Fixed Conditions: Apply fixed-amount adjustments (e.g., $5 off)
- Tax Conditions: Special conditions for tax calculations
Conditions can target:
- Individual Items: Applied to specific cart items
- Cart Subtotal: Applied to the entire cart subtotal
- Taxable Items: Applied only to items marked as taxable
Adding Conditions
Add conditions to the cart or specific items:
Removing Conditions
Remove conditions from the cart or items:
Marking Items as Non-Taxable
By default, all items are taxable. You can mark specific items as non-taxable:
Configuration Options
Storage Configuration
Configure how cart data is stored:
Session Key Configuration
Customize the session key when using session storage:
Currency and Locale Configuration
Set the default currency and locale for price formatting:
Custom Models Configuration
When using database storage, you can specify custom models:
Compound Discounts
Control how multiple discounts are calculated:
Cart Cleanup
Configure automatic cleanup of old carts when using database storage:
Working with Prices
FlexiCart uses the Brick/Money library for precise price calculations.
Creating Price Objects
Price Operations
Formatting and Conversion
Displaying the Cart in Blade
Here's an example of how to display cart contents in a Blade template:
Database Storage Notes
When using database storage, FlexiCart creates the following tables:
carts
: Stores cart metadata (ID, user association, timestamps)cart_items
: Stores individual cart items and their properties
Cart Persistence
With database storage, carts are automatically persisted. You can also manually persist session-based carts:
Multiple Carts
You can work with multiple carts by specifying cart IDs:
Extending the Package
Custom Condition Class
Create custom condition types by extending the base Condition class:
Custom Storage Method
Implement custom storage by creating a class that implements StorageInterface
:
Then configure it in your flexicart.php
config file:
Testing
The package comes with comprehensive tests. To run them:
Troubleshooting
Common Issues
Cart data not persisting between requests
- Ensure sessions are properly configured in your Laravel application
- If using database storage, verify migrations have been run
- Check that the
CART_STORAGE
environment variable is set correctly
Price calculation errors
- Verify that all price values are numeric
- Ensure currency codes are valid ISO codes
- Check that the Brick/Money library is properly installed
Condition not applying correctly
- Verify condition targets are set appropriately
- Check condition order values if multiple conditions exist
- Ensure condition values are properly signed (negative for discounts)
Memory issues with large carts
- Consider implementing cart item limits
- Use database storage for better memory management
- Implement cart cleanup for old/abandoned carts
Debug Mode
Enable debug mode to get more detailed error messages:
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Mike Wall
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of flexicart with dependencies
ext-bcmath Version *
ext-intl Version *
brick/money Version ^0.10.1
illuminate/contracts Version ^10.0||^11.0||^12.0
illuminate/session Version ^10.0||^11.0||^12.0
illuminate/support Version ^10.0||^11.0||^12.0
spatie/laravel-package-tools Version ^1.16