简体   繁体   中英

Magento product list page - group products by color attribute

I need a help with magento. There are two attributes for creating configurable products, size and color. On the category page where products are listed, I want to display only different colors of products not sizes. I've to group products by color.

Ie if there is a shirt with colors red, blue, gray, black and for each color there are a sizes M, L, XL (there are 12 simple products), I need to display only 4 products grouped by color.

Thanks in advance

I believe your approach for configurable products is wrong - IMHO it should be the whole COLOR as a configurable and then SIZES as SIMPLES so in this case you would have 4 configurables and 3 simples for each ex. SHIRT-RED-M, SHIRT-RED-L, SHIRT-RED-XL as the SKU.

But that's just a suggestion..

As for your original problem - isn't it just this:

$collection =  Mage::getModel('catalog/product')
    ->getCollection()
    ->groupByAttribute('color');

?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM