获取magento中所有产品属性的数组
我无法弄清楚这一点!
我正在尝试将产品属性列表放入 list.phtml 页面上的数组中。我已经尝试了一切。我见过很多使用的解决方案
$attributes = $product->getAttributes();
,但我无法使其工作,它只会显示一个空白页面。任何帮助将不胜感激,到目前为止我已经花了很多时间...
我正在使用 Magento 版本 1.4.2.0
更新:这正是我想要做的:
$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 中/adminhtml/default/default/catalog/product/helper/
由于某种原因,我无法让 getAttributeCode 函数返回任何内容。
I cannot figure this out!
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...
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;
}
}
this is in the file gallery.phtml in design/adminhtml/default/default/catalog/product/helper/
For some reason, I cannot get the getAttributeCode function to return anything.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我猜你需要一个仅可见值的列表。我说“值”是因为属性不是实际值,它们是描述符。以下是
Mage_Mage_Catalog_Block_Product_View_Attributes
的重要部分:不过,您实际上不需要重复此内容,因为您可以更改/使用模板
catalog/product/view/attributes.phtml
它已在产品视图页面上声明为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
: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 asattributes
block.根据您的问题,您应该改用
Mage::getResourceModel('catalog/product_attribute_collection')
:您并不总是在
_data
中具有属性 (getData()
) 存储,您并不总是需要加载产品来获取其属性。According to your question, you should be using
Mage::getResourceModel('catalog/product_attribute_collection')
instead:You don't always have attributes in the
_data
(getData()
) storage and you don't always need to load a product to get its attributes.它相当简单,并为您提供了一组可用的产品属性名称
如果您需要一个属性对象集合,您可以调用
如果您需要一个产品集合,然后您可以对每个集合成员执行前面提到的方法
It's rather easy and gives you an array of available product attribute names
If you need a attribute object collection you can call
If you need a product collection and after that you can perform the previously mentioned ways on each collection member