Add shipping method with respect to cities [closed]
I am trying to extend shipping method with respect to cities.
senerio :
When i select country in flat rate, Automatically populate cities with respect to selected country.
How may i change or extend shipping method
To answer your own questions in the future always explore the methods in abstract classes and you find that every shipping method has a parent method isActive() defined in their object.
So your task is to write your restrictions to this method in your shipping method class that extends Mage_Shipping_Model_Carrier_Abstract
public function isActive(){
parent::isActive();
//your logic to follow and check the selected shipping or billing city and return boolean true/false
}
or you can narrow your needs to specific methods in abstract( dont forget to call the parent method in your overwrite)
checkAvailableShipCountries()
isActive()
isCityRequired()
isStateProvinceRequired()
isZipCodeRequired()
Experience tells me that (outside of America) users cannot be trusted to enter their city name in correctly, i.e. as your code would like to match it to. However, postcodes are reliably entered as users are familiar with getting this part of their address right.
Are you doing flat rate or weight/location with checks on dimensions? This complicates matters considerably.
If your calculations are simple then you can use post/zip codes with existing built in methods, e.g. standard table rates will require a CSV loaded up in shop-view of admin->system->shipping methods:
Country County/State Postcode Weight (and above) Delivery Price
USA * 12345 1 10
USA * 16384 1 10
USA * 65536 1 10
USA * 32768 1 10
If you want to do the same with code of your own that pattern matches part of the post/zip code then a starting point is to copy the existing Flatrate.php out of core and into local.
From here you can use $order->getShippingAddress()->getPostcode()
and do your own calculations on that.
With a similar approach you could do cities too, although you must appreciate that not everyone in a city puts their 'city' entry in correctly, certainly not in Title Case.
精彩评论