且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Magento:如何在 PHP 中访问自定义变量?

更新时间:2023-11-14 16:19:46

这样做已经有一段时间了,以创建可通过管理界面编辑的各种消息,因此我不必在当下流行时去挖掘代码变化.

Been doing this for some time to create various messages that are editable through the admin interface so I don't have to go code digging when the flavor of the moment changes.

要使用代码custom_variable_code访问自定义变量的普通值,请使用:

To access the plain value of the custom variable with code custom_variable_code use this:

Mage::getModel('core/variable')->loadByCode('custom_variable_code')->getValue('plain');

注意:单个商店不显示变量范围的商店选择下拉列表.这个答案在技术上是不正确的,为了在拥有多家商店的情况下证明自己的未来 -> 请参阅下面的@Mark van der Sanden 回答并给他一个赞.

NOTE: Single store doesn't show the store select dropdown for the variable scope. This answer is not technically correct, in order to future-proof yourself in case of having multiple stores --> Please see @Mark van der Sanden answer below and give him an upvote.