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.

1
  • Please let me know if you have any issue. Commented May 1, 2017 at 8:40

4 Answers 4

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"): ?> 
0
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") { // ... } 
3
  • I tried this, but I couldn't get it to work the right way :( But thanks for your quick answer! Commented May 1, 2017 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. Commented May 1, 2017 at 9:08
  • It's working now: <?php if ($_product->getData('cp_doos_specificaties') == "1"): ?> Commented May 1, 2017 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')) 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.