Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Getting Product Name for Product Page
 
rfazuer
Jr. Member
 
Total Posts:  15
Joined:  2008-03-11
 

I’m attempting to integrate with an external gift registry, and need to get at the product name so I can pass to the script which call the registry.  I want this from on a product page, and have created a template file and added to the XML for catalog to get it to appear, but can’t get any of the get() functions to work.  I have this in right sidebar

As a test (just to see if I can get the value) I have the following in my template file:

<?php $_product $this->getProduct() ?>
<h3><?php echo $this->htmlEscape($_product->getName()) ?></h3>

However I get the following on the page:

Fatal error: Call to a member function getName() on a non-object in /path/to/templatefile

A further test (just echoing getProduct() ) seems to show that the value is Null (which explains the above error).

Why does it not get the product from this call?  Is there a problem with having it in the Right sidebar?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Discovery
Enthusiast
 
Total Posts:  767
Joined:  2007-12-29
 

you might have pulled an array of products and you may need to specify individual entities in the array.

 
Magento Community Magento Community
Magento Community
Magento Community
 
LeeSaferite
Guru
 
Avatar
Total Posts:  322
Joined:  2007-08-31
Lake City, FL
 

I’m going to guess that you are trying to call getProduct() on a block that does not have that method or variable stored on it.  When you are running inside a template file, $this references the current Block class you are inside.  Without knowing more information it’s kinda hard to give a better response.  How are you telling Magento to load your template file?  Can you post the layout XML that you are using?

 
Magento Community Magento Community
Magento Community
Magento Community
 
rfazuer
Jr. Member
 
Total Posts:  15
Joined:  2008-03-11
 

OK, both of those make sense to me...think the later (not in the right block context) is probably what is going on.  I was able to move the link into a different area within the actual product block and was able to get at the proper information just fine.

Thanks for clarifications.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top