1

In Magento 1.7, is there any way to show Flat Rate Shipping only if chart is over a certain amount?

By rule the only option seems to be free shipping, but my goal is to have Flat Rate if sub total in chart is xx (if sub total is lower, normal rates will be used).

starball
  • 20,030
  • 7
  • 43
  • 238
Espen
  • 147
  • 4
  • 16

1 Answers1

2

Not by default. It's easy to extend the flat rate shipping carrier method though to do this. Simply create a new module, extend the flat rate shipping system.xml so that there is a new option for minimum cart price (this will allow you to configure it through admin). Extend the following class Mage_Shipping_Model_Carrier_Flatrate and override the collectRates method to check the cart total vs the admin config value. Return false if the cart value is not enough and it will not show up as an option, otherwise it will return the cost set in the admin.

Edit: Something like the following would do it. Extend the class, don't mod the core!

public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
    // Get The Minimum Order Value From Admin Config & Compare To Cart Subtotal (Base Prices)
    if (!$this->getConfigFlag('minimum_order') || $request->getBaseSubtotalInclTax() < $this->getConfigFlag('minimum_order')) {
        return false;
    } else {
        return parent::collectRates($request);
    }
}
Ashley Swatton
  • 2,104
  • 1
  • 18
  • 27
  • Hi. I managed to create the new module, and added the option for cart price (called it 'minimum_order'). And make it work in frontend. But didn't quite manage to tweek the collectRates so that the new flat rate only shows when chart is equal to or higher than the 'minimum_order' value. Could you kindly help me? Thanks a lot! – Espen Sep 30 '13 at 19:15
  • Updated with example. Pay attention to the $this->getConfigFlag() method. This is what retrieves the admin configuration value for your new parameter for the given carrier. We then simply compare to the cart subtotal. If we return false, the method is not available. – Ashley Swatton Sep 30 '13 at 19:29
  • Hi. I cant get the getConfigFlag-function to work, seems like it don't fetch the value from admin. However, I won't need to change this value for a while, so tried a more hardcode-version of your code that worked: `if ($request->getBaseSubtotalInclTax() <= ('699')) { return false; }` That will help me reach my goal, but unfortunatly not in a perfect way. Thanks a lot for your help :) – Espen Sep 30 '13 at 21:02
  • I suspect you havn't overridden the class properly if you can't get the admin value. Take a look here for a guide on how to do it Magento style. http://stackoverflow.com/questions/4474502/overridding-a-shipping-method-what-am-i-missing Please accept my answer if it helped. – Ashley Swatton Oct 01 '13 at 11:43
  • I am afraid my skills isn't good enough to make that last part work. It looks correct, but... no luck :( However your help was excellent, and it made me reach my goal : to show Flat Rate Shipping only if chart is over a certain amount. Again, thanks a lot Ashley! – Espen Oct 01 '13 at 21:32