1

For every product in my magento i have custom attributes like - food_taste, food_brand and many more. I use them for filtering my products in category view. But now i want when clients open the product to see attributes.

Example: Brand: Royal Canin Taste: Chicken ...... I try with some codes that i found here, but...

$productId = 52;
$product = Mage::getModel('catalog/product')->load($productId);
$attributes = $product->getAttributes();

foreach ($attributes as $attribute) {       
    $attributeCode = $attribute->getAttributeCode();
    $label = $attribute->getStoreLabel($product);   
    $value = $attribute->getFrontend()->getValue($product);
    echo $attributeCode . '-' . $label . '-' . $value; echo "<br />";       
} 

Can you help me to do that.

Thank you

  • wt issue are you facing.? – Manashvi Birla Jul 9 '15 at 13:13
  • If i use the code UP, i receive not found 404 of product page – Martin Jul 9 '15 at 13:15
  • make sure that the id of the product is 52. I suppose you have copied the code from here blog.chapagain.com.np/…, so just to clear my doubt – Manashvi Birla Jul 9 '15 at 13:19
  • ýou want to show all attribute in product view page – MeenakshiSundaram R Jul 9 '15 at 13:21
  • Yes, i want to show all attributes of product in product view page. – Martin Jul 9 '15 at 13:26
5

This will give all the attributes of a product on the vew page

$product_id = $_product->getId();
$product = Mage::getModel('catalog/product')->load($product_id);
$attributes = $product->getAttributes();

foreach ($attributes as $attribute) { 
    if($attribute->getAttributeCode() == 'zoo_spec_dog' || $attribute->getAttributeCode() == 'zoo_taste')      
    {
        $attributeLabel = $attribute->getFrontendLabel();
        $value = $attribute->getFrontend()->getValue($product);
        echo $attributeLabel . '-' . $label . '-' . $value; echo "<br />";       
    }
}
  • i try, but receive magento page - 404 error: Page not found. – Martin Jul 9 '15 at 13:33
  • the code of 404 <head> <title>Error 404: Not Found</title> <base href="cccccccccc.bg/errors/default" /> – Martin Jul 9 '15 at 13:37
  • check my updated answer – Manashvi Birla Jul 9 '15 at 13:38
  • I receive really all attributes... hmmm... i need to define my question...How to show only 5 of them? – Martin Jul 9 '15 at 13:43
  • you can use this to display selected attributes if($attribute->getFrontendLabel() == 'Your attribute label'){// display logic} – Manashvi Birla Jul 9 '15 at 13:46
2

EDIT: Thanks To Fabian for catching my mistake; answer adjusted accordingly"

i want when clients open the product to see attributes.

You need to mark these attributes as "Visible on Product View Page on Front-end" = "Yes"*

This can be done two ways.

  1. In the admin panel: Attribute edit settings

  2. Via setup script, using Mage_Catalog_Model_Resource_Setup::updateAttribute() to set the is_visible_on_front value to 1.

  • If I understand the question correct, it should be "Visible on Product View Page on Front-end" (is_visible_on_front). "Used in Product Listing" just adds the attribute to the flat index so that it gets loaded in collections and can be used in product lists. – Fabian Schmengler Jul 10 '15 at 7:02
  • Absolutely correct, @fschmengler. This is what happens when one spends too much time evangelizing. – benmarks Jul 12 '15 at 11:30
0

If you want to show custom attribute value in product view page.

You can set that in admin panel itself.

Navigate to

admin > catalog > manage attribute

Then set all your custom attribute visible on product view page on frontend value yes.

So now your custom attribute value will be automatically rendered in product view page.

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.