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;
}
}
我自定義了我的代碼來隱藏這個選項卡中具有空值的屬性,並且也隱藏了它們的組標題。具有空值的屬性是隱藏的,但現在所有的組標題都是隱藏的。我想隱藏空的。