duanbushi1479 2015-10-31 03:29
浏览 7
已采纳

在目录 - >管理类别 - >显示设置中创建新属性字段

Im trying to add attribute field in the Display settings in Manage Categories. I found this tutorial on the 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_* for the different types */
    'label'    => 'CMS Block', /* Your label */
    'input'    => 'select', /* This refers to the 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 does run as I checked it in the core_resources table but the field does not display on the Display Settings Tab. Can anyone help me with this?

  • 写回答

1条回答 默认 最新

  • duandao8607 2015-11-02 07:25
    关注

    You can add a dropdown in manage categories section. Please do the 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 all 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() as $option) {
            $_options[$option["value"]] = $option["label"];
        }
        return $_options;
        }
    
        /**
         * Get a text for option value
         *
         * @param string|integer $value
         * @return string
         */
        public function getOptionText($value)
        {
        $options = $this->getAllOptions();
        foreach ($options as $option) {
            if ($option["value"] == $value) {
                return $option["label"];
            }
        }
        return false;
        }
    
        /**
         * Retrieve Column(s) for 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) for 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 For 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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?