【问题标题】:Magento: How do I list the values of a product's attribute set?Magento:如何列出产品属性集的值?
【发布时间】:2013-08-02 21:55:10
【问题描述】:

在 Magento(1.6 社区版)中,我如何找到产品属性集的值?

例如,有一个产品具有名为 T 恤的属性集,具有性别、衬衫尺寸和颜色等属性。从 $_product 对象开始,我如何找到属性的值,例如男士、绿色、大号?

【问题讨论】:

  • 您可以尝试下拉属性$_product->getAttributeText('attributename') 或简单属性,例如$_product->getAttributeName()
  • 这可行,但需要提前知道属性名称:$_product->getResource()->getAttribute('gender')->getFrontend()->getValue($_product));
  • 如何遍历属性集以获取它们的所有值?

标签: magento attributes product


【解决方案1】:

你可以试试这样的:

$attributes = Mage::getModel('catalog/product_attribute_api')->items($_product->getAttributeSetId());
foreach($attributes as $_attribute){
    var_dump($_product->getData($_attribute['code']));
}

【讨论】:

  • 而不是属性集的值,这仅获取“模型”字段的值。属性集的范围是全局的,所以我不确定为什么会这样。
  • 我明白你的意思,请查看修改后的答案
  • 这个答案没有产生预期的结果。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多