Moo*_*oon 30 attributes magento
我想在Magento产品视图模板中获取属性集名称.我可以获取属性值$_product->getAttributeText('attribute')
,但是如何获取属性集名称?
我想仅在属于某个属性集时才显示属性.
Jos*_*tey 71
只要有产品对象,就可以像这样访问其属性集:
$attributeSetModel = Mage::getModel("eav/entity_attribute_set");
$attributeSetModel->load($product->getAttributeSetId());
$attributeSetName = $attributeSetModel->getAttributeSetName();
Run Code Online (Sandbox Code Playgroud)
这将为您提供属性集的名称,然后您可以使用strcmp进行比较:
if(0 == strcmp($attributeSetName, 'My Attribute Set')) {
print $product->getAttributeText('attribute');
}
Run Code Online (Sandbox Code Playgroud)
希望有所帮助!
小智 25
为了更加性感,您可以将其缩短为:
$attributeSetName = Mage::getModel('eav/entity_attribute_set')->load($_product->getAttributeSetId())->getAttributeSetName();
Run Code Online (Sandbox Code Playgroud)
Mag*_*cho 13
请尝试以下代码:
$entityTypeId = Mage::getModel('eav/entity')
->setType('catalog_product')
->getTypeId();
$attributeSetName = 'Default';
$attributeSetId = Mage::getModel('eav/entity_attribute_set')
->getCollection()
->setEntityTypeFilter($entityTypeId)
->addFieldToFilter('attribute_set_name', $attributeSetName)
->getFirstItem()
->getAttributeSetId();
echo $attributeSetId;
Run Code Online (Sandbox Code Playgroud)
在下面的文章中查找有关属性集的更多信息.
谢谢