如果产品属于某个属性集,我希望在产品页面上显示一个静态块
例如,如果我是一家时装商店,并且我有一个“鞋类”属性集,那么我只希望当该属性集与“鞋类”匹配时,静态块才会显示在产品页面上
我发现了一些输出Attribute set ID的代码,但我想将其转换为else if语句。
<?php
$entityTypeId = Mage::getModel('eav/entity')
->setType('catalog_product')
->getTypeId();
$attributeSetName = 'Footwear';
$attributeSetId = Mage::getModel('eav/entity_attribute_set')
->getCollection()
->setEntityTypeFilter($entityTypeId)
->addFieldToFilter('attribute_set_name', $attributeSetName)
->getFirstItem()
->getAttributeSetId();
echo $attributeSetId;
?>
谁有想法?
G
最佳答案
将此方法添加到Product View Block
(当然不是核心文件app/code/core/Mage/Catalog/Block/Product/View.php
):
public function checkAttributeSet($product = null, $attributeSetName = null)
{
if(is_null($product) || is_null($attributeSetName))
return false;
$attributeSetModel = Mage::getModel("eav/entity_attribute_set");
$attributeSetModel->load($product->getAttributeSetId());
if($attributeSetModel->getAttributeSetName() == $attributeSetName) {
return true;
} else {
return false;
}
}
然后在
app/design/frontend/package/theme/template/catalog/product/view.phtml
中:if($this->checkAttributeSet($_product, 'Monitors')):
echo $this->getLayout()->createBlock('cms/block')->setBlockId('monitor')->toHtml();
elseif($this->checkAttributeSet($_product, 'Footwear')):
echo $this->getLayout()->createBlock('cms/block')->setBlockId('footwear')->toHtml();
endif;
关于magento - Magento:基于产品属性集显示html元素?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15109556/