2

I figure this part of a code is getting all products for product page

$collection = Mage::getResourceModel('catalog/product_collection')
        ->setStoreId($this->getStoreId())
        ->addCategoryFilter($this);

I need to get available colors only for each product on product list page. So for example if my configurable product consists of 3 simple products with colors: red, green, blue, but simple product with color green is disabled, product with color red is out of stock, how do I show only color "blue".

I would like to do it in single query so it doesn't waste my resources. Is it possible to do some joins on default collection to get that data?

Here is the example of loading few products and under each product's image I would like to show available color. enter image description here

2

Try this script, it works for me.

$collection = Mage::getResourceModel('catalog/product_collection')
              ->getCollection()
              ->addAttributeToSelect('*')
              ->addAttributeToFilter('color', 'blue');
  • I was thinking more of getting all attributes that are available for each product. Let's say we have 3 colors but only blue is available so it returns blue to me, next product has 4 colors but only 2 available – FosAvance Feb 24 '17 at 6:52
  • @FosAvance Magento already done that code, in rwd theme so you dont have to do by your own – Murtuza Zabuawala Feb 24 '17 at 7:01
  • @Murtuza Zabuawala does it loads product by product and then takes its attribute or takes it all together? – FosAvance Feb 24 '17 at 19:54
1

First of all this magento theme does not support swatches.

Go to system->config->general->design->package

and set Current Package Name to rwd

so this default rwd theme support swatches.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.