Goal:
I need to display on homepage a list of colors of products available at the moment in the particular store view.
Description:
- Products have color attribute (the default attribute which exists in Magento just after installation).
- There are many colors but not all colors are associated with products yet.
- There are a few store views and each has different products (so also the list of colors on homepage will be different in each store view).
- If color is associated only with products that are out of stock, it shouldn't be on the list of colors on homepage.
Partial solution:
Based on this thread: https://stackoverflow.com/a/9562720/2461702 I was able to accomplish first part of the job:
get the list of colors which are associated with products.
How to filter this list further so that it contains only the colors which are associated with:
-
products that are NOT out of stock?
-
products from the current store view?
-
products from selected category?
Is there any easy way to speed up the code posten in: https://stackoverflow.com/a/9562720/2461702 ?
Best Answer
It'll get you the products associated with the colors you listed, and will only give you the products that are in stock for a given category. If you are working with flat catalog for products, then the store filter isn't needed because it will pick products from
catalog_product_flat_X
, but if you don't use it, then just throw ain there.
Hope this helps