Hi folks,
Can someone please help me with the following. We display a list of categories the product belongs to in the following code. However, when there are no category headings the "Application Guide" row still appears. I believe we need some sort of an "if" statement but I tried everything and couldn't make it work. Basically, I need the Application Guide row to disappear if there are no Category Headings for the product.
The regular attributes do hide if they are empty.
<?php $_helper = $this->helper('catalog/output'); $_product = $this->getProduct(); $currentCatIds = $_product->getCategoryIds(); $catCollection = Mage::getResourceModel('catalog/category_collection') ->addAttributeToSelect('*') ->addAttributeToFilter('entity_id', $currentCatIds) ->addAttributeToFilter('is_active', 1) ->setOrder('creareseo_heading', 'asc') ->addIsActiveFilter(); ?> <?php if($_additional = $this->getAdditionalData()): ?> <h2><?php echo $this->__('Additional Information') ?></h2> <table class="data-table" id="product-attribute-specs-table"> <col width="25%" /> <col /> <tbody> <?php foreach ($_additional 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"><?php echo $this->escapeHtml($this->__($_data['label'])) ?></th> <td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td> </tr> <?php } ?> <?php endforeach; ?> <tr> <th class="label"><?php echo $this->__('Application Guide') ?></th> <td class="data"> <ul> <?php foreach($catCollection as $cat): ?> <li><?php echo $cat->getCreareseoHeading() ?></li> <?php endforeach; ?> </ul> </td> </tr> </tbody> </table> <script type="text/javascript">decorateTable('product-attribute-specs-table')</script> <?php endif;?>
Thanks in advance!
Hello
Please use
$_additional = $this->getAdditionalData(); if(sizeof($_additional)) { your code }
instaed of
if($_additional = $this->getAdditionalData()):
Thanks
Please download the code from the link provided here and paste into your magento root directory.
Hope this helps!