0

is there any way to filter shipping methods based on customer chosen region/city from address book in checkout process? for example: there are two shipping methods (A & B). "A" is available for all cities and "B" is available for just one city. can it be done programmatically or other ways?

0

I think a extention need to be created. This link explains the same.. http://www.blog.magepsycho.com/how-to-filter-shipping-method-in-onepage-checkout/ and there is one extension (free) where your might get some Idea. http://www.magentocommerce.com/magento-connect/shipping-and-payment-filters.html I hope others might explain more on this.

0

Take a look at How to filter shipping method in onepage checkout?

Create: app/code/local/MagePal/ShippingFilter/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <MagePal_ShippingFilter>
            <version>1.0.1</version>
        </MagePal_ShippingFilter>
    </modules>

    <global>
        <models>
            <shipping>
               <rewrite>
                  <shipping>MagePal_Shipmentfilter_Model_Shipping</shipping>
               </rewrite>
           </shipping>
        </models>
    </global>
</config>

Create: app/code/local/MagePal/ShippingFilter/Model/Shipping.php

class MagePal_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();
        // get login customer address book
        // if customer login and have address on file
        // check payment code
        if(!$isLoggedIn){
            if($carrierCode == ''){ #Hide shipping method
                return false;
            }
        }
        return true;
    }
}

Create: app/etc/modules/MagePal_ShippingFilter.xml

  <?xml version="1.0"?>
    <config>
           <modules>
                  <MagePal_ShippingFilter>
                          <active>true</active>
                          <codePool>local</codePool>
                  </MagePal_ShippingFilter>
           </modules>
    </config>
6
  • i want a solution to Filter Shipping Methods Based on city; not for payment methods! – Moh3n Feb 6 '15 at 20:35
  • i'm new in magento coding. i will thankful if you explain this with details. what should i do with this codes? – Moh3n Feb 6 '15 at 21:01
  • You will need to create a custom module see code.tutsplus.com/tutorials/… ... then rewrite the shipping model – Renon Stewart Feb 6 '15 at 21:02
  • thanks. and can you guide me to how to rewrite shipping model in magento? – Moh3n Feb 6 '15 at 21:13
  • Take a look at my update – Renon Stewart Feb 6 '15 at 21:20
0

You can set allowed carrier codes to the quote (shipping) address with setLimitCarrier method, and then recalculate the shipping rates.

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.