From b80a75188dd65f2e402e6d2c720e750737ab3be3 Mon Sep 17 00:00:00 2001 From: Ivan Chepurnyi Date: Thu, 19 Jul 2012 18:29:52 +0300 Subject: [PATCH 1/4] Fixed non reasonable usage of memory for collection, where possible to use more appropriate load() method of the model. --- .../Mage/Adminhtml/controllers/Sales/OrderController.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php index e891015d4e8d0..7ad5f479dc220 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php @@ -721,10 +721,7 @@ public function transactionsAction() public function addressAction() { $addressId = $this->getRequest()->getParam('address_id'); - $address = Mage::getModel('Mage_Sales_Model_Order_Address') - ->getCollection() - ->addFilter('entity_id', $addressId) - ->getItemById($addressId); + $address = Mage::getModel('Mage_Sales_Model_Order_Address')->load($addressId); if ($address) { Mage::register('order_address', $address); $this->loadLayout(); From cd665b12ef70709f5eaa5e2c45d0d48ec692deda Mon Sep 17 00:00:00 2001 From: Ivan Chepurnyi Date: Thu, 19 Jul 2012 20:47:47 +0300 Subject: [PATCH 2/4] Added fix for loaded object check, to prevent viewing form if address not found. --- .../core/Mage/Adminhtml/controllers/Sales/OrderController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php index 7ad5f479dc220..fd63ffd09a6d3 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php @@ -722,7 +722,7 @@ public function addressAction() { $addressId = $this->getRequest()->getParam('address_id'); $address = Mage::getModel('Mage_Sales_Model_Order_Address')->load($addressId); - if ($address) { + if ($address->getId()) { Mage::register('order_address', $address); $this->loadLayout(); // Do not display VAT validation button on edit order address form From ae10d80994cce3e75b80ca1edf348e40edd1efe9 Mon Sep 17 00:00:00 2001 From: Ivan Chepurnyi Date: Tue, 24 Jul 2012 19:33:45 +0300 Subject: [PATCH 3/4] Fixed core issue related to invalid totals sorting in the quote. The problem is visible if you have additional custom totals that need to be placed in between core ones. --- .../core/Mage/Sales/Model/Config/Ordered.php | 56 +++++++++++-------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/app/code/core/Mage/Sales/Model/Config/Ordered.php b/app/code/core/Mage/Sales/Model/Config/Ordered.php index bd89d332946a8..4e72804e803ec 100644 --- a/app/code/core/Mage/Sales/Model/Config/Ordered.php +++ b/app/code/core/Mage/Sales/Model/Config/Ordered.php @@ -140,36 +140,46 @@ protected function _getSortedCollectorCodes() $element = current($configArray); if (isset($element['sort_order'])) { uasort($configArray, array($this, '_compareSortOrder')); + $sortedCollectors = array_keys($configArray); } else { - foreach ($configArray as $code => $data) { - foreach ($data['before'] as $beforeCode) { - if (!isset($configArray[$beforeCode])) { + $sortedCollectors = array_keys($configArray); + // Move all totals with before specification in front of related total + + foreach ($configArray as $code => &$data) { + foreach ($data['before'] as $positionCode) { + if (!isset($configArray[$positionCode])) { continue; } - $configArray[$code]['before'] = array_unique(array_merge( - $configArray[$code]['before'], $configArray[$beforeCode]['before'] - )); - $configArray[$beforeCode]['after'] = array_merge( - $configArray[$beforeCode]['after'], array($code), $data['after'] - ); - $configArray[$beforeCode]['after'] = array_unique($configArray[$beforeCode]['after']); - } - foreach ($data['after'] as $afterCode) { - if (!isset($configArray[$afterCode])) { - continue; + if (!in_array($code, $configArray[$positionCode]['after'], true)) { + // Also add additional after condition for related total, + // to keep it always after total with before value specified + $configArray[$positionCode]['after'][] = $code; } - $configArray[$code]['after'] = array_unique(array_merge( - $configArray[$code]['after'], $configArray[$afterCode]['after'] - )); - $configArray[$afterCode]['before'] = array_merge( - $configArray[$afterCode]['before'], array($code), $data['before'] - ); - $configArray[$afterCode]['before'] = array_unique($configArray[$afterCode]['before']); + $currentPosition = array_search($code, $sortedCollectors, true); + $desiredPosition = array_search($positionCode, $sortedCollectors, true); + if ($currentPosition > $desiredPosition) { + // Only if current position is not corresponding to before condition + array_splice($sortedCollectors, $currentPosition, 1); // Removes existent + array_splice($sortedCollectors, $desiredPosition, 0, $code); // Add at new position + } + } + } + // Sort out totals with after position specified + foreach ($configArray as $code => &$data) { + $maxAfter = null; + $currentPosition = array_search($code, $sortedCollectors, true); + + foreach ($data['after'] as $positionCode) { + $maxAfter = max($maxAfter, array_search($positionCode, $sortedCollectors, true)); + } + + if ($maxAfter !== null && $maxAfter > $currentPosition) { + // Moves only if it is in front of after total + array_splice($sortedCollectors, $maxAfter + 1, 0, $code); // Add at new position + array_splice($sortedCollectors, $currentPosition, 1); // Removes existent } } - uasort($configArray, array($this, '_compareTotals')); } - $sortedCollectors = array_keys($configArray); if (Mage::app()->useCache('config')) { Mage::app()->saveCache(serialize($sortedCollectors), $this->_collectorsCacheKey, array( Mage_Core_Model_Config::CACHE_TAG From 48fdf7dd19487a306cceb3402400e068bea67fb5 Mon Sep 17 00:00:00 2001 From: Ivan Chepurnyi Date: Tue, 24 Jul 2012 20:01:01 +0300 Subject: [PATCH 4/4] ! Revert changes from app/code/core/Mage/Sales/Model/Config/Ordered.php, to move them into separate branch --- .../core/Mage/Sales/Model/Config/Ordered.php | 56 ++++++++----------- 1 file changed, 23 insertions(+), 33 deletions(-) diff --git a/app/code/core/Mage/Sales/Model/Config/Ordered.php b/app/code/core/Mage/Sales/Model/Config/Ordered.php index 4e72804e803ec..bd89d332946a8 100644 --- a/app/code/core/Mage/Sales/Model/Config/Ordered.php +++ b/app/code/core/Mage/Sales/Model/Config/Ordered.php @@ -140,46 +140,36 @@ protected function _getSortedCollectorCodes() $element = current($configArray); if (isset($element['sort_order'])) { uasort($configArray, array($this, '_compareSortOrder')); - $sortedCollectors = array_keys($configArray); } else { - $sortedCollectors = array_keys($configArray); - // Move all totals with before specification in front of related total - - foreach ($configArray as $code => &$data) { - foreach ($data['before'] as $positionCode) { - if (!isset($configArray[$positionCode])) { + foreach ($configArray as $code => $data) { + foreach ($data['before'] as $beforeCode) { + if (!isset($configArray[$beforeCode])) { continue; } - if (!in_array($code, $configArray[$positionCode]['after'], true)) { - // Also add additional after condition for related total, - // to keep it always after total with before value specified - $configArray[$positionCode]['after'][] = $code; - } - $currentPosition = array_search($code, $sortedCollectors, true); - $desiredPosition = array_search($positionCode, $sortedCollectors, true); - if ($currentPosition > $desiredPosition) { - // Only if current position is not corresponding to before condition - array_splice($sortedCollectors, $currentPosition, 1); // Removes existent - array_splice($sortedCollectors, $desiredPosition, 0, $code); // Add at new position - } + $configArray[$code]['before'] = array_unique(array_merge( + $configArray[$code]['before'], $configArray[$beforeCode]['before'] + )); + $configArray[$beforeCode]['after'] = array_merge( + $configArray[$beforeCode]['after'], array($code), $data['after'] + ); + $configArray[$beforeCode]['after'] = array_unique($configArray[$beforeCode]['after']); } - } - // Sort out totals with after position specified - foreach ($configArray as $code => &$data) { - $maxAfter = null; - $currentPosition = array_search($code, $sortedCollectors, true); - - foreach ($data['after'] as $positionCode) { - $maxAfter = max($maxAfter, array_search($positionCode, $sortedCollectors, true)); - } - - if ($maxAfter !== null && $maxAfter > $currentPosition) { - // Moves only if it is in front of after total - array_splice($sortedCollectors, $maxAfter + 1, 0, $code); // Add at new position - array_splice($sortedCollectors, $currentPosition, 1); // Removes existent + foreach ($data['after'] as $afterCode) { + if (!isset($configArray[$afterCode])) { + continue; + } + $configArray[$code]['after'] = array_unique(array_merge( + $configArray[$code]['after'], $configArray[$afterCode]['after'] + )); + $configArray[$afterCode]['before'] = array_merge( + $configArray[$afterCode]['before'], array($code), $data['before'] + ); + $configArray[$afterCode]['before'] = array_unique($configArray[$afterCode]['before']); } } + uasort($configArray, array($this, '_compareTotals')); } + $sortedCollectors = array_keys($configArray); if (Mage::app()->useCache('config')) { Mage::app()->saveCache(serialize($sortedCollectors), $this->_collectorsCacheKey, array( Mage_Core_Model_Config::CACHE_TAG