prasanna / bagisto-weight-shipping
Weight based shipping package for Bagisto - Calculate shipping costs based on total cart weight
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:bagisto-package
README
A comprehensive weight-based shipping package for Bagisto that calculates shipping costs based on the total weight of cart items.
Features
- Weight-based Calculation: Calculates shipping cost based on total cart weight
- Flexible Rate Configuration: Support for multiple weight ranges with different rates
- Admin Configuration: Easy-to-use admin interface for configuring weight ranges
- Multi-language Support: Supports localization for different languages
- Channel-based Configuration: Different rates for different sales channels
- Easy Installation: Install via Composer with automated setup
Requirements
- Bagisto 2.x
- PHP 8.2+
- Laravel 11.x
- Products must have weight attributes set
Installation
Method 1: Via Composer (Recommended)
composer require prasanna/bagisto-weight-shipping
Method 2: Manual Installation
-
Download the package to your Bagisto installation:
git clone https://github.com/prasanna/bagisto-weight-shipping.git packages/prasanna/bagisto-weight-shipping
-
Add to composer.json (in your Bagisto root):
{ "autoload": { "psr-4": { "Prasanna\\WeightShipping\\": "packages/prasanna/bagisto-weight-shipping/src/" } } }
-
Update autoloader:
composer dump-autoload
Setup
After installation, run the setup command:
php artisan weight-shipping:install
This command will:
- Add weight-based shipping to the carriers configuration
- Add admin configuration fields
- Add language translations
- Clear cache
Configuration
- Go to Admin Panel → Configuration → Sales → Shipping Methods
- Find "Weight Based Shipping" section
- Configure the following settings:
Settings
- Title: Display name for the shipping method
- Description: Description shown to customers
- Weight Ranges: Configure weight ranges and their corresponding rates
- Status: Enable/disable the shipping method
Weight Ranges Format
Enter weight ranges in the following format:
1:45,5:80,10:120
This means:
- 0-1kg: ₹45
- 1-5kg: ₹80
- 5-10kg: ₹120
- 10kg+: ₹120 (uses last range price)
Example Configurations
Basic Configuration:
1:45,5:80,10:120
Complex Configuration:
0.5:25,1:45,2:60,5:100,10:150,20:250
Usage
For Customers
- Add products to cart (products must have weight set)
- Go to checkout
- Select shipping address
- Choose "Weight Based Shipping" from available shipping methods
- Complete checkout
For Admins
- Set product weights in product management
- Configure weight ranges in shipping settings
- Enable the shipping method
- Monitor and adjust rates as needed
How It Works
Weight Calculation
- System calculates total weight of all cart items
- For each item:
item_weight × quantity
- Total weight = Sum of all item weights
Rate Calculation
- System parses the weight ranges configuration
- Finds the appropriate range for the total cart weight
- Returns the corresponding shipping rate
Example
Weight Ranges: 1:45,5:80,10:120
- Cart with 0.5kg total → ₹45 (0-1kg range)
- Cart with 3kg total → ₹80 (1-5kg range)
- Cart with 8kg total → ₹120 (5-10kg range)
- Cart with 15kg total → ₹120 (uses last range)
Troubleshooting
Common Issues
-
Shipping method not showing
- Check if the method is enabled in configuration
- Verify products have weight attributes set
- Clear cache:
php artisan cache:clear
-
Incorrect rate calculations
- Verify weight range format is correct
- Check product weights are set properly
- Test with different cart combinations
-
Configuration not appearing
- Run installation command:
php artisan weight-shipping:install
- Check if service providers are registered
- Clear config cache:
php artisan config:clear
- Run installation command:
Debug Steps
-
Check product weights:
// In tinker $product = Product::find(1); dd($product->weight);
-
Check cart total weight:
// In tinker $cart = Cart::getCart(); // Check individual item weights foreach ($cart->items as $item) { echo $item->product->name . ': ' . $item->product->weight . 'kg' . PHP_EOL; }
-
Check configuration:
// In tinker dd(core()->getConfigData('sales.carriers.weightbased'));
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
License
This package is open-source software licensed under the MIT License.
Support
For issues and questions:
- Check the troubleshooting section above
- Review Bagisto documentation
- Check Laravel logs for errors
- Create an issue on GitHub
Changelog
v1.0.0
- Initial release
- Basic weight-based shipping calculation
- Admin configuration interface
- Multi-language support
- Automated installation command
Credits
- Author: Prasanna
- Based on: Bagisto eCommerce framework
- Inspired by: WooCommerce weight-based shipping plugins