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
?
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With