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

  • 24

We 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, 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!


Was this answer helpful?

« Back