5

I would like to change the default grid/list view based on the category. There is 1 category I would like to change to a list view only. Is this possible through Custom Layout Update under Manage Categories?

3

The simplest and easiest to implement is to use the Custom Design tab for the category you want to force the grid / list view by entering the following in the Custom Layout Update:

Grid View:

<reference name="product_list_toolbar">
<action method="setData"><key>_current_grid_mode</key><value>grid</value</action>
</reference>

List View:

<reference name="product_list_toolbar">
<action method="setData"><key>_current_grid_mode</key><value>list</value></action>
</reference>
1

This is not possible out of the box.
But with some coding is possible.
Here is how I would do it.
I would add a new yes/no attribute on the category called only_list_view.
Then rewrite the block Mage_Catalog_Block_Product_List_Toolbar and in your new block make the method _construct look like this:

protected function _construct()
{
    parent::_construct();
    $category = Mage::registry('current_category');
    if ($category) { //if on the category page
         if ($category->getOnlyListView()) { //if the category is flagged with only list view
              $this->_availableMode = array('list' => $this->__('List')); //set the available modes to list only.
         }
    }
}

You can also try the quick and dirty method and instead of adding the category attribute, just hard-code the id.
So

if ($category->getOnlyListView())

will become

if ($category->getId() == YOUR ID HERE)

But that's ugly.

1

I think perhaps the simplest way is to split app/design/frontend/{package}/{theme}/template/catalog/product/list.phtml into two files, one containing List mode and another Grid (right now they are combined into single file, toolbar object determining which part of it should be displayed). After that it's a simple matter of choosing template from Custom Layout Update on every category Design tab. Put something like that there:

<reference name="product_list">
    <action method="setTemplate"><template>catalog/product/list-only.phtml</template></action>
</reference>

Its not an elegant way either, but this is Magento.

0

It is not a default functionality, You can create custom attribute for category, if you want something manageable from admin:

Create a small module :

app/etc/modules/Tbi_CustomCategoryAttribute.xml

<?xml version="1.0"?> <config>
    <modules>
        <Tbi_CustomCategoryAttribute>
            <active>true</active>
            <codePool>community</codePool>
        </Tbi_CustomCategoryAttribute>
    </modules> </config>

Then in config.xml

app/code/community/Tbi/CustomCategoryAttribute/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Tbi_CustomCategoryAttribute>
            <version>0.0.1</version>
        </Tbi_CustomCategoryAttribute>
    </modules>

    <global>
        <resources>
            <add_category_attribute>
                <setup>
                    <module>Tbi_CustomCategoryAttribute</module>
                    <class>Mage_Catalog_Model_Resource_Setup</class>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </add_category_attribute>
            <add_category_attribute_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </add_category_attribute_write>
            <add_category_attribute_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </add_category_attribute_read>
        </resources>
    </global>
</config>

Create a file in

data

like mysql4-install-x.x.x.php

$this->startSetup();
$this->addAttribute(Mage_Catalog_Model_Category::ENTITY, 'custom_attribute', array(
    'group'         => 'General',
    'input'         => 'textarea',
    'type'          => 'text',
    'label'         => 'Custom attribute',
    'backend'       => '',
    'visible'       => true,
    'required'      => false,
    'visible_on_front' => true,
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));

$this->endSetup();

Then you can use it in view like :

<?php if($_customAttribute = $this->getCurrentCategory()->getCustomAttribute()): ?>
    <?php echo $_helper->categoryAttribute($_category, $_customAttribute, 'custom_attribute') ?>
<?php endif; ?>

Thus you can modify you grid/list view as per set in admin end.

This might make a small module for you and should be helpful.

0

I'm just editing core code.I know we should not do it.I'm just giving for fast response only.first try to understand this.

Mage_Catalog_Block_Product_List_Toolbar

1.modify _construct

2.add one public method

3.comment switch case in construct

4.call added public method from _construct

5.set this method from using action tag in your desired category's custom layout update

protected function _construct()
    {
        parent::_construct();
        $this->_orderField  = Mage::getStoreConfig(
            Mage_Catalog_Model_Config::XML_PATH_LIST_DEFAULT_SORT_BY
        );

        $this->_availableOrder = $this->_getConfig()->getAttributeUsedForSortByArray();

        /*switch (Mage::getStoreConfig('catalog/frontend/list_mode')) {
            case 'grid':
                $this->_availableMode = array('grid' => $this->__('Grid'));
                break;

            case 'list':
                $this->_availableMode = array('list' => $this->__('List'));
                break;

            case 'grid-list':
                $this->_availableMode = array('grid' => $this->__('Grid'), 'list' =>  $this->__('List'));
                break;

            case 'list-grid':
                $this->_availableMode = array('list' => $this->__('List'), 'grid' => $this->__('Grid'));
                break;
        }*/
        $this->modepercategorywise(Mage::getStoreConfig('catalog/frontend/list_mode'));

        $this->setTemplate('catalog/product/list/toolbar.phtml');
    }
    public function modepercategorywise($mode)
    {
     switch ($mode) {
          case 'grid':
                $this->_availableMode = array('grid' => $this->__('Grid'));
                break;

            case 'list':
                $this->_availableMode = array('list' => $this->__('List'));
                break;

            case 'grid-list':
                $this->_availableMode = array('grid' => $this->__('Grid'), 'list' =>  $this->__('List'));
                break;

            case 'list-grid':
                $this->_availableMode = array('list' => $this->__('List'), 'grid' => $this->__('Grid'));
                break;

    }
    }

under Custom Design tab-> Custom Layout Update : add this:

<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
<action method="modepercategorywise"><parem>list</parem></action>
</block>

my sincere suggestion is please override toolbar.php block file and add one extra public method.I hope this helpful.

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.