{"id":1318,"date":"2013-02-22T09:47:43","date_gmt":"2013-02-22T09:47:43","guid":{"rendered":"http:\/\/webkul.com\/blog\/?p=1318"},"modified":"2013-03-21T08:25:50","modified_gmt":"2013-03-21T08:25:50","slug":"magento-product-attributes","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/magento-product-attributes\/","title":{"rendered":"Magento Product Attributes"},"content":{"rendered":"<p>Get Custom Attributes Value in Frontend.<\/p>\n<p>1. Suppose our custom attribute code is <strong>&#8220;test_attr&#8221;<\/strong> and of type <strong>Text Field<\/strong> or <strong>Text Area<\/strong> .<\/p>\n<pre class=\"brush:php\">&lt;?php\r\n     $product = Mage::getModel(\"catalog\/product\")-&gt;load($product_id);\r\n     echo $product-&gt;getTestAttr();\r\n?&gt;<\/pre>\n<p>I use <strong>getTestAttr()<\/strong> because my attribute code is <strong>&#8220;test_attr&#8221;<\/strong>, Use uppercase after underscore or begining of character, like<\/p>\n<p>for <strong>&#8220;testattr&#8221;<\/strong> method should be <strong>getTestattr()<\/strong><\/p>\n<p>for <strong>&#8220;test_attr&#8221;<\/strong> method should be <strong>getTestAttr()<\/strong><\/p>\n<p>2.\u00a0Suppose our custom attribute code is\u00a0<strong>&#8220;test_attr&#8221;<\/strong>\u00a0and of type\u00a0<strong>Multiselect<\/strong>\u00a0or <strong>Dropdown<\/strong>\u00a0.<\/p>\n<pre class=\"brush:php\">&lt;?php\r\n     $product = Mage::getModel(\"catalog\/product\")-&gt;load($product_id)\r\n     $attributeCode = 'test_attr';\r\n     $AllAttributes = $product-&gt;getAttributes();\r\n        if(array_key_exists($attributeCode , $AllAttributes)){\r\n            $Attribute = $AllAttributes[\"$attributeCode\"];\r\n            $Value = $Attribute-&gt;getFrontend()-&gt;getValue($product);\r\n        }\r\n     echo $Value;\r\n?&gt;<\/pre>\n<p>3. To get all the options of attributes .<\/p>\n<pre class=\"brush:php\">&lt;?php  \r\n     $attributeId = Mage::getResourceModel('eav\/entity_attribute')-&gt;getIdByCode('catalog_product','test_attr');\r\n     $attribute = Mage::getModel('catalog\/resource_eav_attribute')-&gt;load($attributeId);\r\n     $attributeOptions = $attribute-&gt;getSource()-&gt;getAllOptions();\r\n     foreach($attributeOptions as $each){\r\n       echo $each[\"label\"].\" \".$each[\"value\"].\"&lt;br&gt;\";\r\n     }\r\n?&gt;<\/pre>\n<p>4. To get value of text type, attribute.<\/p>\n<pre class=\"brush:php\">$_product-&gt;getData(\"test_attr\");<\/pre>\n<p>5. To get values of multiselect type, attribute.<\/p>\n<pre class=\"brush:php\">$_product-&gt;getResource()-&gt;getAttribute('test_attr')-&gt;getFrontend()-&gt;getValue($_product);<\/pre>\n<p>6. To get value of dropdown type, attribute.<\/p>\n<pre class=\"brush:php\">$_product-&gt;getAttributeText('test_attr');<\/pre>\n<p>Enjoy !!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Get Custom Attributes Value in Frontend. 1. Suppose our custom attribute code is &#8220;test_attr&#8221; and of type Text Field or Text Area . &lt;?php $product = Mage::getModel(&#8220;catalog\/product&#8221;)-&gt;load($product_id); echo $product-&gt;getTestAttr(); ?&gt; I use getTestAttr() because my attribute code is &#8220;test_attr&#8221;, Use uppercase after underscore or begining of character, like for &#8220;testattr&#8221; method should be getTestattr() for <a href=\"https:\/\/webkul.com\/blog\/magento-product-attributes\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[240],"class_list":["post-1318","post","type-post","status-publish","format-standard","hentry","category-magento","tag-product-attributes"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Magento Product Attributes - Webkul Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/magento-product-attributes\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Magento Product Attributes - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"Get Custom Attributes Value in Frontend. 1. Suppose our custom attribute code is &#8220;test_attr&#8221; and of type Text Field or Text Area . &lt;?php $product = Mage::getModel(&quot;catalog\/product&quot;)-&gt;load($product_id); echo $product-&gt;getTestAttr(); ?&gt; I use getTestAttr() because my attribute code is &#8220;test_attr&#8221;, Use uppercase after underscore or begining of character, like for &#8220;testattr&#8221; method should be getTestattr() for [...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/magento-product-attributes\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2013-02-22T09:47:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2013-03-21T08:25:50+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Ratnesh\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ratnesh\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/magento-product-attributes\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento-product-attributes\/\"},\"author\":{\"name\":\"Ratnesh\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/98fa964dace2c6affe08c231d20914f7\"},\"headline\":\"Magento Product Attributes\",\"datePublished\":\"2013-02-22T09:47:43+00:00\",\"dateModified\":\"2013-03-21T08:25:50+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento-product-attributes\/\"},\"wordCount\":100,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"keywords\":[\"Product attributes\"],\"articleSection\":[\"magento\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/magento-product-attributes\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/magento-product-attributes\/\",\"url\":\"https:\/\/webkul.com\/blog\/magento-product-attributes\/\",\"name\":\"Magento Product Attributes - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"datePublished\":\"2013-02-22T09:47:43+00:00\",\"dateModified\":\"2013-03-21T08:25:50+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento-product-attributes\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/magento-product-attributes\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/magento-product-attributes\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Magento Product Attributes\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/98fa964dace2c6affe08c231d20914f7\",\"name\":\"Ratnesh\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/87f852615fec6dd5521718a501298d8eeba3c4882fea89c1eda3b272e53406d3?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/87f852615fec6dd5521718a501298d8eeba3c4882fea89c1eda3b272e53406d3?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Ratnesh\"},\"sameAs\":[\"http:\/\/webkul.com\"],\"url\":\"https:\/\/webkul.com\/blog\/author\/ratnesh\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Magento Product Attributes - Webkul Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/magento-product-attributes\/","og_locale":"en_US","og_type":"article","og_title":"Magento Product Attributes - Webkul Blog","og_description":"Get Custom Attributes Value in Frontend. 1. Suppose our custom attribute code is &#8220;test_attr&#8221; and of type Text Field or Text Area . &lt;?php $product = Mage::getModel(\"catalog\/product\")-&gt;load($product_id); echo $product-&gt;getTestAttr(); ?&gt; I use getTestAttr() because my attribute code is &#8220;test_attr&#8221;, Use uppercase after underscore or begining of character, like for &#8220;testattr&#8221; method should be getTestattr() for [...]","og_url":"https:\/\/webkul.com\/blog\/magento-product-attributes\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2013-02-22T09:47:43+00:00","article_modified_time":"2013-03-21T08:25:50+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png","type":"image\/png"}],"author":"Ratnesh","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Ratnesh","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/magento-product-attributes\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/magento-product-attributes\/"},"author":{"name":"Ratnesh","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/98fa964dace2c6affe08c231d20914f7"},"headline":"Magento Product Attributes","datePublished":"2013-02-22T09:47:43+00:00","dateModified":"2013-03-21T08:25:50+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/magento-product-attributes\/"},"wordCount":100,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"keywords":["Product attributes"],"articleSection":["magento"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/magento-product-attributes\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/magento-product-attributes\/","url":"https:\/\/webkul.com\/blog\/magento-product-attributes\/","name":"Magento Product Attributes - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"datePublished":"2013-02-22T09:47:43+00:00","dateModified":"2013-03-21T08:25:50+00:00","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/magento-product-attributes\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/magento-product-attributes\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/magento-product-attributes\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Magento Product Attributes"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/98fa964dace2c6affe08c231d20914f7","name":"Ratnesh","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/87f852615fec6dd5521718a501298d8eeba3c4882fea89c1eda3b272e53406d3?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/87f852615fec6dd5521718a501298d8eeba3c4882fea89c1eda3b272e53406d3?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Ratnesh"},"sameAs":["http:\/\/webkul.com"],"url":"https:\/\/webkul.com\/blog\/author\/ratnesh\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/1318","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=1318"}],"version-history":[{"count":3,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/1318\/revisions"}],"predecessor-version":[{"id":1320,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/1318\/revisions\/1320"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=1318"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=1318"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=1318"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}