0

This is the php code I wrote for our product view page. It should only show on the front end if the variable has a value. yet the html still shows even if the product does not have the variable defined. Note: This is specific to the magento predefined country of manufacture attribute.

<?php 
    $coManufacturer = $this->getProduct()->getAttributeText('country_of_manufacture'); 
?>
<?php if ($coManufacturer): ?>
    <p><strong>Country of Origin:</strong> <?php echo $coManufacturer; ?></p>                           
<?php endif; ?>
4
  • 1
    Which value do you get in a product with no value of that attribute? Dump the var to check it. – mbalparda Oct 1 '14 at 0:31
  • change your condition to if (!empty($coManufacturer)) and then check again – Rajeev K Tomy Oct 1 '14 at 3:08
  • @programmer_rkt I tried your suggestion and I get the same result. – Legendary_Fish Oct 1 '14 at 16:11
  • @mbalparda I dumped the var and got this result: string(1) " " – Legendary_Fish Oct 1 '14 at 16:15
0

Looks like the solution was to dump the var to understand what was being populated for the empty field of the attribute. Once I got that figured out, I was able to change the condition to this: ($coManufacturer!=" ") which corrected the behavior. Thanks for your guys help!

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.