2015-05-09 62 views
0

我做了一些编码来组产品属性的前端,并显示上述类似这样的主题,他们的团体名称:隐藏空属性组属性选项卡

  • attgroup 1
    • 属性1
    • 属性2
    • ...
  • attgroup 2
    • 属性3
    • 属性4
    • ...

这是我groupview.phtml(atributes.phtml二选一)内容:

groupview.phtml

<?php 
     $_helper = $this->helper('catalog/output'); 
     $_product = $this->getProduct() 
    ?> 
    <?php if($_additionalgroup = $this->getAdditionalData()): ?> 
    <div class="box-collateral box-additional"> 
     <h2><?php echo $this->__('Additional Information') ?></h2> 

     <?php $i=0; foreach ($_additionalgroup as $_additional): $i++; 
if($_additional['values_exist'] !== true) { 
    continue; ?> 
     <div class="attributesgroups-title"> 
      <h3 style="margin:0; color:white;"><?php echo $this->__($_additional['title'])?></h3> 
      </div> 
<?php } ?> 
      <table style="border-radius: 0 0 2px 2px;" class="data-table" id="product-attribute-specs-table-<?php echo $i?>"> 
       <col width="25%" /> 
       <col /> 
       <tbody> 
       <?php foreach ($_additional['items'] as $_data): ?> 
       <?php $_attribute = $_product->getResource()->getAttribute($_data['code']); 
     if (!is_null($_product->getData($_attribute->getAttributeCode())) && ((string)$_attribute->getFrontend()->getValue($_product) != '')) { ?> 
        <tr> 
         <th class="label"><img src="<?php echo $this->getSkinUrl('images/attributes/'.$_data['code'].'.png')?>" alt="<?php echo $this->htmlEscape($this->__($_data['label'])) ?>" /><span class="separator">|</span><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th> 
         <td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td> 
        </tr> 
        <?php } ?> 
       <?php endforeach; ?> 
       </tbody> 
      </table> 
      <script type="text/javascript">decorateTable('product-attribute-specs-table-<?php echo $i?>')</script> 
     <?php endforeach; ?> 

    </div> 
    <?php endif;?> 

groupview.php :

<?php 

class Webguys_AttributesAsGroup_Block_Groupview extends Mage_Core_Block_Template 
{ 
    protected $_product = null; 

    function getProduct() 
    { 
     if (!$this->_product) { 
      $this->_product = Mage::registry('product'); 
     } 
     return $this->_product; 
    } 

    public function getAdditionalData(array $excludeAttr = array()) 
{ 
    $data = array(); 
    $product = $this->getProduct(); 
    $attributes = $product->getAttributes(); 
    foreach ($attributes as $attribute) { 
//   if ($attribute->getIsVisibleOnFront() && $attribute->getIsUserDefined() && !in_array($attribute->getAttributeCode(), $excludeAttr)) { 
     if ($attribute->getIsVisibleOnFront() && !in_array($attribute->getAttributeCode(), $excludeAttr)) { 

      $value = $attribute->getFrontend()->getValue($product); 

      // TODO this is temporary skipping eco taxes 
      if (is_string($value)) { 
       if (strlen($value) && $product->hasData($attribute->getAttributeCode())) { 
        if ($attribute->getFrontendInput() == 'price') { 
         $value = Mage::app()->getStore()->convertPrice($value,true); 
        } 

        $group = 0; 
        if($tmp = $attribute->getData('attribute_group_id')) { 
         $group = $tmp; 
        } 

        $data[$group]['items'][ $attribute->getAttributeCode()] = array(
         'label' => $attribute->getFrontend()->getLabel(), 
         'value' => $value, 
         'code' => $attribute->getAttributeCode() 
        ); 

        // If there has been a value set above, we know this group is worth showing. 
        if(strlen($data[$group]['items'][$attribute->getAttributeCode()]['value'])) { 
         // Set the group to record that it has values 
         $data[$group]['values_exist'] = true; 
        } 
        $data[$group]['attrid'] = $attribute->getId(); 

       } 
      } 
     } 
    } 

    // Noch Titel lesen 
    foreach($data AS $groupId => &$group) { 
     $groupModel = Mage::getModel('eav/entity_attribute_group')->load($groupId); 
     $group['title'] = $groupModel->getAttributeGroupName(); 
    } 

    return $data; 
    } 
} 

我自定义了我的代码来隐藏这个选项卡中具有空值的属性,并且也隐藏了它们的组标题。具有空值的属性是隐藏的,但现在所有的组标题都是隐藏的。我想隐藏空的。

回答

0

这个模块正是你想要的。你遇到的同样的问题是在我自己的网站上窃听我,也可能让客户感到困惑。

Improved Attribute Display

Demo

其实,这并不确切地格式化你想要的清单,但它消除了空瓶和非相关者不碰你的模板文件。另外,它也可以在产品比较屏幕中使用。