Jump to content

SQL database query to retrieve product carrier


PizzaPie

Recommended Posts

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

(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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...