views:

88

answers:

1

I have created attributes; “Shop by Type” and “Shop by Color”. They work great within the layered navigation and extended search. I’ve designed graphics and placed them in the home page and would like to link to the respective attribute’s assigned products. Been searching the webs, but so far have been unsuccessful.

If there’s no direct possible way, the next method would be creating cms pages and linking to it directly. How can I display products that are assigned to a specific attribute? Specifically “Multiple Select” types.

I know you guys prefer at least some attempts, but as mentioned, been playing with it with no luck. I would appreciate some kind of starting point.

Happy Holidays!

Edit: I was able to put together this code that lists all the products assigned to said category id. Tried to filter it down where it only displays products that have an assigned same attribute with no luck yet. Any ideas?

<?php
$cat_id = 123; // category id
$category = Mage::getModel('catalog/category')->load($cat_id);

$_products = $category->getProductCollection()
->addAttributeToSelect('shop_by_color');

if (($this->getProductCollection()) && $_products->getSize()): ?>

By the way, $cat_id is a sub category of root. Is there an easier way to point to it instead of using direct id number?

A: 

I don't know if that's the exact answer you're looking for, but you should change

$_products = $category->getProductCollection()->addAttributeToSelect('shop_by_color');

to

$_products = $category->getProductCollection()
->addAttributeToSelect('shop_by_color')
->addAttributeToFilter(array('attribute'=>'shop_by_color', 'in'=>array('red', 'blue', ...)));

so that it lists only product where their shop_by_color is one of the given constant. It's up to you to get those out of the url path or query string and you get your base for dynamic pages showing only products matching one of the input colors.

Zeograd
Thanks Zeograd. I tried your method, worked on it a little and for some reason kept getting "Invalid Attribute Error". It doesn't recognize 'shop_by_color'. I'll get back to it at end of day and let you know if I come out with a solution. Any suggestions would be appreciated.
monocat
I suggest to debug the generated sql with Mage::log($_products->getSelect()->__toString());if the error isn't thrown too early.
Zeograd