-1

May I ask what I am missing? My attributes and blocks are set. However the conditional isn't firing.

<?php if ($_product->getAttributeText('design_and_imprint_avail') == "Yes"): ?>

    <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('design-imprint-edit')->toHtml() ?>

<?php elseif ($_product->getAttributeText('custom_design') == "Yes"): ?>

    <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('custom-design-edit')->toHtml() ?>

<?php else ($_product->getAttributeText('imprint_available') == "Yes"): ?>

    <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('imprint-edit')->toHtml() ?>

<?php endif; ?>
3
  • Which version of Magento you are using? Commented Dec 14, 2015 at 14:22
  • 2
    Nevermind. You shouldn't use a condition for else part. Commented Dec 14, 2015 at 14:24
  • Yep, else is the default if nothing matches the conditions in the previous if/elsif tests. Commented Dec 14, 2015 at 17:17

1 Answer 1

0

getAttributeText should only be used for displaying values, not for conditions. It all goes south if you switch the language.
You can try this:

if ($_product->getData('design_and_imprint_avail')) : 
   //
elseif ($_product->getData('custom_design')) :....

Also, if you are doing this in the product list page, make sure the attributes involved in this if/else chain are marked with "Used in product listing" and that you rebuilt the indexes.

1
  • So then getData sets it as a "truthy" statement? No need to add "Yes" Commented Dec 14, 2015 at 20:37

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