0
点赞
收藏
分享

微信扫一扫

magento 获取产品的属性值

陬者 2023-04-03 阅读 55


magento采用强大的EAV设计方法,我们可以很方便的给商品添加任意数量的属性,那如何在前台获取这些属性值呢?

 

magento同样提供了很方便的方式来读取它。使用$_product->getAttributeName ()或者$_product['AttributeName' ]就可以获得指定名字属性的值,以颜色属性color为例,可以这样写   $_product->getColor ()  or  $_product['color'

$_product->getResource()->getAttribute('AttributeName')->getFrontend()->getValue($_product)

同样以颜色为例:

$_product->getResource()->getAttribute('color')->getFrontend()->getValue($_product)

 

 

或者可以使用:

$_product->getAttributeText('attribute_code');  // string or array

 

 

举报

相关推荐

0 条评论