2

I currently use the following code to check if the attribute got a specific value.

<?php if ($_product->getAttributeText('brand_name') == "Cisco"): ?>

But now I need to add another value that it needs to check.

Is this the correct way to check this?

 <?php if ($_product->getAttributeText('brand_name') == "Cisco" && $_product->getAttributeText('brand_name') == "Dell"): ?>

3 Answers 3

3

The code you pasted:

<?php if ($_product->getAttributeText('brand_name') == "Cisco" && $_product->getAttributeText('brand_name') == "Dell"): ?>

Means:

If the brand name is Cisco AND Dell.

That's very unlikely in my opinion.

If you want to know:

If the brand name is Cisco OR Dell.

You can do:

<?php if ($_product->getAttributeText('brand_name') == "Cisco" || $_product->getAttributeText('brand_name') == "Dell"): ?>

Or another way of doing it is:

<?php if (in_array($_product->getAttributeText('brand_name'),array("Cisco","Dell")): ?>
0

Try this:

<?php

if(in_array($_product->getAttributeText('brand_name'), array('Cisco','Dell','Sony'))) {

}
?>
0

You can use

Mage::hepler('catalog/product')->productAttribute($_product, $_product->getBrandName(), 'brand_name')

But as you are using asking this attribute multiple times. So You can use

$_product->getBrandName()

So that your code works fast.

Also you can do it by using array check

in_array($_product->getAttributeText('brand_name'), array('A','B','C'));

Where A,B,C is the value of checking

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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