Enabling Magento Flat Rate Shipping for Subtotals Over a Certain Amount
In Magento 1.7, you can configure your store to use flat rate shipping only if the cart subtotal exceeds a specified amount. This allows you to offer discounted or fixed-rate shipping for larger orders while still using standard rates for smaller purchases.
Understanding the Default Configuration
By default, Magento provides two main shipping methods: Free Shipping and Flat Rate.
- Free Shipping: Applies when your customer’s order meets certain conditions (like minimum subtotal).
- Flat Rate: Provides a fixed rate regardless of the number of items or their weight.
However, out-of-the-box, you can only set up free shipping based on subtotal. To achieve flat rate shipping for specific subtotals, we’ll need to create a custom extension.
Creating a Custom Extension
To add this functionality, follow these steps:
-
Create the necessary files: In your Magento root folder, navigate to
app/code/local/Your_Module/. If the directory doesn’t exist, create it usingmkdir -p app/code/local/Your_Module/. -
Configure the XML
Create a new file called
config.xmlin theetcsubdirectory of your module:<!-- config.xml --> <config> <modules> <Your_Module_SubtotalFlatRate> <active>true</active> <codePool>local</codePool> <depends> <Mage_Core /> </depends> </Your_Module_SubtotalFlatRate> </modules> <global> <models> <your_module> <class>Your_Module_Model</class> <resourceModel>your_module_resource</resourceModel> </your_module> <your_module_resource> <class>Your_Module_Model_Mysql4</class> <entities> <flat_rate> <table>shipping_flat_rate</table> </flat_rate> </entities> </your_module_resource> </models> <resources> <your_module_setup> <setup> <module>Your_Module</module> <version>1.0.0</version> </setup> </your_module_setup> </resources> </global> </config> -
Create the model
In
app/code/local/Your_Module/Model/, create a new file calledFlatRate.php:<?php class Your_Module_Model_FlatRate extends Mage_Core_Model_Abstract { protected function _construct() { $this->_init('your_module/flat_rate'); } } -
Override the shipping method
Open
app/code/core/Mage/Shipping/Model/Carrier/Flatrate.phpand add your custom logic in thecollectRatesmethod:<?php class Mage_Shipping_Model_Carrier_Flatrate extends Mage_Shipping_Model_Carrier_Abstract { // ... existing code ... public function collectRates(Mage_Shipping_Model_Rate_Request $request) { $subtotal = $this->getQuote()->getSubtotal(); if ($subtotal > $your_custom_amount) { return parent::collectRates($request); } else { // Return an empty rate request for smaller orders return []; } } // ... existing code ... }
Replace $your_custom_amount with the desired minimum subtotal.
Conclusion
With these modifications, your Magento store will now offer flat rate shipping automatically whenever a customer’s cart subtotal exceeds the specified amount. This allows you to provide discounted or fixed-rate shipping for larger orders while still using standard rates for smaller purchases.
Remember to clear your cache and refresh your storefront after making changes:
php shell/indexer.php reindexall
For more advanced customizations and best practices in Magento development, check out the dedicated resources at Laravel Company’s Magento Development Guide.