I am building mobile apps integrated with Magento via REST APIs. I have completed the app and created a lot of custom APIs for this purpose. I am now stuck in fetching filterable attributes and associated options for a category listing.
I am aware Magento uses the catalog/layer model for this purpose in the frontend. Most of it is done using blocks. I am not sure how to use this from API since there is no concept of layout here. Correct me if I am wrong.
The app's requirement is this.
- There are categories listed in the app.
- Clicking on a category will list all the products in that category.
- There is a filter button which when clicked should show all available
filters for that particular products listed (results). - Further, clicking on each filter should fetch the relevant products
and the filters will get changed based on whether there are products
for a particular attribute's option.
I am able to do this by calling the Magento functions directly. But it is very heavy. Taking forever to load. This is what I am doing.
- Get all categories using the id.
- Get all filterable attributes in Magento
- Get all options for each attribute
- Load the product collection for each option to determine whether this option has any products in it and to get the count of products.
- Return the products
- Return all attributes and options with count.
I cannot do this way obviously because it is too heavy and taking 1 minute to repond for for 5k products and many attributes. In fact there are 3 for loops.
Does anyone know the right way?
Best Answer
Hi I Know it is a late reply but it may help some other magento api developers.
Request Format
{ "categoryId":"", "limit":"", "page":"", "filters":{ "price":"from-to", "attribute_code":"values " } }