Magento 2 orderFactory not found in vendor directory

Magento 2 orderFactory not found in vendor directory

October 13, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento 2 orderFactory not found in vendor directory

Magento 2 OrderFactory Not Found in Vendor Directory: Debugging and Solution

Introduction

I recently encountered an issue while working on a payment gateway extension for Magento 2 (version 2.3.4). The error message was “Call to a member function setTransactionId() on null,” which seemed like a symptom of a deeper problem with the order object not being properly created or loaded.

Analyzing the Code Issue

Let’s first look at the relevant portion of the affected code:

public function _prepareLayout()
{
    $method_data = array();
    $order = $this->orderFactory->create()->load($this->getParentId());
    if ($order) {
        $payment = $order->getPayment();
        // The error is thrown here (" Call to a member function setTransactionId() on null")
        $payment->setTransactionId("-1");
        ...
        $payment->save();
        $order->save();

        ...
    }
}

The issue lies in the line $payment = $order->getPayment();. My IDE marks this method as not found, suggesting that the order object is not being created correctly or that the required dependencies are missing.

The Sales Model Directory Problem

Upon further investigation, I discovered that the folder ‘Sales/Model’ does not contain an orderFactory.php file. This raised concerns about whether the file was missing or deprecated in my Magento 2 version (2.3.4).

Several modules, including Magento’s official PayPal PGM extension, use this file and create orders similarly to the above code example:

$order = $this->orderFactory->create()->load($incrementId);

The question remained: Is the OrderFactory.php file missing in my installation, or has it been replaced by a different approach in more recent versions of Magento 2?

Debugging and Solution Approach

To resolve this issue, I decided to follow these troubleshooting steps:

  1. Review the Magento 2 Documentation: I checked the official Magento 2 documentation for any updates regarding the OrderFactory.php file or changes to order creation methods in version 2.3.4.

  2. GitHub Repository Comparison: I compared the GitHub repository of my current Magento 2 installation with a clean, fresh installation of the same version (2.3.4) to identify any discrepancies that might have caused the missing OrderFactory.php file.

  3. Extension Compatibility Check: Since I was working inside a Docker container, I ensured that all required dependencies and extensions were installed correctly and compatible with Magento 2.3.4.

Conclusion

After thorough analysis and debugging, it appears that the issue might be related to a configuration inconsistency or missing dependency in my current environment. The OrderFactory.php file is indeed present in the official Magento 2 repository for version 2.3.4.

To resolve this:

  • Ensure your Magento 2 installation is clean and up-to-date.
  • Verify that all required extensions are installed correctly and compatible with your version (2.3.4).
  • Double-check your configuration files for any inconsistencies or misconfigurations.

If the issue persists, I recommend reaching out to Laravel Company for expert Magento 2 support and consultation to diagnose and resolve this problem effectively in your specific environment.

Magento 2 Extensions Themes Orders

Our network