Magento的1.7添加属性类别 [英] Magento 1.7 Add attribute to category

查看:138
本文介绍了Magento的1.7添加属性类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加到类别字段列表中的新文本字段名为WEBSITE_URL。

I'm trying to add to the field list of the categories a new text field called "website_url".

我发现很多教程,但没有工作在Magento的1.7。

I found many tutorials but none works on magento 1.7.

我创建了一个新的模块如下:

I created a new module as following :

-$c$c\\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 \\本地\\ SaponeWebConcept \\ CategoriesAttributes \\等\\ 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>

和我的模块是否正确这个激活:

And my module is correctly activated by this :

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

但是,当我进入我的类别编辑,我没有看到任何新的领域。
我究竟做错了什么?该模块应该立刻工作,如果缓存是关闭的,对不对?
先谢谢了。

But when I access my category editing, I don't see any new field. What am I doing wrong ? The module is supposed to work immediatly if the cache is off, right ? Thanks in advance.

推荐答案

我有同样的问题。这是我如何解决它:

I had the same issue. This is how I solved it:

应用程序/ code /本地/ yourmodulename / SQL / yourcustomattribute_setup / mysql4升级-0.0.9-0.1.3.php

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();

应用程序/ code /本地/ yourmodulename的/ etc / config.xml中

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 /模块/ Your_modulename.xml

app/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>

检查你的数据库,看看如果SQL已根据杨仁属性

Check you database to see if the sql has been installed under "Eav Attribute"

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

You custom category attribute should now be showing in the frontend!!!!

现在,所有你需要做的是显示在该属性的使用frontened:

Now all you need to do is show the attribute on the frontened using:

<?php echo $_product->getYourattributeid(); ?>

这篇关于Magento的1.7添加属性类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆