All optional attributes for grouped products in Magento

Similar to the question asked : Magento - show user attributes in a table of grouped products

I would like to display simple product attributes on a grouped product page.

However, I need it to work so that it does not explicitly indicate which attributes will be displayed. Instead, it displays all the attributes that will be displayed on a simple product view of that product.

I tried the options:

(from / template / catalog / product / view / type / grouped.phtml)

<?php foreach ($_associatedProducts as $_item): ?>
  <tr>
            <td><?php echo $this->htmlEscape($_item->getName()) ?></td>

   <!-- important problem part -->
   <?php foreach ($_item->getAttributes() as $arr): ?>
    <td><?php echo $arr->getData() ?></td>
   <?php endforeach; ?>
   <!-- end of problem part -->

            <td class="a-right">
                <?php echo $this->getPriceHtml($_item, true) ?>
            </td>
            <?php if ($_product->isSaleable()): ?>
            <td class="a-center">
            <?php if ($_item->isSaleable()) : ?>
    <a href="<?php echo $_item->getUrlPath() ?>">View</a>
            <?php else: ?>
                <p class="availability"><span class="out-of-stock"><?php echo $this->__('Out of stock.') ?></span></p>
            <?php endif; ?>
            </td>
            <?php endif; ?>
        </tr>
    <?php endforeach; ?>

, , , (.. , , , " Frontend" ). ?

+3
2

Mage_Catalog_Block_Product_View_Attributes getAdditionalData() , , Frontend. getAdditionalData .

:  1. Magento .  2. , getAdditionalData() Mage_Catalog_Block_Product_View_Attributes.  3. /template/catalog/product/view/type/grouped.phtml, .  4. config.xml(. / //, Magento)

, . , , ( , !), .

+1

$_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()
      );
    }
  }
}
?>

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

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

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

foreach($gridattributes as $attribname=>$attribval){
    echo '<td>'.$this->htmlEscape($_item->getData($attribname)).'</td>';
}
+1

Source: https://habr.com/ru/post/1726756/


All Articles