0

好的,我试图在我的商店页面的左栏中显示自定义 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 上的几篇文章),这应该允许我访问该类别中我漂亮的新自定义属性,但我就是无法让它工作。必须有一种方法可以简单地访问这个值……当然。

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

配置.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-install-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 定制相对较新,我必须承认已经从另一个来源改编了模块代码,但它似乎运行良好......

有任何想法吗??

4

1 回答 1

0

在左侧布局 left_col.phtml 上添加功能

 function addAttribute($code)

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

return $this;

}

用于在左侧布局中显示自定义属性的值 left_col.phtml

echo $_product->getResource()->getAttribute('author_name')->getFrontend()->getValue($_product) 
于 2013-06-14T06:33:04.210 回答