【发布时间】:2016-08-20 04:37:15
【问题描述】:
我在 magento 中有一个自定义函数,如何在前端查看公共函数值?
功能:
public function getOptionsWithValues()
{
$attributes = $item->getOptionByCode('attributes')->getValue();
if (!$attributes)
{
return null;
}
$attributes = unserialize($attributes);
$options = array();
foreach ($attributes as $attr_id => $attr_value)
{
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', $attr_id);
$attr_options = $attribute->getSource()->getAllOptions(false);
foreach ($attr_options as $option)
{
if ($option['value'] == $attr_value)
{
$options[$attribute->getFrontendLabel()] = $option['label'];
}
}
}
return $options;
}
谢谢
【问题讨论】:
-
您可以在模块的 Helper 类中拥有此代码。然后你可以这样称呼它:
Mage::helper("helpername")->getOptionsWithValues(); -
我在核心愿望清单中添加了这个,/app/code/core/Mage/Wishlist/Model/Item/Option.php 我想在前端显示属性值
-
不要将代码破解到核心文件中。创建一个模块,将上面的代码插入到
Data.php(这是您模块的帮助程序类)中,然后在前端任何您想要的地方调用它,就像我在第一条评论中向您展示的那样。 -
别担心这不是问题,我只想告诉我你是否知道如何在前端显示 $option['label']
-
echo $options["attribute_name"]?
标签: php magento magento-1.7 magento-1.9 magento-1.8