php - Creating new attribute field in Catalog->Manage Categories->Display Settings -
im trying add attribute field in display settings in manage categories. found tutorial on web http://www.marketingadept.com/blog/magento-developers-add-a-custom-field-to-the-category-admin-page/
config.xml
<?xml version="1.0" encoding="utf-8"?> <config> <modules> <cmsblock> <version>0.0.1</version> </cmsblock> </modules> <global> <resources> <cmsblock_setup> <setup> <module>cmsblock</module> <class>mage_catalog_model_resource_eav_mysql4_setup</class> <connection> <use>core_setup</use> </connection> </setup> </cmsblock_setup> <cms_block_setup_write> <connection> <use>core_write</use> </connection> </cms_block_setup_write> <cms_block_setup_read> <connection> <use>core_read</use> </connection> </cms_block_setup_read> </resources> </global> </config>
mysql4-install-0.0.1.php
$installer = $this; $installer->startsetup(); $entitytypeid = $installer->getentitytypeid('catalog_category'); $attributesetid = $installer->getattributesetid($entitytypeid); $attributegroupid = $installer->getattributegroupid($entitytypeid, $attributesetid,5); $installer->addattribute('catalog_category', 'cms_block', array( 'type' => 'varchar', /* type - see eav_entity_* different types */ 'label' => 'cms block', /* label */ 'input' => 'select', /* refers type of form field should display*/ 'global' => mage_catalog_model_resource_eav_attribute::scope_store, 'visible' => true, 'required' => false, 'user_defined' => false, 'option' => array('values'=> array('option 1','option 2')) )); $installer->addattributetogroup( $entitytypeid, $attributesetid, $attributegroupid, 'cms_block', '52' ); $installer->endsetup();
the installer script run checked in core_resources table field not display on display settings tab. can me this?
you can add dropdown in manage categories section. please following :-
app/etc/modules/magpedia_categorytab.xml
<?xml version="1.0"?> <config> <modules> <magpedia_categorytab> <active>true</active> <codepool>local</codepool> <version>0.1.0</version> </magpedia_categorytab> </modules> </config>
app/code/local/magpedia/categorytab/etc/config.xml
<?xml version="1.0"?> <config> <modules> <magpedia_categorytab> <version>0.1.0</version> </magpedia_categorytab> </modules> <global> <helpers> <categorytab> <class>magpedia_categorytab_helper</class> </categorytab> </helpers> <models> <categorytab> <class>magpedia_categorytab_model</class> <resourcemodel>categorytab_mysql4</resourcemodel> </categorytab> </models> <resources> <categoryattribute1446446121_setup> <setup> <module>magpedia_categorytab</module> <class>mage_catalog_model_resource_eav_mysql4_setup</class> </setup> <connection> <use>core_setup</use> </connection> </categoryattribute1446446121_setup> <categoryattribute1446446121_write> <connection> <use>core_write</use> </connection> </categoryattribute1446446121_write> <categoryattribute1446446121_read> <connection> <use>core_read</use> </connection> </categoryattribute1446446121_read> </resources> </global> </config>
app/code/local/magpedia/categorytab/helper/data.php
<?php class magpedia_categorytab_helper_data extends mage_core_helper_abstract { }
app/code/local/magpedia/categorytab/model/eav/entity/attribute/source/categoryoptions14464461210.php
<?php class magpedia_categorytab_model_eav_entity_attribute_source_categoryoptions14464461210 extends mage_eav_model_entity_attribute_source_abstract { /** * retrieve options array * * @return array */ public function getalloptions() { if (is_null($this->_options)) { $this->_options = array( array( "label" => mage::helper("eav")->__("cms block 1"), "value" => 1 ), array( "label" => mage::helper("eav")->__("cms block 1"), "value" => 2 ), array( "label" => mage::helper("eav")->__("cms block 1"), "value" => 3 ), array( "label" => mage::helper("eav")->__("cms block 1"), "value" => 4 ), ); } return $this->_options; } /** * retrieve option array * * @return array */ public function getoptionarray() { $_options = array(); foreach ($this->getalloptions() $option) { $_options[$option["value"]] = $option["label"]; } return $_options; } /** * text option value * * @param string|integer $value * @return string */ public function getoptiontext($value) { $options = $this->getalloptions(); foreach ($options $option) { if ($option["value"] == $value) { return $option["label"]; } } return false; } /** * retrieve column(s) flat * * @return array */ public function getflatcolums() { $columns = array(); $columns[$this->getattribute()->getattributecode()] = array( "type" => "tinyint(1)", "unsigned" => false, "is_null" => true, "default" => null, "extra" => null ); return $columns; } /** * retrieve indexes(s) flat * * @return array */ public function getflatindexes() { $indexes = array(); $index = "idx_" . strtoupper($this->getattribute()->getattributecode()); $indexes[$index] = array( "type" => "index", "fields" => array($this->getattribute()->getattributecode()) ); return $indexes; } /** * retrieve select flat attribute update * * @param int $store * @return varien_db_select|null */ public function getflatupdateselect($store) { return mage::getresourcemodel("eav/entity_attribute") ->getflatupdateselect($this->getattribute(), $store); } }
app/code/local/magpedia/categorytab/sql/categoryattribute1446446121_setup/mysql4-install-0.1.0.php
<?php $installer = $this; $installer->startsetup(); $installer->addattribute("catalog_category", "custom_cms_block", array( "type" => "int", "backend" => "", "frontend" => "", "label" => "cms block", "input" => "select", "class" => "", "source" => "categorytab/eav_entity_attribute_source_categoryoptions14464461210", "global" => mage_catalog_model_resource_eav_attribute::scope_store, "visible" => true, "required" => false, "user_defined" => false, "default" => "", "searchable" => false, "filterable" => false, "comparable" => false, "visible_on_front" => false, "unique" => false, "note" => "" )); $installer->endsetup();
thanks
Comments
Post a Comment