1
Magento 1.9.1
Porto theme

I am trying to add another Flat rate shipping option.

I followed these steps here but I am not certain as to where to find the 2nd Flat rate shipping option:

How to add multiple flat rate shipping

(it's the step that starts with:

You could also create a second flat rate shipping method with a module. and has a +150 bounty awarded to it)

I looked in the Admin under Shipping methods but it's not there.

If this is not going to work at all - is there another way to do this?


UPDATED on April 15th, 2019:

I am trying to set this up on Magento 1.9.4 but it does not appear to be working. It gives the following Error:

There has been an error processing your request Exception printing is disabled by default for security reasons.

Error log record number: 1248949596922

This is the content of that Error log:

a:5:{i:0;s:141:"Cannot send headers; headers already sent in /home/mainDOMAIN/public_html/app/code/local/Prashant/Flatrate2/Model/Carrier/Flatrate2.php, line 1";i:1;s:1677:"#0 /home/mainDOMAIN/public_html/lib/Zend/Controller/Response/Abstract.php(148): Zend_Controller_Response_Abstract->canSendHeaders(true)
#1 /home/mainDOMAIN/public_html/app/code/core/Mage/Core/Controller/Response/Http.php(107): Zend_Controller_Response_Abstract->setRedirect('https://www.528...', 302)
#2 /home/mainDOMAIN/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(711): Mage_Core_Controller_Response_Http->setRedirect('https://www.528...')
#3 /home/mainDOMAIN/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(689): Mage_Core_Controller_Varien_Action->setRedirectWithCookieCheck('checkout/cart', Array)
#4 /home/mainDOMAIN/public_html/app/code/core/Mage/Checkout/controllers/CartController.php(98): Mage_Core_Controller_Varien_Action->_redirect('checkout/cart')
#5 /home/mainDOMAIN/public_html/app/code/core/Mage/Checkout/controllers/CartController.php(278): Mage_Checkout_CartController->_goBack()
#6 /home/mainDOMAIN/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(418): Mage_Checkout_CartController->addAction()
#7 /home/mainDOMAIN/public_html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(254): Mage_Core_Controller_Varien_Action->dispatch('add')
#8 /home/mainDOMAIN/public_html/app/code/core/Mage/Core/Controller/Varien/Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#9 /home/mainDOMAIN/public_html/app/code/core/Mage/Core/Model/App.php(365): Mage_Core_Controller_Varien_Front->dispatch()
#10 /home/mainDOMAIN/public_html/app/Mage.php(686): Mage_Core_Model_App->run(Array)
#11 /home/mainDOMAIN/public_html/index.php(83): Mage::run('thisSTORE', 'website')
#12 {main}";s:3:"url";s:126:"/index.php/checkout/cart/add/uenc/aHR0cHM6Ly93d3cuNTI4MGdvdXJtZXQuY29tL2luZGV4LnBocC8,/product/2111/form_key/hFNgXCWFfaEydW3g/";s:11:"script_name";s:10:"/index.php";s:4:"skin";s:7:"thisSTORE";}

1 Answer 1

1

Create a below custom module

create a Prashant_Flatrate2.xml file at app\etc\modules\Prashant_Flatrate2.xml

<?xml version="1.0"?>
    <config>
        <modules>
            <Prashant_Flatrate2>
                <active>true</active>
                <codePool>local</codePool>
            </Prashant_Flatrate2>
        </modules>
    </config>

Create a config.xml at app\code\local\Prashant\Flatrate2\etc\config.xml

<?xml version="1.0"?>

<config>

    <modules>
        <Prashant_Flatrate2>
            <version>0.0.1</version>
        </Prashant_Flatrate2>
    </modules>

    <global>
        <models>
            <flatrate2>
                <class>Prashant_Flatrate2_Model</class>
            </flatrate2>
        </models>

        <helpers>
            <flatrate2>
                <class>Prashant_Flatrate2_Helper</class>
            </flatrate2>
        </helpers>

    </global>

    <default>
      <carriers>
        <flatrate2>
            <active>1</active>
            <sallowspecific>0</sallowspecific>
            <model>flatrate2/carrier_flatrate2</model>
            <title>Flat Rate 2</title>
            <type>I</type>
            <specificerrmsg>This shipping method is currently unavailable. If you would like to ship using this shipping method, please contact us.</specificerrmsg>
            <handling_type>F</handling_type>
        </flatrate2>
       </carriers>
    </default>
</config>

create a system.xml file at app\code\local\Prashant\Flatrate2\etc\system.xml

<?xml version="1.0"?>
<config>
    <sections>
        <carriers>
            <groups>
                <flatrate2 translate="label" module="flatrate2">
                    <label>Flat Rate 2</label>
                    <frontend_type>text</frontend_type>
                    <sort_order>21</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>1</show_in_store>
                    <fields>
                        <active translate="label">
                            <label>Enabled</label>
                            <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_yesno</source_model>
                            <sort_order>1</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </active>
                        <name translate="label">
                            <label>Method Name</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>3</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </name>
                        <price translate="label">
                            <label>Price</label>
                            <frontend_type>text</frontend_type>
                            <validate>validate-number validate-zero-or-greater</validate>
                            <sort_order>5</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </price>
                        <handling_type translate="label">
                            <label>Calculate Handling Fee</label>
                            <frontend_type>select</frontend_type>
                            <source_model>shipping/source_handlingType</source_model>
                            <sort_order>7</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </handling_type>
                        <handling_fee translate="label">
                            <label>Handling Fee</label>
                            <frontend_type>text</frontend_type>
                            <validate>validate-number validate-zero-or-greater</validate>
                            <sort_order>8</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </handling_fee>
                        <sort_order translate="label">
                            <label>Sort Order</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>100</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </sort_order>
                        <title translate="label">
                            <label>Title</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>2</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </title>
                        <type translate="label">
                            <label>Type</label>
                            <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_shipping_flatrate</source_model>
                            <sort_order>4</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </type>
                        <sallowspecific translate="label">
                            <label>Ship to Applicable Countries</label>
                            <frontend_type>select</frontend_type>
                            <sort_order>90</sort_order>
                            <frontend_class>shipping-applicable-country</frontend_class>
                            <source_model>adminhtml/system_config_source_shipping_allspecificcountries</source_model>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </sallowspecific>
                        <specificcountry translate="label">
                            <label>Ship to Specific Countries</label>
                            <frontend_type>multiselect</frontend_type>
                            <sort_order>91</sort_order>
                            <source_model>adminhtml/system_config_source_country</source_model>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                            <can_be_empty>1</can_be_empty>
                        </specificcountry>
                        <showmethod translate="label">
                            <label>Show Method if Not Applicable</label>
                            <frontend_type>select</frontend_type>
                            <sort_order>92</sort_order>
                            <source_model>adminhtml/system_config_source_yesno</source_model>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </showmethod>
                        <specificerrmsg translate="label">
                            <label>Displayed Error Message</label>
                            <frontend_type>textarea</frontend_type>
                            <sort_order>80</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </specificerrmsg>
                    </fields>
                </flatrate2>
            </groups>
        </carriers>
    </sections>
</config>

create Flatrate2.php at app\code\local\Prashant\Flatrate2\Model\Carrier\Flatrate2

    <?php

class Prashant_Flatrate2_Model_Carrier_Flatrate2
    extends Mage_Shipping_Model_Carrier_Flatrate
    implements Mage_Shipping_Model_Carrier_Interface
{

    protected $_code = 'flatrate2';

          /**
     * Enter description here...
     *
     * @param Mage_Shipping_Model_Rate_Request $data
     * @return Mage_Shipping_Model_Rate_Result
     */
    public function collectRates(Mage_Shipping_Model_Rate_Request $request)
    {
        if (!$this->getConfigFlag('active')) {
            return false;
        }

        $freeBoxes = 0;
        if ($request->getAllItems()) {
            foreach ($request->getAllItems() as $item) {

                if ($item->getProduct()->isVirtual() || $item->getParentItem()) {
                    continue;
                }

                if ($item->getHasChildren() && $item->isShipSeparately()) {
                    foreach ($item->getChildren() as $child) {
                        if ($child->getFreeShipping() && !$child->getProduct()->isVirtual()) {
                            $freeBoxes += $item->getQty() * $child->getQty();
                        }
                    }
                } elseif ($item->getFreeShipping()) {
                    $freeBoxes += $item->getQty();
                }
            }
        }
        $this->setFreeBoxes($freeBoxes);

        $result = Mage::getModel('shipping/rate_result');
        if ($this->getConfigData('type') == 'O') { // per order
            $shippingPrice = $this->getConfigData('price');
        } elseif ($this->getConfigData('type') == 'I') { // per item
            $shippingPrice = ($request->getPackageQty() * $this->getConfigData('price')) - ($this->getFreeBoxes() * $this->getConfigData('price'));
        } else {
            $shippingPrice = false;
        }

        $shippingPrice = $this->getFinalPriceWithHandlingFee($shippingPrice);

        if ($shippingPrice !== false) {
            $method = Mage::getModel('shipping/rate_result_method');

            $method->setCarrier('flatrate2');
            $method->setCarrierTitle($this->getConfigData('title'));

            $method->setMethod('flatrate2');
            $method->setMethodTitle($this->getConfigData('name'));

            if ($request->getFreeShipping() === true || $request->getPackageQty() == $this->getFreeBoxes()) {
                $shippingPrice = '0.00';
            }


            $method->setPrice($shippingPrice);
            $method->setCost($shippingPrice);

            $result->append($method);
        }

        return $result;
    }

    public function getAllowedMethods()
    {
        return array('flatrate2' => 'Flatrate 2');
    }

}

create a Data.php file at app\code\local\Prashant\Flatrate2\Helper\Data.php

<?php

class Prashant_Flatrate2_Helper_Data extends Mage_Core_Helper_Abstract
{
}

Login to Admin > System > Configuration > Sales > Shipping Method you will find Flaterate2 as below

enter image description here

Frontend:

enter image description here

10
  • I've tried this and it now does appear in the Admin but does NOT appear on the front end after enabling the Flat rate 2 option. I've tripple checked all the files and paths and I'm 100% sure I followed all of your steps correctly....Is there anything else I can try to make this work? Thank you.
    – Allysin
    Commented May 29, 2018 at 19:52
  • updated config.xml code please update your code and check again Commented May 30, 2018 at 6:01
  • Now it appears on the front end (thank you) but there are 2 problems with it: 1. I specified $9.99 for the first (default) flat rate and $17.50 for the 2nd (your flat rate) but when I place a test order using the 2nd (your flat rate) - it comes through as $9.99 on the order. The second problem I have to fix is - we have the Delivery date extension from Amasty (just a fancy calendar) and it appears when customers select the first flat rate....oddly enough though - it also appears when I select the 2nd (your) flat rate method. Is there any way to rename your flat rate so that..
    – Allysin
    Commented May 30, 2018 at 20:36
  • ....the calendar from Amasty would NOT show after clicking that radio button?
    – Allysin
    Commented May 30, 2018 at 20:40
  • For that problem you need to customize amasty extension code Commented May 31, 2018 at 5:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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