Invalid method Mage_Catalog_Block_Product_Price::testPrice(Array(

Invalid method Mage_Catalog_Block_Product_Price::testPrice(Array(

October 18, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Invalid method Mage_Catalog_Block_Product_Price::testPrice(Array(

Magento: Overriding Price Text Using an Extension

Are you struggling to modify the price text displayed on your Magento store? In this post, we’ll walk through the process of creating a custom extension to override the default price label using a new method in the price.phtml template file.

The Original Error

The error message you’re encountering indicates that there’s an issue with how you’ve set up your custom method newPriceText() in the MyCompany_Catalog_Block_Product_Price.php file. Let’s troubleshoot this step-by-step.

Understand the Error Message

The error log provides valuable insights into what went wrong:

Invalid method Mage_Catalog_Block_Product_Price::testPrice(Array(
))

This suggests that Magento is trying to call a non-existent method testPrice() on the MyCompany_Catalog_Block_Product_Price class, which is causing a fatal error.

The Current Setup

Based on your provided code and setup, here’s what you’ve done so far:

  1. You have created a new file local/MyCompany/Catalog/Block/Product/Price.php.
  2. In this file, you extended the core Magento class Mage_Catalog_Block_Product_Price with your own class MyCompany_Catalog_Block_Product_Price.
  3. Inside this custom class, you defined a new method newPriceText().

The Issue: Method Visibility

The problem lies in how you’re calling the custom method from the template file.

In PHP, methods must be public to be accessible outside the class. Your current implementation has the newPriceText() method with no visibility specified, which means it’s private by default:

public function newPriceText()
{
    print_r('Testing Price Text');
}

To fix this, you need to make the newPriceText() method public so that it can be called from the template file.

The Solution: Updating the Method Visibility

Change your custom class definition and method declaration as follows:

<?php

class MyCompany_Catalog_Block_Product_Price extends Mage_Catalog_Block_Product_Price
{
    public function newPriceText()
    {
        print_r('Testing Price Text');
    }
}

By declaring the newPriceText() method as public, you ensure that it can be accessed directly from your template file.

The Layout XML Configuration

You also mentioned in a comment that you’re not sure how to write the layout XML for this. To call your custom block and method, you need to update the catalog product view layout:

<layout version="1.0">
    <catalog_product_view>
        <reference name="product.info.price">
            <action method="setTemplate">
                <template>your_module/price.phtml</template>
            </action>
        </reference>
    </catalog_product_view>
</layout>

Replace your_module with the actual module that contains your custom price template. This layout update tells Magento to use your custom price.phtml file for rendering product prices.

Conclusion

To successfully override the price text in Magento, follow these key steps:

  1. Create a new custom block class extending the core Mage_Catalog_Block_Product_Price.
  2. Define a public method (e.g., newPriceText()) to handle your custom price logic.
  3. Update the template file (price.phtml) to call this new method.
  4. Configure the layout XML to use your custom template for rendering product prices.

Remember, overriding core Magento files directly is generally discouraged due to upgrade issues and potential conflicts with updates. Always consider creating an extension that maintains a clear separation between your custom code and the core Magento files.

For more in-depth guides on Magento development best practices, be sure to check out our comprehensive tutorials at Laravel Company.

Happy coding!

Catalog Extensions Themes Pricing

Our network