3

I'm using this kind of statements on other places in the webshop (product detail page) but I want to use this one is on the category page:

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

But for some reason this isn't working... When I remove the || Yes it's working, but I need the Yes also because the webshop is also in English and otherwise the code won't work.

Hope someone can help me with this.

  • Please let me know if you have any issue. – Rakesh Jesadiya May 1 '17 at 8:40
2

Yo can use like below statement in your case,

This condition is allow both value Ja And Yes

<?php if ($_product->getAttributeText('cp_doos_specificaties') == "Ja" || $_product->getAttributeText('cp_doos_specificaties') == "Yes"): ?>
2

In addition to Rakesh Jesadiya who is absolutely correct in his answer, I think you should also improve the quality of the IF-statement.

If the attribute cp_doos_specificaties is a Yes/No-attribute, it will either have values "0" (for no) or "1" (for yes). Your IF-statement only takes into account 2 languages, and if someone ever adds another, they will have to know this - which is very unlikely to happen.

Instead, better use this:

<?php
// language-independent check
if ($_product->getData('cp_doos_specificaties') == "1") {
    // ...
}
  • I tried this, but I couldn't get it to work the right way :( But thanks for your quick answer! – n00bly May 1 '17 at 9:02
  • 2
    It also depends where you call this functions. If you do Zend_Debug::dump($_product->debug());, you can see the data available in the place where you are. – simonthesorcerer May 1 '17 at 9:08
  • It's working now: <?php if ($_product->getData('cp_doos_specificaties') == "1"): ?> – n00bly May 1 '17 at 12:35
1

I think Your flat tables is enable so Follow below steps,

  1. Login to admin panel
  2. Goto Catalog > attributes > Manage Attributes
  3. Find cp_doos_specificaties in attribute code
  4. Click on the attribute
  5. Set yes to Used in Product Listing
  6. Click on save
  7. Do re-indexing from System->index Managment
  8. Finally clear the cache
0

Depending on your attribute type, you can use $_product->getAttributeText('xyz') or $_product->getData('xyz') to get attribute value.

Instead of

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

you should consider to make this work language independend. It seems better to compare the attributes to the translated value.

if ($_product->getAttributeText('cp_doos_specificaties') == $this->__('Yes'))

Now make shure "Yes" is somewhere translated in one of your translation.csv.

If the attribute only returns 0 or 1, you can use

if ($_product->getData('cp_doos_specificaties'))

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.