1

我正在尝试将一个名为“website_url”的新文本字段添加到类别的字段列表中。

我找到了很多教程,但没有一个适用于 magento 1.7。

我创建了一个新模块,如下所示:

-code\local\SaponeWebConcept\CategoriesAttributes\sql\categoriesattributes_setup\mysql4-install-0.1.0.php

<?php
$installer = $this;
$installer->startSetup();

$installer->addAttribute('catalog_category', 'website_url', array(
    'type'              => 'text',
    'backend'           => '',
    'frontend'          => '',
    'label'             => 'Lien du site',
    'input'             => 'text',
    'class'             => '',
    'source'            => '',
    'global'            => 0,
    'visible'           => 1,
    'required'          => 0,
    'user_defined'      => 0,
    'default'           => '',
    'searchable'        => 0,
    'filterable'        => 0,
    'comparable'        => 0,
    'visible_on_front'  => 0,
    'unique'            => 0,
    'position'          => 1,
));

$installer->endSetup();

-code\local\SaponeWebConcept\CategoriesAttributes\etc\config.xml

<?xml version="1.0"?>
<config>
   <modules>
      <SaponeWebConcept_CategoriesAttributes>
         <version>0.1.0</version>
      </SaponeWebConcept_CategoriesAttributes>
   </modules>
   <global>
      <resources>
         <categoriesattributes_setup>
            <setup>
               <module>SaponeWebConcept_CategoriesAttributes</module>
               <class>Mage_Catalog_Model_Resource_Eav_Mysql4_Setup</class>
            </setup>
            <connection>
               <use>core_setup</use>
            </connection>
         </categoriesattributes_setup>
      </resources>
   </global>
</config>

我的模块由此正确激活:

<SaponeWebConcept_CategoriesAttributes>
    <active>true</active>
    <codePool>local</codePool>
</SaponeWebConcept_CategoriesAttributes>

但是当我访问我的类别编辑时,我没有看到任何新字段。我究竟做错了什么 ?如果缓存关闭,该模块应该立即工作,对吗?提前致谢。

4

2 回答 2

1

我遇到过同样的问题。这就是我解决它的方法:

app/code/local/yourmodulename/sql/yourcustomattribute_setup/mysql4-upgrade-0.0.9-0.1.3.php

<?php
$installer = $this;
$installer->startSetup();


$installer->addAttribute("catalog_category", "your_attribute",  array(
    "type"     => "varchar",
    "backend"  => "",
    "frontend" => true,
    "label"    => "Your Attribute",
    "input"    => "text",
    "class"    => "",
    "source"   => "",
    "global"   => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
    "visible"  => true,
    "required" => false,
    "user_defined"  => false,
    "default" => "",
    "searchable" => false,
    "filterable" => false,
    "comparable" => false,

    "visible_on_front"  => true,
    "unique"     => true,
    "note"       => ""

    ));
$installer->endSetup();

app/code/local/yourmodulename/etc/config.xml

<config>
  <modules>
    <Yournamespace_Yourmodulename>
      <version>0.1.3</version>
    </Yournamespace_Yourmodulename>
  </modules>
  <frontend>
    <routers>
      <yourmodulename>
        <use>standard</use>
          <args>
            <module>Yournamespace_Yourmodulename</module>
            <frontName>categoryattribute</frontName>
          </args>
      </yourmodulename>
    </routers>
        <category>
        <collection>
            <attributes>
                <yourmodulename />
            </attributes>
        </collection>
    </category>
        <layout>
          <updates>
            <yourmodulename>
              <file>categoryattribute.xml</file>
            </yourmodulename>
          </updates>
        </layout>
  </frontend>
  <global>
    <helpers>
      <yourmodulename>
        <class>Yournamespace_Yourmodulename_Helper</class>
      </yourmodulename>
    </helpers>
    <blocks>
      <yourmodulename>
        <class>Yournamespace_Yourmodulename_Block</class>
      </yourmodulename>
    </blocks>
    <models>
      <yourmodulename>
        <class>Yournamespace_Yourmodulename_Model</class>
        <resourceModel>categoryattribute_mysql4</resourceModel>
      </yourmodulename>
    </models>
    <resources>
      <yourmodulenamee_setup>
        <setup>
          <module>Yournamespace_Yourmodulename</module>
          <class>Mage_Catalog_Model_Resource_Eav_Mysql4_Setup</class>
        </setup>
        <connection>
          <use>core_setup</use>
        </connection>
      </yourmodulename_setup>
      <yourmodulename_write>
        <connection>
          <use>core_write</use>
        </connection>
      </yourmodulename_write>
      <yourmodulename_read>
        <connection>
          <use>core_read</use>
        </connection>
      </yourmodulename_read>
    </resources>
  </global>
</config> 

应用程序/etc/modules/Your_modulename.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Yournamespace_Yourmodulename>
      <active>true</active>
      <codePool>local</codePool>
      <version>0.1.3</version>
    </Yournamespace_Yourmodulename>
  </modules>
</config>

检查您的数据库以查看是否已在“Eav Attribute”下安装了 sql

您的自定义类别属性现在应该显示在前端!!!!

现在您需要做的就是在前端显示属性:

<?php echo $_product->getYourattributeid(); ?>
于 2013-01-18T19:05:53.167 回答
0

对于那些有这类问题的人,我在 MAGENTO 1.8 中的解决方案只确保设置了 VERSION 标签。

<config>
    <modules>
        <Yournamespace_Yourmodulename>
            <active>true</active>
            <codePool>local</codePool>
            <version>0.0.1</version>
        </Yournamespace_Yourmodulename>
    </modules>
</config>
于 2014-07-29T10:45:13.360 回答