Jump to content

getProducts() returns empty arrays...


Recommended Posts

Dear forum,

 

only yesterday, I was assigned some issue on a PrestaShop project at work :D

This is my first contact with PrestaShop...

It's also still not clear to me all the customizations that my colleagues have done up until this point...

 

We have calls like the following in one of the files that I'm having to edit:

 

$mujer = new Category(2);
$productos_mujer = $mujer->getProducts();
$hombre = new Category(3);
$productos_hombre = $hombre->getProducts();

 

This is the problem I'm having:

We have products in all categories, ie all categories are nonempty. However, the getProducts method is returning empty arrays for some categories...

 

I've mentioned this to my colleagues and they suggest it may be related to some 1.5.2 upgrade, so that I'm suspecting my problems could be related to say this thread: http://www.prestasho...lersprice-drop/

 

As far as I can tell, we are using PrestaShop™ 1.5.2.0

 

I've tried the BO > Preferences > Products > Pagination > Default order by > Product Name suggestions from the above thread to no avail...

 

Any help or suggestions are appreciated :D

Link to comment
Share on other sites

Hey math_php, good to read you...

Thanks :D

 

I've tried your suggestions to no avail...

 

If anything, my saying "empty array" yesterday was not quite correct.

On second look, I think that the getProducts method is returning "false".

 

With our current setup/database/... I don't think that anything is being set for the $result attribute of getProducts.

 

As far as I can tell, the return value of say $mujer->getProducts($id_lang,1,100) is being sent through the if (!$result) in the following extract of the getProducts method. Here, it's lines 667-676 of classes/Category.php...

 

				$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
			if ($order_by == 'orderprice')
					Tools::orderbyPrice($result, $order_way);

			if (!$result)
					return false;

			/* Modify SQL result */
			return Product::getProductsProperties($id_lang, $result);
	}

 

Like said, this is happening for some categories only. We have a few categories where all is good!!!

 

Hope this makes some sense...

Edited by prestashop_forum_account (see edit history)
Link to comment
Share on other sites

  • 1 month later...

Hi,

 

getProducts method needs id_lang a page number and a maximum of products.

I gave you default prestashop id_lang, but in most case you have to get the cookie id_lang.

 

This should work, else put the fault on Microsoft, they deserve it :D

 

Hi,

 

do you know in which class can I find the getproduct function?

 

Thanks in advance

Patrizia

Link to comment
Share on other sites

It could work with

 

$all_product = Product::getProducts(Configuration::get('PS_LANG_DEFAULT'),0,1000000);

1000000 is max number of products.

 

But this solution may be ok for you but it really depends on what you want to make.

 

I made a module that display all products in home page, it is a modified homefeatured module, is this what you want to do ?

Link to comment
Share on other sites

It could work with

 

$all_product = Product::getProducts(Configuration::get('PS_LANG_DEFAULT'),0,1000000);

1000000 is max number of products.

 

But this solution may be ok for you but it really depends on what you want to make.

 

I made a module that display all products in home page, it is a modified homefeatured module, is this what you want to do ?

 

I'm using a module that shows in home the home featured products and some other products tagged by my customer.

I've rewritten the getProduct function so I could filter the products using the product tags.

The only thing is that I filter only the products that are homefeatured or, at least, present in a single category.

I wanted to show all products that had that specific tag.

 

Now it seems we have found a solution. The client will flag as home products the one that flag as "recommended" for example.

 

Thank you for everything :) :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...