magento 通过属性组获取产品属性值
public function getAttribueByGroup($mediaProduct){
$setId = $mediaProduct->getAttributeSetId(); // Attribute set Id
$groups = Mage::getModel('eav/entity_attribute_group')
->getResourceCollection()
->setAttributeSetFilter($setId)
->setSortOrder()
->load();
$attributeCodes = array();
foreach ($groups as $group) {
if($group->getAttributeGroupName() == 'VIDEOS'){//属性值名称
$attributes = Mage::getResourceModel('catalog/product_attribute_collection')
->setAttributeGroupFilter($group->getId())
->addVisibleFilter()
->checkConfigurableProducts()
->load();
if ($attributes->getSize() > 0) {
foreach ($attributes->getItems() as $attribute) {
/* @var $child Mage_Eav_Model_Entity_Attribute */
$attributeCodes[] = $attribute->getAttributeCode();
}
}
}
}
return $attributeCodes;
}
模板调用,比如产品详情页面product view
<?php $videoIds =$this->getAttribueByGroup($_product); ?>
<?php if ($videoIds): ?>
<?php foreach ($videoIds as $key=>$val): ?>
<?php $array=explode('_',$val);?>
<?php if($array[2]=='id'): ?>
<?php echo $videosimple=$_product->getResource()->getAttribute($val)->getFrontend()->getValue($_product);?>
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
(责任编辑:好模板) |