将自定义属性添加到magento属性并显示在前端 [英] Add custom property to magento Attributes and display it on the front end

查看:132
本文介绍了将自定义属性添加到magento属性并显示在前端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始使用magento作为我的电子商务cms,我知道这是一个非常强大的平台. 最近,我遇到了它的功能,该功能可以帮助开发人员扩展核心,并且我设法添加了自定义类别选项. 有机会在属性上获得相同的结果吗? 我想在属性的选项卡上添加文本描述,并在前端显示它吗?

I have started using magento as my ecommerce cms and I know that is an extremely powerful platform. Recently I came across its functionality that helps the developer extending the core and I have managed to add custom category options. Is there any chance to achieve the same results on an attribute? I would like to add a text description on the properties' tab and display it on the front end?

推荐答案

这可以通过编写自己的自定义模块来实现.我这样做是为了向属性添加一个工具提示选项.

This is possible with writing your own custom module. I did it to add a tooltip-option to an attribute.

您可以使用adminhtml_catalog_product_attribute_edit_prepare_form事件向观察者添加字段:

You can use the adminhtml_catalog_product_attribute_edit_prepare_form-event to add a field with your observer:

$fieldset = $observer->getForm()->getElement('base_fieldset');
$fieldset->addField('tooltip', 'text', array(
    'name' => 'tooltip',
    'label' => Mage::helper('catalog')->__('Tooltip'),
    'title' => Mage::helper('catalog')->__('Tooltip')
));

这会将额外的字段添加到属性编辑屏幕.下一步是确保在编辑属性时保存属性.可以在安装程序脚本中完成以下操作:

This adds the extra field to the attribute-edit screen. Next up is to make sure the property gets saved when editing your attribute. This can be done in your installer script with something like:

$installer->getConnection()->addColumn(
    $installer->getTable('catalog/eav_attribute'),
    'tooltip',
    array(
        'type'      => Varien_Db_Ddl_Table::TYPE_TEXT,
        'nullable'  => true,
        'comment'   => 'Tooltip'
    )
);

还必须确保您的Model/Resource/Setup类扩展了Mage_Eav_Model_Entity_Setup而不是Mage_Core_Model_Resource_Setup.

You also have to make sure your Model/Resource/Setup-class extends Mage_Eav_Model_Entity_Setup instead of Mage_Core_Model_Resource_Setup.

现在,您现在可以保存自定义属性属性.下一步是将其显示在前端.只需使用简单的Magento模板101,即可相当轻松地完成此操作:

Now, at this point, you can save your custom attribute property. Next step is to display it on the frontend. This can be done fairly easy, just by simple Magento templating 101:

例如,在foreach()循环的catalog/product/view/type/options/configurable.phtml中,放置如下所示的内容,以显示工具提示:

For example, in catalog/product/view/type/options/configurable.phtml in the foreach()-loop, place something like this, to display the tooltip:

echo $_attribute->getProductAttribute()->getTooltip();

很好...

更新:由于我通过电子邮件收到有关此主题的一些问题,因此,我决定撰写有关此主题的更详细的博客文章.您可以在此处阅读: http://gielberkers.com/add-custom-properties- magento属性/

Update: Since I got some questions about this subject by e-mail, I decided to write a more detailed blog post about it. You can read it here: http://gielberkers.com/add-custom-properties-magento-attributes/

这篇关于将自定义属性添加到magento属性并显示在前端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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