How to fix broken or slow Sales Order Address editing via Magento Admin

We recently came upon an issue in a Magento 1.5* instance where any attempt to edit the customer address from within the Sales Order screen in Magento Admin would cause a "HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request." type of error. This occurred when the client started going over approx 65536 orders. Alarm bells start to ring on that number.

Viewing the server logs (/var/log/messages) showed "ALERT - script tried to increase memory_limit to 3145728000 bytes which is above the allowed value". Obviously we had by this stage increased memory well above the norm to diagnose. In this case Suhosin was preventing the script from increasing the memory limit, but that's not the cause of the problem. Any memory usage above 1GB indicates something is seriously wrong.

The problem turns out to be a core bug in Magento (that btw still isn't fixed), and is due to the way in which Magento searches for addresses in app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.

The change is a simple one. Create a local override for app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php in app/code/local/Mage/Adminhtml/controllers/Sales/OrderController.php (by creating this new directory and copyingOrderController.php into that).

Change app/code/local/Mage/Adminhtml/controllers/Sales/OrderController.php approx line 710 from

/**
* Edit order address form
*/
public function addressAction()
{
$addressId = $this->getRequest()->getParam('address_id');
$address = Mage::getModel('sales/order_address')
->getCollection()
->getItemById($addressId);
if ($address) {
Mage::register('order_address', $address);
$this->loadLayout();
$this->renderLayout();
} else {
$this->_redirect('*/*/');
}
}

to

/**
* Edit order address form
*/
public function addressAction()
{
$addressId = $this->getRequest()->getParam('address_id');
//$address = Mage::getModel('sales/order_address')
// ->getCollection()
// ->getItemById($addressId);

// bugfix
$address = Mage::getModel('sales/order_address')->load($addressId);
if ($address) {
Mage::register('order_address', $address);
$this->loadLayout();
$this->renderLayout();
} else {
$this->_redirect('*/*/');
}
}

Thanks to Aaron Bonner and Wojciech Naruniec for the bugfix!

  • 24 Users Found This Useful
Was this answer helpful?

Related Articles

How to upgrade Magento 1.3 to 1.4.1.1

The Magento 1.3 to 1.4.1.1 upgrade is quite complex, as there are many changes to the database...

Error - Cannot edit customers / Cannot load configuration for payment method "amazonpayments_asp" after upgrading to 1.4.2.0

After upgrading to Magento 1.4.2.0, you may experience dificulty in editing customer information...

How do I make my Magento site temporarily unavailable (put into maintenance mode)?

There may be times when you need to perform an upgrade and don't want your website to be accessed...

Bugfix - Magento 1.4.2.0 search not working properly / showing same results for all searches

If you are having problems with your search after upgrading to 1.4.2.0, ensure that you have...

Path path/example.csv is not available and cannot be used

This is most likely due to your export path residing outside of the var/ directory. If you...