<?php
$_category = Mage::getModel(‘catalog/category’)->load(17); //$categoryid for which the child categories to be found
$childCategories = $category_model->getResource()->getAllChildren($_category); //array consisting of all child categories id
print_r($childCategories);
?>
Tag Archives: Magento
Include Static Block in CMS Page Magento
{{block type="cms/block" block_id="your_block_id"}}
Magento Create Attribute Source Model
1) Create the file app/code/local/Mage/Eav/Model/Entity/Attribute/Source/Cms.php and paste the code
<?php
class Mage_Eav_Model_Entity_Attribute_Source_Cms extends Mage_Eav_Model_Entity_Attribute_Source_Table{
public function getAllOptions($withEmpty = true){
if (!$this->_options) {
$options = array();
$options[] = array(
‘value’ => ‘0’,
‘label’ => ‘No’,
);
$options[] = array(
‘value’ => ‘1’,
‘label’ => ‘Yes’,
);
$this->_options = $options;
}
$options = $this->_options;
if ($withEmpty) {
array_unshift($options, array(
‘value’ => ”,
‘label’ => ‘Please Select’,
));
}
return $options;
}
Magento Delete Custom Category Attribute
1)Change the directory to the root of magento installation
2) vi app/etc/modules/Pcode_Attribute.xml and paste the below given content
<config>
<modules>
<Pcode_Attribute>
<active>true</active>
<codePool>local</codePool>
</Pcode_Attribute>
</modules>
</config>
3) mkdir app/code/local/
4) mkdir app/code/local/Pcode
5 )mkdir app/code/local/Pcode/Attribute
6) mkdir app/code/local/Pcode/Attribute/etc
7) mkdir app/code/local/Pcode/Attribute/sql
8) mkdir app/code/local/Pcode/Attribute/sql/categoryattribute_setup
9) vi app/code/local/Pcode/Attribute/sql/categoryattribute_setup/mysql4-install-0.1.0.php and paste the below given code
<?php
$this->startSetup();
$this->removeAttribute(‘catalog_category’, attribute_code);
$this->endSetup();
?>
10) vi app/code/local/Pcode/Attribute/etc/config.xm and paste the below code
<?xml version=”1.0″?>
<config>
<modules>
<Pcode_Attribute>
<version>0.1.0</version>
</Pcode_Attribute>
</modules>
<global>
<resources>
<categoryattribute_setup>
<setup>
<module>Pcode_Attribute</module>
<class>Mage_Eav_Model_Entity_Setup</class>
</setup>
<connection>
<use>default_setup</use>
</connection>
</categoryattribute_setup>
</resources>
</global>
</config>
Create Custom Category Attribute Dropdown Magento
1)Change the directory to the root of magento installation
2) vi app/etc/modules/Pcode_Attribute.xml and paste the below given content
<config>
<modules>
<Pcode_Attribute>
<active>true</active>
<codePool>local</codePool>
</Pcode_Attribute>
</modules>
</config>
3) mkdir app//code/local/
4) mkdir app//code/local/Pcode
5 )mkdir app//code/local/Pcode/Attribute
6) mkdir app//code/local/Pcode/Attribute/etc
7) mkdir app//code/local/Pcode/Attribute/sql
8) mkdir app/code/local/Pcode/Attribute/sql/categoryattribute_setup
9) vi app/code/local/Pcode/Attribute/sql/categoryattribute_setup/mysql4-install-0.1.0.php and paste the below given code
<?php
$this->startSetup();
$this->addAttribute(‘catalog_category’, ‘show_line_name’, array(
‘group’ => ‘General Information’,
‘input’ => ‘select’,
‘type’ => ‘int’,
‘label’ => ‘Show Line Name’,
‘backend’ => ”,
‘visible’ => true,
‘required’ => false,
‘wysiwyg_enabled’ => true,
‘visible_on_front’ => true,
‘source’ => ‘eav/entity_attribute_source_boolean’,
‘global’ => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
$this->endSetup();
?>
10) vi app//code/local/Pcode/Attribute/etc/config.xm and paste the below code
<?xml version=”1.0″?>
<config>
<modules>
<Pcode_Attribute>
<version>0.1.0</version>
</Pcode_Attribute>
</modules>
<global>
<resources>
<categoryattribute_setup>
<setup>
<module>Pcode_Attribute</module>
<class>Mage_Eav_Model_Entity_Setup</class>
</setup>
<connection>
<use>default_setup</use>
</connection>
</categoryattribute_setup>
</resources>
</global>
</config>
Create Custom Category Attribute Magento
1)Change the directory to the root of magento installation
2) vi app/etc/modules/Pcode_Attribute.xml and paste the below given content
<config>
<modules>
<Pcode_Attribute>
<active>true</active>
<codePool>local</codePool>
</Pcode_Attribute>
</modules>
</config>
3) mkdir app//code/local/
4) mkdir app//code/local/Pcode
5 )mkdir app//code/local/Pcode/Attribute
6) mkdir app//code/local/Pcode/Attribute/etc
7) mkdir app//code/local/Pcode/Attribute/sql
8) mkdir app/code/local/Pcode/Attribute/sql/categoryattribute_setup
9) vi app/code/local/Pcode/Attribute/sql/categoryattribute_setup/mysql4-install-0.1.0.php and paste the below given code
<?php
$this->startSetup();
$this->addAttribute(‘catalog_category’, ‘new_attribute’, array(
‘group’ => ‘General’,
‘input’ => ‘text’,
‘type’ => ‘varchar’,
‘label’ => ‘New attribute’,
‘backend’ => ”,
‘visible’ => 1,
‘required’ => 0,
‘user_defined’ => 1,
‘global’ => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
$this->endSetup();
?>
10) vi app//code/local/Pcode/Attribute/etc/config.xm and paste the below code
<?xml version=”1.0″?>
<config>
<modules>
<Pcode_Attribute>
<version>0.1.0</version>
</Pcode_Attribute>
</modules>
<global>
<resources>
<categoryattribute_setup>
<setup>
<module>Pcode_Attribute</module>
<class>Mage_Eav_Model_Entity_Setup</class>
</setup>
<connection>
<use>default_setup</use>
</connection>
</categoryattribute_setup>
</resources>
</global>
</config>
Category name on product listing page Magento
<?php
$category = Mage::registry(‘current_category’);
echo $category->getName();
?>
Custom Image Attribute generates error when no image is set Magento
Ensure that Placeholder image for the new image attribute is uploaded from admin panel
System > Configuration > Catalog > Catalog > Product image placeholders
Get custom Image Attribute value on product listing page Magento
1) Open the page catalog xml and search the for the string “catalog/product/list.phtml’
2) Include the code
<action method=”addAttribute”><name>alternate_another_imageimage</name></action>
after
<block type=”catalog/product_list” name=”product_list” template=”catalog/product/list.phtml”>
3) Call the below given code on list.phtml
$another_image = $this->helper(‘catalog/image’)->init($_product, another_image)->resize(135); // Assuming another_image is the attribute code
Remove custom category attribute Magento
<?php
$this->startSetup();
$this->removeAttribute(‘catalog_category’, ‘show_line_name’);
$this->endSetup();
?>