Filter Shipping Methods Based on chosen region/city from address book
-
12-12-2019 - |
Question
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?
Solution
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.
OTHER TIPS
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>
You can set allowed carrier codes to the quote (shipping) address with setLimitCarrier method, and then recalculate the shipping rates.