Magento - how to hook into order reorder

Magento - how to hook into order reorder

September 9, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento - how to hook into order reorder

Hooking into Order Reorder in Magento: A Comprehensive Guide

As an experienced developer working on e-commerce platforms like Magento, you often face challenges when trying to integrate custom functionality into existing processes. One such common requirement is hooking into the order reorder process to add additional attributes or cross-references.

Understanding the Order Reorder Process

The order reorder feature in Magento is quite straightforward and is handled by the Abstract.php controller under the Sales module. Specifically, the reorderAction method is responsible for this functionality.

public function reorderAction()
{
    $quoteId = $this->getRequest()->getParam('quote_id');
    $quote = Mage::getModel('sales/quote')->load($quoteId);
    $cartHelper = Mage::helper('checkout/cart');

    foreach ($quote->getItemsCollection() as $item) {
        if ($item->isDeleted()) continue;
        if (!$item->hasRequiredOption()) {
            Mage::throwException(Mage::helper('checkout')->__('Please select required options for some product(s).'));
        }
        $cartHelper->addOrderItem($item, null);
    }

    // Clear cart helper errors
    $cartHelper->getCart()->getQuote()->collectTotals();
    $this->_redirect('*/checkout/cart');
}

As you can see, the reorderAction method takes the quote ID as a parameter, loads the corresponding quote object, and then iterates through each item in the quote. It adds each valid item to the cart using the addOrderItem method of the checkout/cart helper.

Hooking into the Reorder Process

You’re right in your assumption that modifying the core controller directly is not a recommended approach. This would require you to copy the entire Abstract.php file and make changes locally, which can lead to maintenance issues when Magento updates occur.

Using Event Observers for Clean Integration

A more elegant solution involves using event observers and the Observer pattern to hook into this process. Magento’s event system allows you to observe specific events and execute custom logic in response.

For the order reorder functionality, we are interested in the sales_order_place_after event. This event is fired after an order has been placed successfully, which includes the case of a reordered item being added to the cart before the final placement.

Here’s how you can create a custom module and define an observer for this event:

  1. Create your local.xml file in <your_module>/etc/
<config>
    <modules>
        <Your_Module_Model_Namespace>
            <version>0.1.0</version>
        </Your_Module_Model_Namespace>
    </modules>
    <global>
        <helpers>
            <your_module>
                <class>Your_Module_Helper_Data</class>
            </your_module>
        </helpers>
        <events>
            <sales_order_place_after>
                <observers>
                    <your_module>
                        <type>singleton</type>
                        <class>your_module/observer</class>
                        <method>addOriginalOrderIdToQuoteItem</method>
                    </your_module>
                </observers>
            </sales_order_place_after>
        </events>
    </global>
</config>
  1. Create your Observer class under <your_module>/Model/Observer.php:
class Your_Module_Model_Observer
{
    public function addOriginalOrderIdToQuoteItem($observer)
    {
        $quote = $observer->getEvent()->getQuote();
        foreach ($quote->getItemsCollection() as $item) {
            if ($item->isDeleted()) continue;
            // Add your logic here to associate the original order ID with the reordered item
            // Example: $item->setData('original_order_id', $originalOrderId);
        }
    }
}
  1. Create a helper class under <your_module>/Helper/Data.php for any necessary functions:
class Your_Module_Helper_Data extends Mage_Core_Helper_Abstract
{
    // Add your helper methods here if needed
}

Remember to replace Your_Module_Model_Namespace, your_module, Observer, and other placeholders with the appropriate values for your custom module.

Including the Original Order ID

To include the original order ID in the reordered item, you would need to have a mechanism to associate the quote items with their corresponding original orders. This could involve maintaining a mapping table or using additional attributes on the quote or order item objects.

Once you have identified the original order for each reordered item, you can set an attribute containing the original_order_id in the observer method:

$item->setData('original_order_id', $originalOrderId);

Conclusion

Hooking into the order reorder process in Magento requires a clear understanding of the existing functionality and careful integration using event observers. By utilizing the Observer pattern and defining an event listener, you can cleanly extend the core behavior without modifying the controllers directly.

Remember to test your implementation thoroughly to ensure that it works correctly with different scenarios and edge cases related to order reordering.

For more detailed information on Magento development best practices and common challenges faced by developers like yourself, feel free to explore our comprehensive guides at Laravel Company. We specialize in providing high-quality tutorials and resources for both beginners and experienced professionals in the Laravel ecosystem.

Checkout Catalog Extensions Orders

Our network