3

I want hide a shipping method in frontend and that only show in backend. Is possible enable pickup store only in backend? I make with payment methods very easy

protected $_canUseInternal = true; protected $_canUseCheckout = false;

but with shipping is impossible for me. Could your help me please? Thanks in advance

5

Following blog could help you:

  • Hi @Rahul Kumar Das i used custom shipping method. it will work – Magento 2 Oct 9 '15 at 18:39
5

Just incase the site given in another answer goes down for some reason.

You may want to filter shipping method in onepage checkout for one of the following cases:

  • Filter shipping method based on Customer Group
  • Filter Shipping method based on Country, State, Zipcode etc
  • Filter Shipping method based on products
  • etc.

Unlike event: ‘payment_method_is_active’ for payment method filtration, we don’t have a similar event: ‘shipping_method_is_active’ available for shipping method.

Whatever may be the reason we still can filter by overriding: Mage_Shipping_Model_Shipping::collectCarrierRates()

Solution Suppose a skeleton module(MagePsycho_Shipmentfilter) has already been created. And for example purpose we will be hiding flat rate shipping for non-logged in customer.

  1. Rewrite the shipping model class: ‘Mage_Shipping_Model_Shipping’ File: app/code/local/MagePsycho/Shipmentfilter/etc/config.xml
...
<global>
    ...
    <models>
        <shipping>
            <rewrite>
                <shipping>MagePsycho_Shipmentfilter_Model_Shipping</shipping>
            </rewrite>
        </shipping>
    </models>
    ...
</global>
  1. Override the method: collectCarrierRates()

File: app/code/local/MagePsycho/Shipmentfilter/Model/Shipping.php

class MagePsycho_Shipmentfilter_Model_Shipping extends 
Mage_Shipping_Model_Shipping {
    public function collectCarrierRates($carrierCode, $request) {
        if (!$this - > _checkCarrierAvailability($carrierCode, $request)) {
            return $this;
        }
        return
        parent::collectCarrierRates($carrierCode, $request);
    }
    protected function _checkCarrierAvailability($carrierCode, $request = null) {
        $isLoggedIn = Mage::getSingleton('customer/session') - > isLoggedIn();
        if (!$isLoggedIn) {
            if ($carrierCode == 'flatrate') {
                # Hide Flat Rate
                for non logged in customers
                return false;
            }
        }
        return true;
    }
}
  1. That’s all.

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.