我正在尝试在我的产品类别的网格/列表视图中显示补充信息(请参阅示例页面(http://marsden.robertobertuol.com/index.php/industrial-scales/bench-scales.html?mode=grid)。我设法打印出如下的元标题:
echo $_product->getMetaTitle();
但我也想打印出另一个属性,即"容量"。有人能给我指正确的方向吗?感谢
如果属性是文本,则使用如下
echo $_product->getCapacity();
如果属性是下拉的
$capacity_id = $_product->getData('capacity');
$productModel = Mage::getModel('catalog/product');
$attr = $productModel->getResource()->getAttribute('capacity'); if ($attr->usesSource()) {
echo $capacity_text = $attr->getSource()->getOptionText($capacity_id);
}
如果属性是多选
$attr = $productModel->getResource()->getAttribute("capacity");
$exploded = explode(',',$productModel->getCapacity());
foreach ($exploded as $key => $value) {
if ($attr->usesSource()) {
$capacity_title[] = $attr->getSource()->getOptionText($value);
}
}
print_r($capacity_title);
我找到了没有打印该值的原因。
为了使该属性在其他页面(产品页面除外)上可用,在后端,设置"product Listing"应设置为"Yes"。在这种情况下,可以使用打印属性的值("容量")
echo $_product->getCapacity();