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

Use getPriceHTML and getAddToCartUrl anywhere
 
RickV
Member
 
Total Posts:  31
Joined:  2008-12-05
 

Hi,

I want the functions getPriceHTML and getAddToCartUrl on my homepage. The homepage is a block of type catalog/navigation. The reason I did this, is because I havbe to scan the entire catalog to find specific products.

I got these lines of code:

$_product = new Mage_Catalog_Model_Product();
    
$_product->load($_product_id);

How can I transform this in some way that I can use these two functions: getPriceHTML and getAddToCartUrl
I know the functions are part of the class “Mage_Catalog_Block_Product_Abstract” ( http://docs.magentocommerce.com/Mage_Catalog/Mage_Catalog_Block_Product_Abstract.html )

I’ve tried everything, including stuff like: $this->getLayout()->createBlock(’Mage_Catalog_Block_Product_list’)
But I couldn’t get it to work.

Anyone?

I guess I should be able to get the price and AddToCartUrl when I got the product ID don’t I… seems logical enough smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
eliezerisrael
Jr. Member
 
Total Posts:  28
Joined:  2009-06-18
 

I had the same issue.
I think the easiest way to do this is change the block type of the block on your home page.

My CMS page that rendered the home page had the following line:
{{block type="core/template" name="home.favorites" template="catalog/product/community-favorites-list.phtml"}}

I changed the block type to one that inherits the getPriceHtml() method:
{{block type="catalog/product_list" name="home.favorites" template="catalog/product/community-favorites-list.phtml"}}

 
Magento Community Magento Community
Magento Community
Magento Community
 
tim_bezhashvyly
Jr. Member
 
Avatar
Total Posts:  17
Joined:  2010-05-19
 

Instead of getPriceHTML use

<?php echo number_format($_product->getFinalPrice(), 2?>

Instead of getAddToCartUrl use

<?php echo $this->helper('checkout/cart')->getAddUrl($_product?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
Paulus
Guru
 
Total Posts:  335
Joined:  2008-07-21
 

Thanks, i needed that addtocart url wink

 
Magento Community Magento Community
Magento Community
Magento Community
 
tim_bezhashvyly
Jr. Member
 
Avatar
Total Posts:  17
Joined:  2010-05-19
 

But please note that it will not work for bundle products.

 
Magento Community Magento Community
Magento Community
Magento Community
 
adisuns
Jr. Member
 
Avatar
Total Posts:  30
Joined:  2010-07-04
 

this will create issues if multiple currencies are used. need to call getpricehtml in page block

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