Monday, February 15, 2010

Magento : Add option in display mode of display setting in magento admin panel

Hi This was my requirement:

Client want to set the category view from admin and the subcategory will show in following views:

1) Category Title + Image + Description
2) Category Title + Image
3) Category Title Only

So to add more options in the admin section you need to modify in the following files:

1) magentoroot\app\code\core\Mage\Catalog\Model\Category.php
In this file you need to add your own constants for example I added this:
const DM_CAT_IMG = 'CAT_IMG'; // for category title and image
Similarly you can add as many example as you need.

2) magentoroot\app\code\core\Mage\Catalog\Model\Category\Attribute\Source\Mode.php
This file is used to add options in the drop down. Search for "public function getAllOptions()" and you will get an array of option, you can add your additional options here or rename the existing one.

array(
'value' => Mage_Catalog_Model_Category::DM_CAT_IMG,
'label' => Mage::helper('catalog')->__('Category Title and Image'),
),

Note that DM_CAT_IMG is the contstant we added in first step.

Applying these constants in frontend:

Open this file:
\magentoroot\app\design\frontend\default\default\template\catalog\category\view.phtml

To get current category id use this code
$current = $this->getCurrentCategory()->getId();

To load category object use
$category = Mage::getModel('catalog/category')->load((int)$current);

Whatever options we set in the Display settings will come under the display_mode variable, to get this variable
$displayMode=$category->display_mode;

You will get the display_mode as the value of contacts that we set in step 1.

Now you have all you need.. just need to use it accordingly.

Hope this helps.

0 comments:

Post a Comment