Prestashop get product attributes from its id

15,432

Solution 1

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);

Solution 2

or you can safe some lines, which is more simple:

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

Good luck!

Share:
15,432
NewUser
Author by

NewUser

I am just a beginner in the field of web. I like to know about new technology behind Web Sites and Web Applications.

Updated on June 14, 2022

Comments

  • NewUser
    NewUser almost 2 years

    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