Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prestashop all products

I need to select all products, but currently my code is:

$products = $category->getProducts((int)($params['cookie']->id_lang), 1, ($nb ? $nb : 10),NULL,NULL,false,true,true /*Random*/, ($nb ? $nb : 10));

How can I reshape this so that the products do not depend on a $category. Is there a getProducts() function that is not child of $category?

like image 576
Martynas Ringys Avatar asked Jul 30 '13 16:07

Martynas Ringys


2 Answers

Yes, in products class there is a function getProducts, which can get you all the products in your shop. You can call that function as below:

$productObj = new Product();
$products = $productObj -> getProducts($id_lang, 0, 0, 'id_product', 'DESC' );

First argument is your site current id language, second is for start, used for pagination purpose, which we kept 0. Third argument is for limit, which limits the number of products to fetch. We also kept it 0, so that no limit clause is applied. Fourth is for order by , and fifth is order way, which you can keep as you need.

Note: This code is not tested, it is just to give you idea. You will need to adjust the arguments according to your needs and where you use this code.

Thank you

like image 103
Altaf Hussain Avatar answered Oct 21 '22 08:10

Altaf Hussain


please, check function description in classes/Product.php:

/**
* Get all available products
*
* @param integer $id_lang Language id
* @param integer $start Start number
* @param integer $limit Number of products to return
* @param string $order_by Field for ordering
* @param string $order_way Way for ordering (ASC or DESC)
* @return array Products details
*/
public static function getProducts($id_lang, $start, $limit, $order_by, $order_way, $id_category = false,
    $only_active = false, Context $context = null) {...}

Regards

like image 33
Alexander Simonchik Avatar answered Oct 21 '22 08:10

Alexander Simonchik