2013-04-30 36 views
0

好吧,我试图在我的商店页面左侧列中的顶部显示自定义Magento类别属性的内容。获取Magento自定义类别属性在左侧列中的值

我编辑2columns-left.phtm,并插入以下内容:

$_category = Mage::getModel('catalog/category')->load($category->getId()); 
echo $_helper->categoryAttribute($_category, $_category->getName(), 'name'); 

这之前

<?php echo $this->getChildHtml('left') ?> 

立即插入现在,任何人都指出了明显之前,是的,我知道这代码使用预先存在的属性“名称”,但我非常疲惫和迷雾,我只用简单的例子来试图让它起作用。我的属性是category_desc - 这是通过我写的一个简单模块创建并成功存储的。通过在后端添加一个值来确认,保存类别然后刷新 - 输入的值被成功保存。

即使上面的例子也不行 - 它只是呈现一个完全空白的左列。我也尝试过无数变化,我已经发现了这个和其他代码(包括SO上的几个帖子),它应该允许我访问该类别中的新的自定义属性,但是我无法使其工作。肯定有一种方法可以简单地访问这个值。

我是meng Magento 1.7。在模块中用于创建自定义属性的代码如下:

config.xml中:

<?xml version="1.0"?> 
<config> 
<modules> 
    <SS_CustomCategoryAttribute> 
     <version>0.0.1</version> 
    </SS_CustomCategoryAttribute> 
</modules> 

<global> 
    <resources> 
     <add_category_attribute> 
      <setup> 
       <module>SS_CustomCategoryAttribute</module> 
       <class>Mage_Catalog_Model_Resource_Eav_Mysql4_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> 

mysql4安装-0.0.1.php:

<?php 
$this->startSetup(); 
$this->addAttribute('catalog_category', 'category_desc', array(
'group'   => 'General', 
'input'   => 'textarea', 
'type'   => 'text', 
'label'   => 'Category Description', 
'backend'  => '', 
'visible'  => true, 
'required'  => false, 
'wysiwyg_enabled' => true, 
'visible_on_front' => true, 
'is_html_allowed_on_front' => true, 
'global'  => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, 
)); 

$this->endSetup(); 

SS_CustomCatgoryAttribute.xml:

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

如果它不是很明显,我对这个级别的Magento定制相对比较陌生,我必须承认已经改编了来自其他来源的模块代码,但它似乎工作得很好...

任何想法? left_col.phtml

function addAttribute($code) 

{ 
    $this->_getProductCollection()->addAttributeToSelect($code); 

return $this; 

} 

左布局

回答

0

添加功能对于左布局left_col.phtml

echo $_product->getResource()->getAttribute('author_name')->getFrontend()->getValue($_product) 
显示自定义属性的值
相关问题