eskaigualker Posted March 17, 2012 Share Posted March 17, 2012 For PS1.4.7. I have one carrier that delivers only for certain zip-codes. All of them in the same state. Using default PS behaviour, a carrier is assigned for a zone... and the zone "is made" of states. We cannot divide states into smaller parts. So, just in case someone need this, I figured out a simply way to achieve this. - I added a zone for my collection of postcodes - I set up a carrier fot that zone And in controllers/ParentOrderController.php, protected function _assignCarrier(), in line ~363 I made this change: Before: $id_zone = Address::getZoneById((int)($address->id)); After: if(($address->id_state==348)&& in_array($address->postcode,array(31001,31014))){ $id_zone=13; }else $id_zone = Address::getZoneById((int)($address->id)); This is an example. In my case, all of my postcodes belongs to the same state. If it is not your case, just delete the part "($address->id_state=xxx) Luk. Link to comment Share on other sites More sharing options...
tomerg3 Posted March 17, 2012 Share Posted March 17, 2012 Updating Controllers or Classes directly is a really bad idea, as it will be lost if you do an upgrade of Prestashop. The right way would be to create a new Override Controller and apply your changes there. There is a module we created that lets you assign shipping cost by country, state, or zip code ranges which would make thing much easier http://www.prestashop.com/forums/index.php?/topic/148747-module-localized-shipping-set-shipping-rates-by-country-state-or-zipcode-range/ Link to comment Share on other sites More sharing options...
eskaigualker Posted March 17, 2012 Author Share Posted March 17, 2012 Well. It's a little change of code in one file. It's free, allows an array of post codes (your module doesn't) and it's simplier to set up. Link to comment Share on other sites More sharing options...
tomerg3 Posted March 17, 2012 Share Posted March 17, 2012 The module was just a suggestion (it's more flexible and does not require changing any files). The advice I gave (using override files instead of changing the controller directly) was the main reason for my reply, even if it is only 1 line change, in 6 months from now, you may forget about it, do an upgrade of PS and lose this change. The is the good scenario where only 1 person works on the site, but if you use a developer, and change it, you will have no way of keeping track of those type of changes, which is why using the override folder is the best way to go. Link to comment Share on other sites More sharing options...
eskaigualker Posted March 20, 2012 Author Share Posted March 20, 2012 Thank you for your comments. I think you're right, so I decided to use "override" folder. It's easy. 1) Just copy "classes/Address.php" to "override/classes/Address.php". 2) In line 28 change class name from AddressCore to Address 3) Before function getZoneById, paste this new function (maybe there's a way to access to this field inside the class) /** * Return postcode of address * * @param $id_address Address id * @return integer postcode */ public static function getPostcodeByAddress($id_address){ $row = Db::getInstance()->getRow(' SELECT `postcode` FROM '._DB_PREFIX_.'address a WHERE a.`id_address` = '.(int)($id_address)); return $row['postcode']; } 4) Add before first line of function getZoneById this: $postcode=self::getPostcodeByAddress($id_address); if(in_array($postcode,array(your list of postcodes)){ return id-of-your-zone; }else 1 Link to comment Share on other sites More sharing options...
bobmartinusa Posted September 2, 2012 Share Posted September 2, 2012 Thank you for your comments. I think you're right, so I decided to use "override" folder. It's easy. 1) Just copy "classes/Address.php" to "override/classes/Address.php". 2) In line 28 change class name from AddressCore to Address 3) Before function getZoneById, paste this new function (maybe there's a way to access to this field inside the class) /** * Return postcode of address * * @param $id_address Address id * @return integer postcode */ public static function getPostcodeByAddress($id_address){ $row = Db::getInstance()->getRow(' SELECT `postcode` FROM '._DB_PREFIX_.'address a WHERE a.`id_address` = '.(int)($id_address)); return $row['postcode']; } 4) Add before first line of function getZoneById this: $postcode=self::getPostcodeByAddress($id_address); if(in_array($postcode,array(your list of postcodes)){ return id-of-your-zone; }else What to do after that because nothing happens in BO Link to comment Share on other sites More sharing options...
innocuous Posted November 7, 2012 Share Posted November 7, 2012 Hi, does this work with PS 1.5.2? Where do we store list of zipcodes to be assigned to a carrier? Link to comment Share on other sites More sharing options...
eskaigualker Posted November 22, 2012 Author Share Posted November 22, 2012 Yes, it works with PS 1.5.2. The changes must be made in override/classes/Address.php Link to comment Share on other sites More sharing options...
AstralProgrammer Posted December 4, 2012 Share Posted December 4, 2012 Yes, it works with PS 1.5.2. The changes must be made in override/classes/Address.php I've tried this but it doesn't work. Link to comment Share on other sites More sharing options...
mehnihma Posted December 29, 2012 Share Posted December 29, 2012 (edited) What does we get with this? I did it and I get: Parse error: syntax error, unexpected T_LIST, expecting ')' in /home2/domain/public_html/shop/override/classes/Address.php on line 260 Edited December 29, 2012 by mehnihma (see edit history) Link to comment Share on other sites More sharing options...
shoulders Posted February 14, 2013 Share Posted February 14, 2013 is there any chance of getting the working code supplied in the files with annotations, and what PS version number they are from so i can do a text comparrison. thanks 1 Link to comment Share on other sites More sharing options...
jxrgxb Posted March 7, 2013 Share Posted March 7, 2013 (edited) Thanks for the solution. Anyway we can extend Address from AddressCore that is better: Edit overrride/classes/Address.php(at least in Prestashop 1.5 exist by default): class Address extends AddressCore { /** * Return postcode of address * * @param $id_address Address id * @return integer postcode */ public static function getPostcodeByAddress($id_address){ $row = Db::getInstance()->getRow(' SELECT `postcode` FROM '._DB_PREFIX_.'address a WHERE a.`id_address` = '.(int)($id_address)); return $row['postcode']; } /** * Get zone id for a given address * * @param integer $id_address Address id for which we want to get zone id * @return integer Zone id */ public static function getZoneById($id_address) { $postcode = self::getPostcodeByAddress($id_address); if(in_array($postcode,array(list of postcode))){ return id-zone; }else if (isset(self::$_idZones[$id_address])) return self::$_idZones[$id_address]; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' SELECT s.`id_zone` AS id_zone_state, c.`id_zone` FROM `'._DB_PREFIX_.'address` a LEFT JOIN `'._DB_PREFIX_.'country` c ON c.`id_country` = a.`id_country` LEFT JOIN `'._DB_PREFIX_.'state` s ON s.`id_state` = a.`id_state` WHERE a.`id_address` = '.(int)$id_address); self::$_idZones[$id_address] = (int)((int)$result['id_zone_state'] ? $result['id_zone_state'] : $result['id_zone']); return self::$_idZones[$id_address]; } } We can use else if(in_array($postcode,array(list of postcode))) return id-zone; for more postcodes in different zones. Edited March 7, 2013 by jxrgxb (see edit history) 2 Link to comment Share on other sites More sharing options...
laziali Posted April 19, 2013 Share Posted April 19, 2013 (edited) looking for the same thing.will try it - thanks! Edited April 19, 2013 by laziali (see edit history) Link to comment Share on other sites More sharing options...
shoulders Posted April 21, 2013 Share Posted April 21, 2013 i have written a module that applies rules to assign postal rates by post code using the idea from here. i will be writing some simpe instructions. see my signature for a link to the thread. it is fully working buts needs to be released as an RC so it cdan be checked in the real world. Link to comment Share on other sites More sharing options...
laziali Posted April 23, 2013 Share Posted April 23, 2013 Hi shoulders and thank you for your help! Is your module 1.5.3 compatible? Link to comment Share on other sites More sharing options...
shoulders Posted April 24, 2013 Share Posted April 24, 2013 i will sort it for weekend. i will do instructions etc.. 1 Link to comment Share on other sites More sharing options...
modestmart Posted August 4, 2014 Share Posted August 4, 2014 what should i do if i want to make shipping caharges 0 for perticular city.there is no option in prestashop to manage shipping charges by city. Link to comment Share on other sites More sharing options...
horiabp Posted July 1, 2015 Share Posted July 1, 2015 Hello, I tried this for prestashop 1.6.0.14 and it doesn't work. Can you tell what or where should I modify to assign the wanted ID_ZONE to my carrier. Thank you, Have a nice day. Link to comment Share on other sites More sharing options...
mahi1122 Posted September 6, 2015 Share Posted September 6, 2015 Carrier by postcode , Automatically selecting a carrier based on postcode ? Can we do this in prestashop cloud, as my requirement is within single state premises, Am using prestashop 1.6 cloud. Link to comment Share on other sites More sharing options...
tomerg3 Posted September 6, 2015 Share Posted September 6, 2015 You can do it using the following module http://addons.prestashop.com/en/shipping-logistics-delivery-prestashop-modules/19772-localized-shipping.html Link to comment Share on other sites More sharing options...
mahi1122 Posted September 7, 2015 Share Posted September 7, 2015 Than q, Is there any free solution? Link to comment Share on other sites More sharing options...
tomerg3 Posted September 7, 2015 Share Posted September 7, 2015 Not that I am aware of, as it's not a simple change / addition Link to comment Share on other sites More sharing options...
Recommended Posts