All Addtional Attributes for Grouped Products in Magento

喜夏-厌秋 提交于 2019-12-04 11:42:50

The class Mage_Catalog_Block_Product_View_Attributes method getAdditionalData() should point you toward how to limit the variables to only those that are selected as Viewable on Frontend. Its getAdditionalData method is referenced in the product view block.

The steps to solving this would be the following: 1. Create a new Magento module with the intent to override the grouped product block. 2. Create the new grouped product block, stealing liberally from the getAdditionalData() method of Mage_Catalog_Block_Product_View_Attributes. 3. Create a new template based on /template/catalog/product/view/type/grouped.phtml to back your custom block. 4. Override the block in your module's config.xml (see: Overriding catalog/breadcrumbs and catalog/products/view, Magento forums)

This has the consequence that all your grouped products in the catalog will behave this way. If you need to be more selective, then I think a reasonable thing to do would be to add a custom attribute to catalog products (preferably set up in the custom module you just created!) in order to toggle the behavior, and program a check for that toggle into your template.

Ortega

Add after $_product = $this->getProduct();

/* CODE TO GET ATTRIBUTES */
$gridattributes = array();
$attributes = $_product->getAttributes();
foreach ($attributes as $attribute) {
  if ($attribute->getIsVisibleOnFront() && !in_array($attribute->getAttributeCode(), $excludeAttr)) {
    $value = $attribute->getFrontend()->getValue($_product);
    if (!$_product->hasData($attribute->getAttributeCode())) {
      $value = Mage::helper('catalog')->__('N/A');
    } elseif ((string)$value == '') {
      $value = Mage::helper('catalog')->__('No');
    } elseif ($attribute->getFrontendInput() == 'price' && is_string($value)) {
      $value = Mage::app()->getStore()->convertPrice($value, true);
    }

    if (is_string($value) && strlen($value)) {
      $gridattributes[$attribute->getAttributeCode()] = array(
        'label' => $attribute->getStoreLabel(),
        'value' => $value,
        'code'  => $attribute->getAttributeCode()
      );
    }
  }
}
?>

Add after <th><?php echo $this->__('Product Name') ?></th>:

foreach($gridattributes as $attrib){
    echo '<th>'.$this->htmlEscape($attrib[label]).'</th>';
}

Add after <td><?php echo $this->htmlEscape($_item->getName()) ?></td>:

foreach($gridattributes as $attribname=>$attribval){
    echo '<td>'.$this->htmlEscape($_item->getData($attribname)).'</td>';
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!