Prestashop get product attributes from its id

NewUser picture NewUser · Dec 25, 2014 · Viewed 14.4k times · Source

In Prestashop I want to get product's all attribute from its product id. Lets say I have a product with id as 3. Now from product id 3 I want to get all of its attribute like name, price, stock, category, product link.. etc.

So far I have tried

$product_id = $result['id_product'];
$id_product = (int)$product_id;
$product = new Product(Tools::getValue($id_product));
var_dump($product);

But its giving me an array with all attributes in blank. The array can be seen here

So can someone tell me how to get its all attribute from id? Any help and suggestions will be really appreciable. Thanks

Answer

gskema picture gskema · Dec 25, 2014

Well, one obvious mistake is

Tools::getValue($id_product)

Which is basically

$_GET[$id_product]

So in your case that would probably evaluate to

$product = new Product($_GET['3']);

So remove Tools::getValue and try again:

$product_id = $result['id_product'];
$id_product = (int)$product_id;
$product = new Product($id_product);
var_dump($product);