Magento 只读和隐藏的产品属性 [英] Magento read-only and hidden product attributes

查看:27
本文介绍了Magento 只读和隐藏的产品属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望拥有一些无法从管理界面编辑的 Magento 产品属性,以及一些在该界面中根本不可见的属性(作为一种存储有关产品的一些不应该被人类查看的持久信息的方法用户..这是我能想到的唯一方法,欢迎任何其他建议.

I would like to have some Magento product attributes that are not editable from the admin interface and some that are not visible at all in that interface (as a method of storing some persistent information about a product that should not be viewed by human users.. it's the only way of doing this that i can think of, any other suggestions are welcome).

所以我的问题是:是否所有 Magento 属性都必须在管理界面中可见和可编辑?如果不是,如何将它们设为只读或隐藏?

So my question is: Do all Magento attributes have to be visible and editable from the admin interface? If not, how can they be made read-only or hidden?

我注意到在管理界面中有一些只读字段,因此必须可以以一种或另一种方式执行此操作.在为此搜索 stackoverflow 后,我找到了一个可能涉及 JavaScript 的解决方案,但如果可能的话,我不想走这条路.

I noticed that in the admin interface there are some read-only fields, so it must be possible to do this one way or another. After searching stackoverflow for this I found a possible solution involving JavaScript, but I would like to not go down that path if it's at all possible.

推荐答案

好吧,看来终于可以了.在为 catalog_product_load_after 事件添加观察者之后,可以使用 Mage_Catalog_Model_Abstract 类的 lockAttribute 方法将产品属性设为只读.下面是观察者方法的代码:

OK, it looks like it can be done after all. After adding an observer for the catalog_product_load_after event, the lockAttribute method of the Mage_Catalog_Model_Abstract class may be used to make a product attribute read-only. Here is the code for the observer method:

public function lockAttributes($observer) {
    $event = $observer->getEvent();
    $product = $event->getProduct();
    $product->lockAttribute('attribute_code');
}

这篇关于Magento 只读和隐藏的产品属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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