在magento中获取所有产品属性的数组 [英] get an array of all a products attributes in magento
问题描述
我无法弄清楚!
我正在尝试将产品属性列表放入list.phtml页面上的数组中.我已经尝试了一切.我已经看到很多使用
I am trying to get a list of a products attributes into an array on the list.phtml page. I have tried everything. I have seen a lot of solutions that use
$attributes = $product->getAttributes();
但是我无法使它正常工作,它只是显示一个空白页.任何帮助将不胜感激,到目前为止,我已经花了数小时的时间...
but I cannot get this to work, it just brings up a blank page. Any help would be greatly appreciated, I have spent hours and hours on this so far...
我正在使用Magento 1.4.2.0版
I am using Magento version 1.4.2.0
更新:这正是我要执行的操作:
UPDATE: Here is exactly what I am trying to do:
$neededAttributes = Mage::helper('mymodule')->getNeededAttributes();
$attributes = $product->getAttributes();
foreach ($attributes as $attribute) {
if(in_array($attribute->getAttributeCode(), $neededAttributes)) {
$attributename = $attribute->getAttributeCode();
echo $attributename;
}
}
这位于文件文件gallery.phtml中,位于design/adminhtml/default/default/catalog/product/helper/
this is in the file gallery.phtml in design/adminhtml/default/default/catalog/product/helper/
由于某种原因,我无法获得getAttributeCode函数以返回任何内容.
For some reason, I cannot get the getAttributeCode function to return anything.
推荐答案
我猜测您只需要一个可见值列表.我说值"是因为属性不是实际值,它们是描述符.以下是Mage_Mage_Catalog_Block_Product_View_Attributes
中的重要部分:
I'm guessing you need a list of only visible values. I say "values" because attributes are not the actual values, they are descriptors. The following is the salient parts from Mage_Mage_Catalog_Block_Product_View_Attributes
:
$attributes = $product->getAttributes();
foreach ($attributes as $attribute) {
if ($attribute->getIsVisibleOnFront()) {
$value = $attribute->getFrontend()->getValue($product);
// do something with $value here
}
}
尽管您可以更改/使用已在产品视图页面上声明为attributes
块的模板catalog/product/view/attributes.phtml
,但是您实际上并不需要重复此操作.
You don't really need to duplicate this though since you can alter/use the template catalog/product/view/attributes.phtml
which is already declared on the product view page as attributes
block.
这篇关于在magento中获取所有产品属性的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!