MrEduar Posted October 8, 2021 Share Posted October 8, 2021 (edited) 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 October 8, 2021 by MrEduar (see edit history) Link to comment Share on other sites More sharing options...
MrEduar Posted November 16, 2021 Author Share Posted November 16, 2021 Up Link to comment Share on other sites More sharing options...
JulienPct Posted November 16, 2021 Share Posted November 16, 2021 Hello, You need the products and all their categories if I understand correctly? Link to comment Share on other sites More sharing options...
MrEduar Posted November 16, 2021 Author Share Posted November 16, 2021 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 More sharing options...
JulienPct Posted November 16, 2021 Share Posted November 16, 2021 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 More sharing options...
MrEduar Posted November 16, 2021 Author Share Posted November 16, 2021 Yes I could do it with raw SQL, but in fact prestashop does not have a method to get the products from multiple categories? Do I have to do it manually? Link to comment Share on other sites More sharing options...
JulienPct Posted November 16, 2021 Share Posted November 16, 2021 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 More sharing options...
MrEduar Posted November 16, 2021 Author Share Posted November 16, 2021 Ok, thank you very much for your help. Regards Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now