The question:
Create Dropdown attribute , if dropdown value is “yes” than image(any image) will display in products page and if dropdown value is “no” than image will not display.
The Solutions:
Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.
Method 1
- Create a new attribute under Store -> Attributes
- link the newly created attribute to the Attribute Set (Store-Menu)
-
in your phtml, get value of Attribute with
$_item->getData('your_attribute_code')
. Example below.<?php if($_item->getData('my_attribute') == 1):
//do something
endif; ?>
Method 2
please follow the my code to getting exact output..
<?php
$productId = 1;
$product = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore()->getId())->load($productId);
$selectedvalue = $product->getAttributeText('paypal');
$atributeCode = 'paypal';
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product',$atributeCode);
$options = $attribute->getSource()->getAllOptions();
foreach($options as $key => $value){
if(in_array($selectedvalue,$value)){
if($selectedvalue=='yes')
{
echo "<pre>";
// print_r($value); //get Product's selected attribute options Values
//echo(implode($value));
echo "</pre>";
//echo "<div id='some'><img src='image.jpg'></div>";
echo "<img src='https://www.paypalobjects.com/webstatic/mktg/logo/bdg_now_accepting_pp_2line_w.png' border='0' alt='Now accepting PayPal'>";
continue;
}
}
}
?>
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0