0

Happy Holidays everyone,

I'm in a quest to develop a block that shows 3 given categories within same view block.

I have this till now in my phtml file:

<?php
/**
 * Displays multiple category view templates along with the product list for it
 */
/* @var $this Mage_Core_Block_Template */

$category_ids     = explode(',', $this->getData('category_ids'));
$current_category = Mage::registry('current_category');

if ($current_category) {
    Mage::unregister('current_category');
}

foreach ($category_ids as $it => $id) {

    $category = Mage::getModel('catalog/category')->load(trim($id));

    if (!$category->getId()) {
        continue;
    }

    Mage::register('current_category', $category);

    global ${"category_"$it} = $this->getLayout()->createBlock('catalog/product_list', 'product_list_'.$id, array('template' => 'catalog/product/list.phtml'));

    Mage::unregister('current_category');

}

foreach ($category_ids as $it => $id) {
        global array product_list ( array $product_list [, array ${"category_"$it}] );
}

Mage::register('current_category', 'category_1');

echo $this
    ->getLayout()
        ->createBlock('catalog/category_view', 'category_1', array('template' => 'catalog/category/view.phtml'))
        ->append($product_list, 'product_list')
        ->toHtml();

}

if ($current_category) {
    Mage::unregister('current_category');
}

and I have this in my cms design page:

<reference name="content">
    <block type="core/template" name="multiple_categories" template="catalog/category/multiple.phtml">
        <action method="setData"><key>category_ids</key><val>12,13,26</val></action>
     </block>
</reference>

This code is an adaptation of this answer, which successfully shows multiple categories, but with multiple blocks.

Unfortunately when I set code given above, my CMS page goes blank.

Does anyone know how to help me? Any tip is appreciated.

  • A blank page is probably due to a PHP error. You have to start debugging that, here's a guide: http://magento.stackexchange.com/questions/428/fundamentals-for-debugging-a-magento-store – Fabian Schmengler Jan 20 '16 at 12:34

1 Answers1

1

Actually, to solve my problem, I've made a workaround which is probably usefull for everyone who's trying to accomplish what I asked:

I created a new sub-category in store view desired with all products of the categories mixed, then used only this new subcategory I created, and virtually I'm showing all 3 categories at once.

It's ugly but works, since noone can help me better...

About the code I was writing, I've corrected a bunch of php errors, and resulting code was this:

<?php
/**
 * Displays multiple category view templates along with the product list for it
 */
/* @var $this Mage_Core_Block_Template */

$category_ids     = explode(',', $this->getData('category_ids'));
$current_category = Mage::registry('current_category');

if ($current_category) {
    Mage::unregister('current_category');
}

foreach ($category_ids as $it => $id) {

    $category = Mage::getModel('catalog/category')->load(trim($id));

    if (!$category->getId()) {
        continue;
    }

    Mage::register('current_category', $category);

    global ${"category_".$it};
    ${"category_".$it} = $this->getLayout()->createBlock('catalog/product_list', 'product_list_'.$id, array('template' => 'catalog/product/list.phtml'));

    Mage::unregister('current_category');

}   

foreach ($category_ids as $it => $id) {
        global $product_list;
    $product_list = $product_list . 'category_'.$it;
}   

Mage::register('current_category', $current_category);

echo $this
    ->getLayout()
        ->createBlock('catalog/category_view', 'category_1', array('template' => 'catalog/category/view.phtml'))
        ->append($product_list, 'product_list')
        ->toHtml();

if ($current_category) {
    Mage::unregister('current_category');
}

I don't think this will work someday but at least it doesn't have syntax problems anymore.