Jump to content

Get all products by category/brand prestashop 1.7


MrEduar

Recommended Posts

Hi, I am trying to make a module that will get all the products of a specific category/brand.

For example, in my front office I have a select, in this select I can select multiple categories. If, for example, I select the category sunglasses and optical glasses, I would like to get all the products in these categories. And if the customer selects a brand within sunglasses, then I would like to get only the sunglasses of that specific brand.

Maybe something like this.

$products = Product::getProducts($langId, 0, 0, 'id_product', 'DESC', $categoryId, true);

But this would only bring me products within a single category. I need to get products within multiple categories and also the possibility to filter it by brands.


How can I achieve this?
Thank you in advance.

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

  • 1 month later...
1 minute ago, JulienPct said:

Hello,

You need the products and all their categories if I understand correctly? 

Hello!
No, I need all products within multiple categories. If I select 2 or more categories, get all the products in those categories.

Link to comment
Share on other sites

You said you wanted to create a module, why not create a DB query at the same time containing all the information you need?

I can understand that you want to use the existing ones so that you don't have any problem of lack of information. In this case, can't you override the query called by the getProducts() function?

Link to comment
Share on other sites

From memory PrestaShop has a method to retrieve products and a method to retrieve all its categories.
I don't remember a method to retrieve products based on categories.

Personally I would try to override the query called by getProducts() to add a test based on categories

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...