0

This question already has an answer here:

http://pastebin.com/6uzYgauE

we are using above attributes.phtml file to display the attibutes in frontend.

app/design/frontend/default/theme/template/catalog/product/view/attributes.phtml

suppose if attribute value is empty , than thiose attributes will not display in frontend for the

particular product .

but if we give some empty space in the attribute text field, than those attributes are displaying in the frontend.

if we gave empty space as attribute values , than we want to hide those attributes for the particular product.

ex: if attribute manufacturer = "" than color will not display in frontend

if attribute manufacturer = " " than color will display in frontend. we want to hide color here....

please help me to find solution.

marked as duplicate by 7ochem, Amit Bera, Mufaddal, Julien Lachal, Qaisar Satti Oct 14 '15 at 12:22

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    You could use trim() to eliminate the whitespace. Or use if(empty($yourvar)) – Michael Sep 22 '15 at 11:08
  • can you please infrom in detail, in which line i have to do which chnages.... – Baby in Magento Sep 22 '15 at 11:09
  • 1
    presumably this bit: ((string)$_attribute->getFrontend()->getValue($_product) != '')) – Michael Sep 22 '15 at 11:12
  • 1
    I'm not sure about this but you could replace the line 49 with something like if(strlen(trim($_product->getData($_attribute->getAttributeCode())))>0 && strlen(trim(((string)$_attribute->getFrontend()->getValue($_product)) > 0))) – Michael Sep 22 '15 at 12:13
  • 1
    ok, so make sure there are the right number of opening and closing brackets (both in that if statement and for php). For example my comment missed the { ?> at the end. Just make sure the if statement and the php parts have the same opening and closing brackets – Michael Sep 22 '15 at 12:34
2

Replace line 49

if (!is_null($_product->getData($_attribute->getAttributeCode())) && ((string)$_attribute->getFrontend()->getValue($_product) != '')) { ?>

With

if (!is_null($_product->getData($_attribute->getAttributeCode())) && (trim((string)$_attribute->getFrontend()->getValue($_product)) != '')) { ?>
1

Find attribute.phtml in this code

<?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>

Replace to this

<?php foreach ($_additional as $_data): ?>
   <?php if ((string)$_data['value'] != '' and $_data['value'] != 'N/A'): ?>
   <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 endif; ?>
  <?php endforeach; ?>
  • Parse error: syntax error, unexpected 'endif' (T_ENDIF) in /var/www/html/demo4/app/design/frontend/default/em0113/template/catalog/product/view/attributes.phtml on line 68 = >pastebin.com/tSS8RPR3 – Baby in Magento Sep 22 '15 at 11:43
  • delete one endif – Magento 2 Sep 22 '15 at 11:46
  • its not working..... pastebin.com/0DZ0hzwt – Baby in Magento Sep 22 '15 at 11:50
  • @BabyinMagento without string not wokring, may i know what is the reason? don't need to give data type in PHP right? – zus Sep 19 at 12:49
1

from :

<?php $_attribute = $_product->getResource()->getAttribute($_data['code']);
    if (!is_null($_product->getData($_attribute->getAttributeCode())) && ((string)$_attribute->getFrontend()->getValue($_product) != '')) { ?>

with

<?php $yourAtttrbute = $_product->getData($_attribute->getAttributeCode()); 
$yourAtttrbute2 = $_attribute->getFrontend()->getValue($_product);
$desLen = strlen(trim($yourAtttrbute));
$desLen2 = strlen(trim($yourAtttrbute2));
     if($desLen != 0 && $desLen2 != 0)
 {
    ?>
  • can you please inform in detail, in which line i have to do which changes.... i s i have to manually fro all attribute codes ? – Baby in Magento Sep 22 '15 at 11:10
  • 1
    change code on line no 48 – Arunendra Sep 22 '15 at 11:20
  • Parse error: syntax error, unexpected '$desLen' (T_VARIABLE) in /var/www/html/2/app/design/frontend/default/em0113/template/catalog/product/view/attributes.phtml on line 50 please check : pastebin.com/QfeQ1f7r – Baby in Magento Sep 22 '15 at 11:28
  • 1
    i have edited ans plz check it i was forget (;) – Arunendra Sep 22 '15 at 11:55
  • Fatal error: Call to a member function getAttributeCode() on a non-object onl ine 49 in pastebin.com/KnC3mCyM – Baby in Magento Sep 22 '15 at 11:58

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