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

Overriding JS function in product.js with custom JS file
 
haligonia
Sr. Member
 
Total Posts:  97
Joined:  2009-02-28
 

How do I override a core JS function?

I am making an extension that calls a custom JS file on the product view page. This custom JS file needs to override the formatPrice() function found at the bottom of /js/varien/product.js.

The original formatPrice function is as follows:

formatPrice: function(price{
    
return formatCurrency(pricethis.priceFormat);
}

I would like to replace / override this function with the following:

formatPrice: function(price{
    
if (price == 0{ this.priceFormat.requiredPrecision 0}
        
    
return formatCurrency(pricethis.priceFormat);
}

How do I write the JS code in my custom JS file so that it will properly override this function? I’m not familiar with JS enough to know.

 
Magento Community Magento Community
Magento Community
Magento Community
 
haligonia
Sr. Member
 
Total Posts:  97
Joined:  2009-02-28
 

I solved this question with the help of Stackoverflow:

function myFormatPrice(price{
    
if (price == 0{ this.priceFormat.requiredPrecision 0}
    
    
return formatCurrency(pricethis.priceFormat);
}

Product
.OptionsPrice.prototype.formatPrice myFormatPrice;
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top