Magento中分组产品的所有附加属性

Magento中分组产品的所有附加属性,magento,attributes,product,Magento,Attributes,Product,类似于在以下会议上提出的问题: 我想在分组产品页面中显示简单产品的属性 但是,我需要它工作,这样您就不会显式地指定显示哪些属性。相反,它显示将在该产品的简单产品视图上显示的所有属性 我试过以下几种: (来自/template/catalog/product/view/type/grouped.phtml) 但是,我不能将显示的属性限制为我需要的属性(即,仅显示在简单产品视图上的附加属性;在前端设置为可查看的属性)。有什么想法吗?类Mage\u Catalog\u Block\u Prod

类似于在以下会议上提出的问题:

我想在分组产品页面中显示简单产品的属性

但是,我需要它工作,这样您就不会显式地指定显示哪些属性。相反,它显示将在该产品的简单产品视图上显示的所有属性

我试过以下几种:

(来自/template/catalog/product/view/type/grouped.phtml)



但是,我不能将显示的属性限制为我需要的属性(即,仅显示在简单产品视图上的附加属性;在前端设置为可查看的属性)。有什么想法吗?

类Mage\u Catalog\u Block\u Product\u View\u Attributes方法getAdditionalData()应该告诉您如何将变量限制为仅在前端可查看的变量。其getAdditionalData方法在产品视图块中引用

解决此问题的步骤如下: 1.创建新的Magento模块,以覆盖分组的产品块。 2.创建新的分组产品块,从Mage\u Catalog\u block\u product\u View\u属性的getAdditionalData()方法中自由窃取。 3.基于/template/catalog/product/view/type/grouped.phtml创建新模板以支持自定义块。 4.覆盖模块config.xml中的块(请参见:,Magento论坛)


这将导致目录中所有分组的产品都将以这种方式运行。如果您需要更具选择性,那么我认为一个合理的做法是向目录产品添加一个自定义属性(最好是在您刚刚创建的自定义模块中设置!),以便切换行为,并在模板中设置该切换的检查。

$\u product=$this->getProduct()之后添加

之后添加:

foreach($gridattributes作为$attrib){
echo'.$this->htmlEscape($attrib[label])。';
}
之后添加:

foreach($gridattributes作为$attribname=>$attribval){
回显“”。$this->htmlEscape($_item->getData($attribname))。';
}
<?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; ?>
/* 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()
      );
    }
  }
}
?>
foreach($gridattributes as $attrib){
    echo '<th>'.$this->htmlEscape($attrib[label]).'</th>';
}
foreach($gridattributes as $attribname=>$attribval){
    echo '<td>'.$this->htmlEscape($_item->getData($attribname)).'</td>';
}