2014-07-14 40 views
0

我想在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值前端。 如果有人知道這一點,那麼請幫助我。 謝謝!

+0

爲什麼不使用類別的默認描述字段? –

+0

您是否在productlisting.phtml頁面中獲得當前類別? –

+0

不,它不是來 –

回答

1

沒有需要所有上述的東西哥們。只需放置這兩個文件。

在下面的路徑創建一個mysql4-install-1.0.0.php。 將下面的代碼在其以下路徑:

/app/code/local/Test/Customcatattrb/sql/customcatattrb_setup

<?php 
$installer = $this; 
$installer->startSetup(); 
$attribute = array(
    'type' => 'text', 
    'label'=> 'Deal name', 
    'input' => 'textarea', 
    'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, 
    'visible' => true, 
    'required' => false, 
    'user_defined' => true, 
    'default' => "", 
    'group' => "General Information" 
); 
$installer->addAttribute('catalog_category', 'deal_name', $attribute); 
$installer->endSetup(); 

以下路徑創建config.xml中 的/ opt/LAMPP/htdocs中/ Magento的/應用/代碼/本地/測試/ Customcatattrb /等

<?xml version="1.0"?> 
<config> 
    <modules> 
    <Test_Customcatattrb> 
     <version>1.0.0</version> 
    </Test_Customcatattrb> 
    </modules> 
    <global> 
     <resources> 
      <customcatattrb_setup> 
      <setup> 
       <module>Test_Customcatattrb</module> 
       <class>Mage_Eav_Model_Entity_Setup</class> 
      </setup> 
      <connection> 
       <use>default_setup</use> 
      </connection> 
      </customcatattrb_setup> 
     </resources> 
    </global> 
</config> 

我想大家都知道的Test_Customcatattrb.xml應用程序/ etc/modules。現在只需轉到管理員並檢查。在通用信息塊中會有一個以「交易名稱」命名的新字段。

相關問題