Magento:属性组作为产品选项卡
我想在产品页面中将不同的属性组显示为选项卡。例如,对于不同类型的产品,我有不同的属性集,但我希望根据产品类型,将属性组列为不同的选项卡 是否有现成的解决方案,或者我需要自己做 我的算法是:Magento:属性组作为产品选项卡,magento,magento-1.9,Magento,Magento 1.9,我想在产品页面中将不同的属性组显示为选项卡。例如,对于不同类型的产品,我有不同的属性集,但我希望根据产品类型,将属性组列为不同的选项卡 是否有现成的解决方案,或者我需要自己做 我的算法是: 从产品中检查属性集ID 收集特定属性集的属性组 检查attributeGroup是否列在我要显示的组数组中 将attributeGroupName写入tabName 从attributeGroup收集AttributeName 使用attributeName->attributeValue对填充选项卡体
- 从产品中检查属性集ID
- 收集特定属性集的属性组
- 检查attributeGroup是否列在我要显示的组数组中
- 将attributeGroupName写入tabName
- 从attributeGroup收集AttributeName
- 使用attributeName->attributeValue对填充选项卡体
//将此设置为您需要的任何值。
$AlloweGroupId=数组(1,2,3,4);
//获取所有组
$groups=Mage::getModel('eav/entity\u attribute\u group')
->getResourceCollection()
->setAttributeSetFilter($\u product->getAttributeSetId())
->setSortOrder()
->加载();
foreach($组作为$组){
//跳过你不需要的小组。
如果(!在数组中($group->getId(),$alloweGroups)){
继续;
}
回显'.$group->getId().-'.$group->getAttributeGroupName()';
//从组中获取属性
$attributes=Mage::getResourceModel('catalog/product\u attribute\u collection'))
->setAttributeGroupFilter($group->getId())
->addVisibleFilter()
->checkConfigurableProducts()
->加载();
如果($attributes->getSize()>0){
回声“”;
foreach($attributes->getItems()作为$attribute){
$attrCode=$attribute->getAttributeCode();
$attrValue=$\u产品->获取数据($attrCode);
回音“- ”;
如果(!是_数组($attrValue)){
回显$attrCode.'='.$attrValue;
}否则{
//如果属性值是数组,请执行某些操作。
}
回音“
”;
}
回声“
”;
}
}
//将此设置为您需要的任何值。
$AlloweGroupId=数组(1,2,3,4);
//获取所有组
$groups=Mage::getModel('eav/entity\u attribute\u group')
->getResourceCollection()
->setAttributeSetFilter($\u product->getAttributeSetId())
->setSortOrder()
->加载();
foreach($组作为$组){
//跳过你不需要的小组。
如果(!在数组中($group->getId(),$alloweGroups)){
继续;
}
回显'.$group->getId().-'.$group->getAttributeGroupName()';
//从组中获取属性
$attributes=Mage::getResourceModel('catalog/product\u attribute\u collection'))
->setAttributeGroupFilter($group->getId())
->addVisibleFilter()
->checkConfigurableProducts()
->加载();
如果($attributes->getSize()>0){
回声“”;
foreach($attributes->getItems()作为$attribute){
$attrCode=$attribute->getAttributeCode();
$attrValue=$\u产品->获取数据($attrCode);
回音“- ”;
如果(!是_数组($attrValue)){
回显$attrCode.'='.$attrValue;
}否则{
//如果属性值是数组,请执行某些操作。
}
回音“
”;
}
回声“
”;
}
}
HVALA!谢谢Zoki,我想我得到了几乎相同的解决方案。HVALA!谢谢Zoki,我想我得到了几乎相同的解决方案。
//Set this to whatever you need to.
$allowedGroupIds = array(1,2,3,4);
//Get all groups
$groups = Mage::getModel('eav/entity_attribute_group')
->getResourceCollection()
->setAttributeSetFilter($_product->getAttributeSetId())
->setSortOrder()
->load();
foreach ($groups as $group) {
//Skip the groups you don't need.
if (!in_array($group->getId(), $allowedGroups)) {
continue;
}
echo '<h3>'.$group->getId().' - '.$group->getAttributeGroupName().'</h3>';
//Get attributes from the group
$attributes = Mage::getResourceModel('catalog/product_attribute_collection')
->setAttributeGroupFilter($group->getId())
->addVisibleFilter()
->checkConfigurableProducts()
->load();
if ($attributes->getSize() > 0) {
echo '<ul>';
foreach ($attributes->getItems() as $attribute) {
$attrCode = $attribute->getAttributeCode();
$attrValue = $_product->getData($attrCode);
echo '<li>';
if (!is_array($attrValue)) {
echo $attrCode.' = '.$attrValue;
} else {
//Do something if the attribute value is array.
}
echo '</li>';
}
echo '</ul>';
}
}