0

In Magento 1.x all shipping rates calculation done by a collect rate function

public function collectRates(Mage_Shipping_Model_Rate_Request $request) {
    if (!Mage::getStoreConfig('carriers/' . $this->_code . '/active')) {
        return false;
    }
/*************** Start Logic to calculate rates****************/

/***************End Logic to calculate rates****************/

}

So if we want to hide that specific shipping method from the list in checkout page frontend. Then what is the correct way to do this.

1

You can create a method in your custom Module helper to check, It is in Admin area or frontend area. Like below:

class Namespace_Modulename_Helper_Isadmin extends Mage_Core_Helper_Abstract
{
public function isAdmin()
{
    if(Mage::app()->getStore()->isAdmin())
    {
        return true;
    }

    if(Mage::getDesign()->getArea() == 'adminhtml')
    {
        return true;
    }

    return false;
}
}

And You can add below condition in shipping method collectRates or getAllowedMethods function to not show shipping method in frontend.

if( !Mage::helper('modulename/isadmin')->isAdmin() )
{
//do the thing in frontend
return false;
}

Frontend check code taken from alan answer: https://stackoverflow.com/questions/9693020/magento-request-frontend-or-backend

1

No need to add this code:

if (!Mage::getStoreConfig('carriers/' . $this->_code . '/active')) {
        return false;
    }

just add this in place of above code.:

if (!$this->getConfigFlag('active')) {
            return false;
     }

Disable for Frontend: Goto backend admin>System>Configuratgion and select your current scope to Main Website from Left panel of page

then goto Sales>Shipping Methods Select your shipping method and make Enabled=NO.

For enable for admin:

Goto backend admin>System>Configuratgion and select your current scope to Default configuration from Left panel of page

then goto Sales>Shipping Methods Select your shipping method and make Enabled=Yes.

If it not work then

add if(!Mage::app()->getStore()->isAdmin()) return false; at start of the

collectRates() function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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