0

How to add Minimum Order Total price to a shipping method just like payment methods?

0
0

In the payment methods is done by this way - in each payment method in etc/system.xml there is this code:

                <min_order_total translate="label">
                    <label>Minimum Order Total</label>
                    <frontend_type>text</frontend_type>
                    <sort_order>98</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>0</show_in_store>
                </min_order_total>

and then in app/code/core/Mage/Payment/Block/Form/Container.php -> protected function _canUseMethod($method):

/**
 * Checking for min/max order total for assigned payment method
 */
$total = $this->getQuote()->getBaseGrandTotal();
$minTotal = $method->getConfigData('min_order_total');
$maxTotal = $method->getConfigData('max_order_total');

if((!empty($minTotal) && ($total < $minTotal)) || (!empty($maxTotal) && ($total > $maxTotal))) {
    return false;
}
return true;

So you can copy this in each shipping method. For an example for Flat Rate shipping method in app/code/core/Mage/Shipping/etc/system.xml -> <flatrate> -> <fields> add this:

                <min_order_total translate="label">
                    <label>Minimum Order Total</label>
                    <frontend_type>text</frontend_type>
                    <sort_order>98</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>0</show_in_store>
                </min_order_total>

and in app/code/core/Mage/Shipping/Model/Carrier/Flatrate.php -> public function collectRates add this:

$total = $request->getPackageValue();
$minTotal = $this->getConfigData('min_order_total');

if(!empty($minTotal) && ($total < $minTotal)) {
    return false;
}

If you like it for all shipping methods maybe you can think of altering some way app/code/core/Mage/Shipping/Model/Carrier/Abstract.php (not each method one by one).

Not the answer you're looking for? Browse other questions tagged or ask your own question.