leeloo Posted November 7, 2010 Share Posted November 7, 2010 I want to offer free shipping in the home of some city around the city of the shop.I do not want to set up the system state (in my case cities) because a customer can choose any state which did not correspond really.I created a conveyor (free shipping) which has ID number 45 in BO.And I changed some files as follows :In class/address.php a added this function at the end of file static public function getPostcodeByAddress($id_address) { $result = Db::getInstance()->getRow(' SELECT `postcode` FROM `'._DB_PREFIX_.'address` WHERE `id_address` = '.intval($id_address)); return isset($result['postcode']) ? $result['postcode'] : false; } In order.php I assigned a smarty value : 'dept' => $dept, if (!isset($checked)) $checked = intval(Configuration::get('PS_CARRIER_DEFAULT')); $smarty->assign(array( 'dept' => $dept, 'checkedTOS' => intval($cookie->checkedTOS), 'recyclablePackAllowed' => intval(Configuration::get('PS_RECYCLABLE_PACK')), 'giftAllowed' => intval(Configuration::get('PS_GIFT_WRAPPING')), ..... and : /* Carrier step */ function displayCarrier() { global $smarty, $cart, $cookie, $defaultCountry; $address = new Address(intval($cart->id_address_delivery)); $id_zone = Address::getZoneById($address->id); modified like : /* Carrier step */ function displayCarrier() { global $smarty, $cart, $cookie, $defaultCountry; $address = new Address(intval($cart->id_address_delivery)); $id_zone = Address::getZoneById($address->id); $dept = Address::getPostcodeByAddress($address->id); In my template, i modified the file order-carrier.tpl :this {foreach from=$carriers item=carrier name=myLoop} <input type="radio" name="id_carrier" value="{$carrier.id_carrier|intval}" id="id_carrier{$carrier.id_carrier|intval}" {if $carrier.id_carrier == $checked || ($checked == 0 && $i == 0) || ($carriers|@sizeof == 1)}checked="checked"{/if} /> {if $carrier.img}{else}{$carrier.name|escape:'htmlall':'UTF-8'}{/if} by (2 conditions added (if id carrier=45 and if zipcode=54100) {foreach from=$carriers item=carrier name=myLoop} {if $carrier.id_carrier=='45'} {if $dept == '54100'} <input type="radio" name="id_carrier" value="{$carrier.id_carrier|intval}" id="id_carrier{$carrier.id_carrier|intval}" {if $carrier.id_carrier == $checked || ($checked == 0 && $i == 0) || ($carriers|@sizeof == 1)}checked="checked"{/if} /> {else}- {/if} {else} <input type="radio" name="id_carrier" value="{$carrier.id_carrier|intval}" id="id_carrier{$carrier.id_carrier|intval}" {if $carrier.id_carrier == $checked || ($checked == 0 && $i == 0) || ($carriers|@sizeof == 1)}checked="checked"{/if} /> {/if} {if $carrier.img}{else}{$carrier.name|escape:'htmlall':'UTF-8'}{/if} This works perfectly, but if a change is made in the configuration of the carrier, his id number change and i must manually change the id in order-carrier.tpl.So I seek a way to adapt this solution even if the id chanqe without returning to the file.Thank you in advance to everyone for all the answers to come.---------------------------------Prestashop 1.2.5 Link to comment Share on other sites More sharing options...
tomerg3 Posted November 9, 2010 Share Posted November 9, 2010 Use the carrier name instead of ID Link to comment Share on other sites More sharing options...
leeloo Posted November 9, 2010 Author Share Posted November 9, 2010 I thought about it, but I want something cleaner without affecting the order-carrier.tpl file if carrier configuration has to change. Link to comment Share on other sites More sharing options...
tomerg3 Posted November 9, 2010 Share Posted November 9, 2010 As long as the name of the carrier doesn't change, you will not need to change the tpl file.I can't really think of another way to do it, other than use the field that it least likely to change, or adding a new field in the database with a new id that won't change when you update the carriers Link to comment Share on other sites More sharing options...
leeloo Posted November 10, 2010 Author Share Posted November 10, 2010 I fear to forget to not update the carrier's name.How to add a new field in the database with a new id that won’t change when you update the carriers.Edit:Solved. I Added new field in the database.Thank's tomerg3 Link to comment Share on other sites More sharing options...
meditation Posted February 11, 2014 Share Posted February 11, 2014 I fear to forget to not update the carrier's name. How to add a new field in the database with a new id that won’t change when you update the carriers. Edit: Solved. I Added new field in the database. Thank's tomerg3 Hi, leeloo how to add a new field in the database? could you share your solution? best regards Link to comment Share on other sites More sharing options...
leeloo Posted February 22, 2014 Author Share Posted February 22, 2014 Hi @meditation I added a field IDFIX in the ps_carrier table as follows : ALTER TABLE ps_carrier ADD idfix tinyint(1) unsigned NOT NULL DEFAULT '0' AFTER `id_carrier` Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now