我尝试在类别页面上显示产品属性值和属性标签(属性标签="可用颜色"属性代码=' available_colours')特定属性集(id = 9)。
我目前正在使用以下代码来显示属性值,但似乎无法显示属性标签。
<?php
if (9 == $_product->getAttributeSetId()) {
echo $_product->getAvailableColours()
}
?>
有什么建议吗?
答案 0 :(得分:0)
以下应该有所帮助:
<?php
$attributeSetId = 9;
if ($attributeSetId == $_product->getAttributeSetId()) {
echo $this->__('Available Colours') . "=" . $_product->getAvailableColours();
}
?>
如果您想打印多个属性,可以尝试下面的代码:
<?php
$attributeSetId = 9;
if ($attributeSetId == $_product->getAttributeSetId()) {
$productData = $_product->getData();
foreach($productData as $attributeCode=>$attributeValue) {
echo $attributeCode . "=" . $attributeValue; //You can do needed customization to check if attribute value is array then there will be a second loop here.
}
}
?>
此外,最好不要使用静态ID,因为它可能随服务器而改变。
使用以下代码,您将能够从属性集名称
动态加载属性集ID<?php
$attributeSetName = "default"; // put your own attribute set name $attribute_set =
Mage::getModel("eav/entity_attribute_set")->getCollection();
$attribute_set->addFieldToFilter("attribute_set_name",$attributeSetName)->getFirstItem();
$attributeSetId = $attribute_set->getAttributeSetId(); //In your case you will get 9
?>