5

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?

2 Answers 2

9

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

5
  • $productObj = new Products(); this part of code is not working Jul 30, 2013 at 21:52
  • sorry it was a type error. Check it now. Also as i mentioned you have to work it out, and also you may have got an error message that why it is not working. You should fix it yourself dude :). Jul 31, 2013 at 8:17
  • 4
    Product::getProducts($id_lang, 0, 0, 'id_product', 'DESC' ); Jan 13, 2014 at 13:05
  • This code is working. Fills an array with all data, including _lang info. Thank you.
    – m3nda
    Apr 16, 2014 at 16:02
  • @AltafHussain This is working fine when I am listing all products in my admin custom module, but not able to display Image. here is my code: $fields_list = array( 'id_image' => array( 'title' => $this->l('Image'), 'align' => 'center', 'image' => 'p', 'filter' => false, 'search' => false, 'orderby' => false, ) ); Jun 2, 2017 at 15:03
2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.