2015-10-09 39 views
1

我想在產品頁面中將不同的屬性組顯示爲選項卡。例如,對於不同類型的產品,我擁有不同的屬性集,但是我希望根據產品的類型將列表屬性組列爲不同的選項卡。Magento:屬性組作爲產品選項卡

是否有任何開箱即用的解決方案,或者我需要自己做?

我的算法是:從產品

  • 檢查屬性集中的ID,如果attributeGroup在我想表明
  • 寫attributeGroupName作爲TABNAME
  • 組陣列列
  • 特定屬性集中
  • 檢查的收集attributeGroups
  • 從屬性組收集屬性名稱
  • 使用attr填充tabBody ibuteName - > attributeValue對

任何提示和幫助歡迎您! 謝謝

回答

0

//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>'; 
    } 
} 
+0

HVALA!謝謝Zoki,我想我得到幾乎相同的解決方案。 –

+0

Isidor :)沒問題 – zokibtmkd