0

I'm trying to display a category within a CMS page. (I know that a workaround would be to include a static block on a Category, but in this instance that is not an option for me). So I have this code in my CMS page:

{{block type="core/template" template="catalog/product/my_template.phtml"}}

Which is working correctly. Within that template file (my_template.phtml), I have a very similar setup to app/design/frontend/core/default/template/catalog/product/list.phtml.

But because this is being called from a CMS page, I'm not within the correct scope to use $this:

<?php
/**
 * Product list template
 *
 * @see Mage_Catalog_Block_Product_List
 */
?>
<?php
    $_productCollection=$this->getLoadedProductCollection();
    $_helper = $this->helper('catalog/output');
?>

How can I manually set up the $_productCollection without access to $this->getLoadedProductCollection(); - for instance, if I have an array of $product_ids, or a $category_id.

I've tried this approach:

$layer = Mage::getSingleton('catalog/layer');
$category = Mage::getModel('catalog/category')->load($category_id);
$layer->setCurrentCategory($category);
$_productCollection = $layer->getProductCollection();

But that is not able to call:

  • $_product->getRatingSummary() (when looping through $_productCollection as $_product)
  • $this->getReviewsSummaryHtml($_product, 'short'), or
  • $this->getPriceHtml($_product, true)

Any pointers?

1

I'm not sure if this fits your needs, but by the looks of it, it should.
I've created this extension that allows you to show product lists based on conditions. You can define a condition in the exact same way you define a cart rule.
You can choose to include the link to the rule page in the main menu.
It evens supports SEF URLs and layered navigation.

In your case you need to create such a rule and for conditions set ID is one of or SKU is one of.
Full documentation of the module can be found here

| improve this answer | |
  • Exactly what I was looking for. Really a great concept - and digging the SEF URLs. I'm surprised this functionality isn't native with Magento. I can only imagine it's quite a sought after feature. +1! – Moose Nov 26 '14 at 11:26
  • quick question. I'm trying to create a page without the layered navigation on the left hand side, so a single (1) column view. I don't see that being possible with this module, right? – Moose Nov 26 '14 at 12:29
  • 1
    By default all pages have 2-columns-left format. But you can edit app/design/frontend/base/default/layout/easylife_ruleproducts.xml and make your page use one column. Instead of <update handle="page_two_columns_left" /> put <update handle="page_one_column" />. This will change the layout for all pages defined by rules. If you want different layouts for different rules you need to code. I'm considering adding this as a feature. I didn't do it so far, because the module is not that used, yet. – Marius Nov 26 '14 at 12:32
  • Exactly what I was looking for, thanks a lot. P.S. I understand completely. It would definitely be a useful feature in future if you decide to continue development. Another possibility is also the ability to update layout XML inline, similarly to the Design tab of CMS pages. – Moose Nov 26 '14 at 12:44
  • 1
    @moose. At first I wanted to implement the Design feature of the categories, but I realized it is not needed for a minimum viable product. Now I'm considering adding it. – Marius Nov 26 '14 at 12:47

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.