0

I've created a media attribute, and now i'm triyng to display this attribute to my product view page.

I've tried this code below:

$hdr_img = $cur_product->getResource()->getAttribute('header_img'); if ($hdr_img) { $ban_img = $this->helper('catalog/image')->init($cur_product, 'header_img')->resize(1600, 312); echo $ban_img; } 

But all I got is a :

Fatal error: Uncaught Error: Call to a member function getResource() on unknown in /var/www/virtual/unikamakeup.com/htdocs/app/design/frontend/sns_simo/default/template/catalog/product/view.phtml:132 Stack trace: #0 /var/www/virtual/unikamakeup.com/htdocs/app/code/core/Mage/Core/Block/Template.php(241): include() #1 /var/www/virtual/unikamakeup.com/htdocs/app/code/core/Mage/Core/Block/Template.php(272): Mage_Core_Block_Template->fetchView('frontend/sns_si...') #2 /var/www/virtual/unikamakeup.com/htdocs/app/code/core/Mage/Core/Block/Template.php(286): Mage_Core_Block_Template->renderView() #3 /var/www/virtual/unikamakeup.com/htdocs/app/code/core/Mage/Core/Block/Abstract.php(919): Mage_Core_Block_Template->_toHtml() #4 /var/www/virtual/unikamakeup.com/htdocs/app/code/core/Mage/Core/Block/Text/List.php(43): Mage_Core_Block_Abstract->toHtml() #5 /var/www/virtual/unikamakeup.com/htdocs/app/code/core/Mage/Core/Block/Abstract.php(919): Mage_Core_Block_Text_List->_toHtml() #6 /var/www/virtual/unikamakeup.com/htdocs/app/code/core/ in /var/www/virtual/unikamakeup.com/htdocs/app/design/frontend/sns_simo/default/template/catalog/product/view.phtml on line 132

2 Answers 2

0

$cur_product is undefined. Says so right there in the stack trace. You need to make sure that $cur_product is actually set to something before you try to access any methods on it.

You might include the code that defines $cur_product so we may better assist you.

Additionally, a nice way to check if your product is valid is doing this:

var_dump($cur_product->debug()); 

or

var_dump($cur_product->getData()); 

This will output a mostly human readable array of the current variable's data.

2
  • This is not an answer Commented May 5, 2016 at 13:41
  • The question was hardly a complete question, but I let THAT slide. Commented May 5, 2016 at 13:51
-1

Its Working code and i tested in my magento 1.9.2.2

$hdr_img = $_product->getHeaderImg();

if ($hdr_img) { $ban_img = $this->helper('catalog/image')->init($_product, 'header_img')->resize(1600, 312); echo $ban_img; } 

Have you assigned image for the given media attribute in images tab in Manage product section.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.