Home > database >  Function getProduct Prestashop
Function getProduct Prestashop

Time:05-25

I'm not usually the type to ask questions on forums, as I always prefer to search on my own.

Only here I'm stuck on a problem that I don't really understand!

I try to recover all the products it works well:

        $id_lang = (int)Context::getContext()->language->id;
        $start = 0;
        $limit = 100;
        $order_by = 'id_product';
        $order_way = 'DESC';
        $id_category = false;
        $only_active = true;
        $context = null;
        $all_products = Product::getProducts($id_lang, $start, $limit, $order_by, $order_way, $id_category, $only_active, $context);

except that I need to display only the product with a predefined id.

That's why I'm appealing to you to try to help me!

thank you in advance for your help

CodePudding user response:

Use the constructor to get a specific Product instance by id_product.

/** @var int Specific Product ID */
$id_product = 1337;

/** @var Product Specific Product instance */
$specific_product = new Product($id_product);

if(false !== $specific_product) {
  // Product found in database, so can use instance
} else {
  // Product does not exist
}
  • Related