Magento custom shipping module - Fatal error: Call to a member function setStore()

Magento custom shipping module - Fatal error: Call to a member function setStore()

October 4, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento custom shipping module - Fatal error: Call to a member function setStore()

Magento Custom Shipping Module: Resolving the “Call to a member function setStore() on a non-object” Error

Introduction

If you’re working with Magento 1.9.0.1 and encountering the error “Fatal error: Call to a member function setStore() on a non-object in /var/www/html/includes/src/Mage_Shipping_Model_Shipping.php on line 424” while implementing a custom shipping module, you’re not alone. Let’s dive into a comprehensive solution for this issue.

The Challenge

The user mentioned that they followed the official Magento tutorial step-by-step to create a custom shipping module for Magento. However, when deployed in a production environment, an error occurred on the frontend during the cart process.

The error message suggests that there might be an issue with the store configuration or the way the shipping model is being initialized.

Understanding the Error

The error occurs due to an object not being initialized properly before calling the setStore() method. This typically happens when the store object isn’t set correctly during the initialization of a class in Magento’s singleton pattern.

Debugging Steps Already Attempted

Before we proceed with the solution, let’s acknowledge the debugging steps the user has already attempted:

  1. Clearing cache: Magento heavily relies on caching for performance optimization. Clearing the cache can often resolve issues related to configuration changes and module enablement.

  2. Disabling and enabling the compiler: The Magento compiler optimizes code execution by pre-compiling PHP classes into a single file. Enabling/disabling and recompiling it can help resolve class-related issues.

  3. Compilation via terminal: Recompiling the codebase ensures that all changes are reflected in the compiled files, which could potentially solve any misalignment between configuration and actual implementation.

The Solution

Step 1: Verify Configuration XML Files

Ensure that your app/etc/modules/Company_Module.xml and app/code/local/Company/Module/etc/config.xml files have the correct syntax and definitions. Here are some key points to verify:

  • In your config.xml, ensure that you’ve defined your module version correctly under <modules>.
<Company_Module>
  <module>0.0.1</module>
</Company_Module>
  • Check if there are any typos or incorrect paths in the configuration files.

Step 2: Double-Check Your Carrier Model

Review your app/code/local/Company/Module/Model/carrier.php file to ensure that you’ve implemented the necessary methods and interfaces correctly:

class Company_Module_Model_Carrier extends Mage_Shipping_Model_Carrier_Abstract implements Mage_Shipping_Model_Carrier_Interface
{
  // Your code here...
}

Ensure that your carrier class extends Mage_Shipping_Model_Carrier_Abstract and implements the Mage_Shipping_Model_Carrier_Interface.

Step 3: Verify Store Context

The error suggests a problem with the store context during object initialization. To resolve this:

  1. Open your app/code/local/Company/Module/Model/carrier.php file.

  2. Locate the constructor of your carrier model and ensure that you’re properly setting the store context using Magento’s singleton pattern. Here’s an example:

public function __construct()
{
    $this->setStore(Mage::app()->getStore());
}
  1. If the constructor is already defined, double-check if the Mage::app()->getStore() call returns a valid store object.

Step 4: Check for Missing Dependencies

Ensure that all necessary dependencies are met in your configuration files:

  • In your config.xml, check if you’ve correctly specified the dependencies under <depends> in the <modules> section.
<Company_Module>
  <active>true</active>
  <codePool>local</codePool>
  <depends>
    <Mage_Shipping />
  </depends>
</Company_Module>
  • In your system.xml, verify that all the necessary system configuration fields are defined correctly.

Step 5: Recompile and Clear Cache

After making any necessary changes, ensure to:

  1. Run the Magento compiler via the command line using php -f shell/compiler.php.

  2. Clear the cache by deleting the contents of your var/cache folder or running the index.php?action=clearCache URL.

Conclusion

Resolving the “Call to a member function setStore() on a non-object” error in Magento typically involves double-checking your configuration files, verifying the store context during object initialization, and ensuring all necessary dependencies are met. By following this comprehensive guide and the debugging steps outlined above, you should be able to resolve this issue effectively.

Remember that working with Magento requires a deep understanding of its inner workings and proper implementation of the singleton pattern for class initialization.

For more in-depth discussions on Magento development best practices and advanced techniques, consider exploring our blog where we delve into various aspects of e-commerce development using Laravel and other technologies.

Magento 1 Checkout Catalog Cache

Our network