0

I added a new attribute 'featured_on_productpage' type yes/no and want to use something like this on one of the cms pages. I included this {{block type="catalog/product_list" category_id="7" attribute_code=”featured_on_productpage” attribute_value=”1″ template="catalog/product/list.phtml"}} in the editor of the cms page, but instead of showing only products with the attribute set to 'yes' it shows all products of this category.

What's wrong?

Thanks.

6
  • I don't even think it should work like you expected it to work.
    – Marius
    Sep 10 '14 at 12:31
  • Does that mean the code I found (the link) is wrong?
    – Sven
    Sep 10 '14 at 12:41
  • Yep, the code is definitely wrong. But I think the problem is that you didn't read that post. You focused on the code. The post actually asks a question. IF that is possible. The answer is 'not out of the box'.
    – Marius
    Sep 10 '14 at 12:43
  • So the only way is to do something like this atwix.com/magento/products-list-cms or this inchoo.net/magento/…?
    – Sven
    Sep 10 '14 at 12:45
  • How can it be the "only way" if you listed 2 links? :). I'm sure there are more ways of doing it, but I would start with one of those. the guys and girls ar atwix and inchoo know what they are talking about.
    – Marius
    Sep 10 '14 at 12:46
2

Just so this question would have an answer...
This is not possible out of the box.
you will need to create your own block that extends the catalog/product_list block and handles the additional attributes.

You need to rewrite the _getProductCollection method and make it look like this:

protected function _getProductCollection() 
{
    if (is_null($this->_productCollection)) {
       $this->_productCollection = parent::_getProductCollection(); //do what the parent class does
       //check if you should filter by an attribute
       if ($this->hasData('attribute_code') && $this->hasData('attribute_value')) {
           $this->_productCollection->addAttributeToFilter($this->getData('attribute_code'), $this->getData('attribute_value'));
       }
    }
    return $this->_productCollection();
}

Then you can use your block like this:

{{block type="[module]/product_list" category_id="7" attribute_code=”featured_on_productpage” attribute_value=”1″  template="catalog/product/list.phtml"}}
0

After rethinking the problem and discussing it with another developer I used another solution. Instead of an attribute I use an additional category "featured" (to be exact I use one additional category for each existing category so I can also differentiate between them ... in my case no problem because the shop has and will have only a single-digit number of categories) and let display it on my page with this

{{block type="catalog/product_list" name="home.catalog.product.list" alias="products_homepage" category_id="10" template="catalog/product/list.phtml"}}

I think the additional advantage of this solution is that you can see at a glance which product is in the featured category and which not (in the manage categories area).

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.