1

I have added a text-field attribute in product-collateral tab in details page with following code:

<?php $_helper = $this->helper('catalog/output'); ?>
<?php $_product = $this->getProduct(); ?>
<script type="text/javascript">
    var optionsPrice = new Product.OptionsPrice(<?php echo $this->getJsonConfig() ?>);
</script>
<?php $Application = $_product->getApplication(); ?>
<?php if(count($Application, 'strlen') > 0): ?>

        <div class="application">
            <?php echo $_product->getApplication(); ?>
        </div>

<?php endif; ?>

when I enter the value in the text field at backend it is perfectly getting displayed. But the error is that the tab is getting displayed even when I enter no value in that field.

Kindly help me to resolve this issue.

0

I'm not sure if I understand your question but if you just want to hide the custom attribute when there is no content then you can use this.

$application = $_product->getApplication();
if (!is_null($application)):
echo '<div class="application">' . $application . '</div>';
endif;

You would use the same method around the tab data

0

This can be done with a small piece of code. Find and open the attributes.phtml file. This file can be found here: /app/design/frontend/[theme name]/[package name]/template/catalog/product/view/attribute.phtml

Open the file and search for the following lines:

<?php foreach ($_additional as $_data): ?>
    <tr>
        <th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
        <td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
    </tr>
<?php endforeach; ?>

Replace the entire foreach loop with the following lines of code:

<?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->htmlEscape($this->__($_data['label'])) ?></th>
        <td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
    </tr>
    <?php } ?>
<?php endforeach; ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.