PizzaPie Posted December 18, 2013 Share Posted December 18, 2013 Hi to everyone, i need help to retrieve and display the selected carrier for certain product in product detail page. I can clearly see those products in PS_product_carrier table, with their carriers, so I would like to make a database query to get carrier id from this table, something like this: SELECT id_carrier_reference AS carrier FROM `ps_product_carrier` WHERE `id_product`='.$id_product; The problem is that I'm pretty good in sql and php, but I don't know how to make a database query in .tpl and smarty. Any help/advice? Thanks in advance! Link to comment Share on other sites More sharing options...
vekia Posted December 18, 2013 Share Posted December 18, 2013 the question is: where you want to get it? if in php script, here is the solution: $product = new $product($id_product); $carriers = $product->getCarriers(); now in $carriers you've got an array of carrier, also id_carrier_reference field Link to comment Share on other sites More sharing options...
PizzaPie Posted December 19, 2013 Author Share Posted December 19, 2013 (edited) Thank you for your fast answer Well, I would like to get it in product.tpl, cause I'm trying to make an if statement to display carriers in product detail page, if available. Edited December 19, 2013 by PizzaPie (see edit history) Link to comment Share on other sites More sharing options...
tuk66 Posted December 19, 2013 Share Posted December 19, 2013 (v1.5.6.0) You need to patch the /controllers/front/ProductController.php file, to add the line with carriers: $this->context->smarty->assign(array( 'carriers' => $this->product->getCarriers(), 'stock_management' => Configuration::get('PS_STOCK_MANAGEMENT'), and work with $carriers in your product.tpl template. Link to comment Share on other sites More sharing options...
PizzaPie Posted December 19, 2013 Author Share Posted December 19, 2013 Ok, I made it and now if I use {$carriers} in product.tpl I get an array, and if print it in this way {foreach from=$carriers item=carrier} {$carrier|@print_r} {/foreach} I get this: Array ( [id_carrier] => 14 [id_reference] => 1 [id_tax_rules_group] => 0 [name] => TLD [url] => [active] => 1 [deleted] => 0 [shipping_handling] => 0 [range_behavior] => 0 [is_module] => 0 [is_free] => 1 [shipping_external] => 0 [need_range] => 0 [external_module_name] => [shipping_method] => 2 [position] => 0 [max_width] => 0 [max_height] => 0 [max_depth] => 0 [max_weight] => 0.000000 [grade] => 0 ) Now, how can I select and display only certain values, for example "id_carrier"? Link to comment Share on other sites More sharing options...
tuk66 Posted December 19, 2013 Share Posted December 19, 2013 {$carrier.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