【问题标题】:Creating Category Attribute in Magento 1.9.2 via setup script通过安装脚本在 Magento 1.9.2 中创建类别属性
【发布时间】:2016-09-22 06:44:22
【问题描述】:

我想创建三个不同的类别属性,一个自定义输入文本,一个所见即所得的文本区域,以及另一个类别图像上传。

我首先从自定义输入文本开始,因为我认为这是最简单的,但它不起作用。我检查了 core_resource 以查看版本是否已注册,但未注册,并且该属性不存在于类别中。

这是我的代码

app/etc/modules/Rnd_Customheader.xml

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

app/code/local/Rnd/Customheader/等

<?xml version="1.0"?>
<config>
<modules>
    <Rnd_Customheader>
        <version>0.1.0</version>
    </Rnd_Customheader>
</modules>
<global>
    <resources>
        <Rnd_Customheader_setup>
          <setup>
               <module>Rnd_Customheader</module>
               <class>Mage_Catalog_Model_Resource_Eav_Mysql4_Setup</class>
          </setup>
          <connection>
            <use>default_setup</use>
          </connection>
      </Rnd_Customheader_setup>
    </resources>  
</global>
</config> 

app/code/local/Rnd/Customheader/sql/rnd_customheader_setup

<?php
    $installer = $this;
    $installer->startSetup();
    $attribute  = array(
        'type'          =>  'text',
        'label'         =>  'Custom Header (If you want different page header)',
        'input'         =>  'text',
        'global'        =>  Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
        'visible'       =>  true,
        'required'      =>  false,
        'user_defined'  =>  true,
        'default'       =>  "",
        'group'         =>  "General Information"
    );
    $installer->addAttribute('catalog_category', 'custom_header', $attribute);
    $installer->endSetup();
?>

这是我的参考

https://magento.stackexchange.com/questions/94833/add-custom-attribute-for-category

http://gauss-development.com/blog/tutorials/adding-custom-category-attributes-magento/

是否有遗漏或我遗漏的步骤?

如果我是对的,这个扩展程序会在页面刷新后运行?

【问题讨论】:

标签: php mysql magento


【解决方案1】:

尝试以下更改:

    <?xml version="1.0"?>
    <config>
      <modules>
         <Rnd_Customheader>
             <version>0.1.0</version>
         </Rnd_Customheader>
      </modules>
      <global>
        <resources>
    <customheader_setup>
      <setup>
           <module>Rnd_Customheader</module>
           <class>Mage_Catalog_Model_Resource_Eav_Mysql4_Setup</class>
      </setup>
      <connection>
        <use>default_setup</use>
      </connection>
  </customheader_setup>
</resources>  

Rnd_Customheader_setup 更改为 customheader_setup 并将目录重命名为 app/code/local/Rnd/Customheader/sql/customheader_setup

还要确保安装脚本名称应该是 mysql4-install-0.1.0.php,这里 0.1.0 是你的模块版本。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多