Magento – Disable shipping Method from frontend but not in backend

magento-1.7shipping-methods

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.

Best Answer

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

Related Topic