我想在admin的管理類別中添加一個簡短的描述字段,並且希望在前端顯示描述值。我試過但無法做到這一點。 我增加了自定義屬性app/etc/modules/Atwix_CustomCategoryAttribute.xml
如何使用magento在管理類別中添加簡短描述字段?
<?xml version="1.0"?>
<config>
<modules>
<Atwix_CustomCategoryAttribute>
<active>true</active>
<codePool>community</codePool>
</Atwix_CustomCategoryAttribute>
</modules>
</config>
然後在app/code/community/Atwix/CustomCategoryAttribute/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Atwix_CustomCategoryAttribute>
<version>0.0.1</version>
</Atwix_CustomCategoryAttribute>
</modules>
<global>
<resources>
<add_category_attribute>
<setup>
<module>Atwix_CustomCategoryAttribute</module>
<class>Mage_Catalog_Model_Resource_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</add_category_attribute>
<add_category_attribute_write>
<connection>
<use>core_write</use>
</connection>
</add_category_attribute_write>
<add_category_attribute_read>
<connection>
<use>core_read</use>
</connection>
</add_category_attribute_read>
</resources>
</global>
</config>
然後在app/code/community/Atwix/CustomCategoryAttribute/sql/add_category_attribute/mysql4-install-0.0.1.php
<?php
$this->startSetup();
$this->addAttribute(Mage_Catalog_Model_Category::ENTITY, 'custom_attribute', array(
'group' => 'General',
'input' => 'textarea',
'type' => 'text',
'label' => 'Custom attribute',
'backend' => '',
'visible' => true,
'required' => false,
'visible_on_front' => true,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
$this->endSetup();
添加補充,這將在創建一個額外的字段管理類一般section.now我想顯示的價值
app/design/frontend/default/alpha/template/catalog/product/productlisting.phtml page
,所以我把這個代碼
<?php if($_customAttribute = $this->getCurrentCategory()->getCustomAttribute()): ?>
<?php echo $_helper->categoryAttribute($_category, $_customAttribute, 'custom_attribute') ?>
<?php endif; ?>
but it shows error
致命錯誤:調用一個成員函數getCustomAttribute()一個非對象
我不知道如何顯示在自定義attribut值前端。 如果有人知道這一點,那麼請幫助我。 謝謝!
爲什麼不使用類別的默認描述字段? –
您是否在productlisting.phtml頁面中獲得當前類別? –
不,它不是來 –