Hello Magento experts.
I'm not a programmer but I have to do this for my new magento store as I can't hire a programmer to do this for me. So I'd be greateful to you if I got solution for this. This should be pretty easy for you guys.
I have added an attribute "New" with the field "Yes/No" Now I need to display "New" in the product list and product view pages if the value is yes.
Similarly I'd like to display some custom attributes in "short description" area. For example there is an attribute called "Dimension". I want to first check if the field "Dimension" has a value or not if yes display the value with the label "Dimension", other wise don't display the label "Dimension" either.
I don't know If I've explained it correct. Please help me out from this.
This is what I've used to display custom attributes in my product page
<?php // check attribute exists (Where 'dimension' is the attribute code for your attribute) if ($attribute = $this->getProduct()->getResource()->getAttribute('flooring_width')): ?> <?php // get label for the current store (in case you have multiple stores and languages) $_attribute_label = $attribute->getStoreLabel(Mage::app()->getStore()->getName()); // get the attribute value (for other attributes change getDimension to getName where name is the name of your attribute ); $_attribute_value = $this->getProduct()->getFlooringWidth(); ?> <?php // check there is a value for the attribute if (isset($_attribute_value)): ?> <p> <?php echo $_attribute_label . ': ' . $_attribute_value; ?> </p> <?php endif; ?> <?php endif; ?>
Here's a short blog post with some references for getting attributes
For this you need to customize the product list and product view file and add the coding according to your requirement.
Display the custom attribute are done like this.
echo $_product->getAttributecode()
Hello, Very thank you for your quick response. I tried the solutions you sent, I changed
if ($attribute = $this->getProduct()->getResource()->getAttribute('flooring_width')): ?>
with getAttribute('label_new'); label_new is my custom attribute with yes/no field. And the label for it is "Mark as New"
please please give me the pin pointed solution. I really need your help.
give this a go
as mentioned above place this in
<?php // check attribute exists (Where 'dimension' is the attribute code for your attribute) if ($attribute = $this->getProduct()->getResource()->getAttribute('new_label')): ?> <?php // get label for the current store (in case you have multiple stores and languages) $_attribute_label = $attribute->getStoreLabel(Mage::app()->getStore()->getName()); // get the attribute value (for other attributes change getDimension to getName where name is the name of your attribute ); $_attribute_value = $this->getProduct()->getNewLabel(); ?> <?php // check there is a value for the attribute if (isset($_attribute_value)): ?> <p> <?php echo $_attribute_label . ': ' . $_attribute_value; ?> </p> <?php endif; ?> <?php endif; ?>
You have to do some coding in order to display custom product attributes on Magento product view page. Refer to the following article as an example of displaying warranty product attribute.
How to display custom product attributes in Magento veiw page