I am trying to display recommended products on a page, the code for a random selection of products is this:

{{block type="ibtheme/product_list_featured" products_count="8" random_products="" template="catalog/product/list/featured.phtml"}}

However I have added an attribute to the products (Yes/No attribute) with the ID of recommended_product, how can I get this shortcode to only display products with the attribute marked as "Yes"?



You can't do that by just modifying the shortcode. The block class (or block type) needs to have built-in support for that attribute. However, because you created the attribute, it most likely won't.

Usually the appropriate thing to do is to create your own module, create a block which extends the class as referenced by ibtheme/product_list_featured and re-implement the method which grabs the product collection.

You should be able to do something like the following:

public function getProducts()
    $collection = parent::getProducts();
    $collection->addAttributeToFilter('recommended_product', 1);
    return $collection;

This probably won't work if flat products are enabled. This also won't work if the products are loaded by the parent method, but there's no way to tell without seeing the code.

If you get all that working, you can specify your own block type in the shortcode. However, there might be a better way as I haven't seen the code (there might be a nice event you can listen to for example).


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.