为什么不创建一个告诉它要显示哪些属性的属性?
我最终创建了一个模块,该模块为作为属性代码字符串的分组产品加载两个文本属性的值。本质上是一个爆炸该属性列表字符串并在其上循环以加载关联产品属性数据的助手。
创建一个称为我的属性:
grouped_attr_array
将属性添加到管理员中分组产品的设计属性中,然后在产品数据中将它们作为分号分隔的字段
torque_range;torque_increments;torque_accuracy
我从模块中提取了这段代码。它会基于属性值进行更多的默认属性加载或隐藏操作,并且该模块更加复杂。但是要获得表中显示的数据,这些是一些核心功能。希望它能给您一个构想。这是使用magento 1.9.2
模块的助手:
public function findAttributes($product, $attributes)
{
    //determined by attribute with id to add additional attributes to the table
    //string needs to be ; separated in ADMIN
    $strattributes = $product->getResource()->getAttribute('grouped_attr_array')->getFrontend()->getValue($product);
    if ($strattributes) {
        $strattributes = explode(';', $strattributes, 5);
        foreach ($strattributes as $additionAttribute) {
            //make sure these are valid attributes
            if ($product->getResource()->getAttribute($additionAttribute)) {
                array_push($attributes, $additionAttribute);
            }
        }
    }
}
public function groupedAttrDump($groupedProduct, $attributes)
{
    $cells = [];
    foreach ($attributes as $attrCode) {
        $attrText = $groupedProduct->getResource()->getAttribute($attrCode);
        if($attrText){
            array_push($cells, $attrText->getFrontend()->getValue($groupedProduct));
        }
    }
    return $cells;
}
public function groupedAttrHeaders($currentProduct, $attributes)
{
    $theads = [];
    foreach ($attributes as $attrCode) {
        $headerText = $currentProduct->getResource()->getAttribute($attrCode);
        if($headerText){
            $headerText = $headerText->getStoreLabel();
            array_push($theads,$headerText);
        }
    }
    return $theads;
}
从groupedproduct.phtml中的帮助程序获取数据
$attrrSetName = Mage::getModel("eav/entity_attribute_set")->load($_product->getAttributeSetId())->getAttributeSetName();
$tableAttributes = Mage::helper('groupedtable')->findAttributes($_product, $attrrSetName);
TH的
     <?php foreach (Mage::helper('groupedtable')->groupedAttrHeaders($_product, $tableAttributes) as $attrLabel ): ?>
        <th><?php echo $attrLabel ?> </th>
     <?php endforeach; ?>
TD的桌子
<?php foreach (Mage::helper('groupedtable')->groupedAttrDump($_associatedProduct, $tableAttributes) as $attr ):?>
        <td><?php if($attr != 'No'){ echo $attr; } ?></td>
   <?php endforeach; ?>
我想建立一种根据商店的可用属性选择属性的方法。也许还有更好的方法可以做到这一点。还没有做到这一点。