Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento: Why load a collection instead of loading an address directly?

Tags:

patch

magento

We received the following Magento core patch:

Index: app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php
===================================================================
--- app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php
    app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php  (working copy)
@@ -718,6 +718,7 @@
     $addressId = $this->getRequest()->getParam('address_id');
     $address = Mage::getModel('sales/order_address')
         ->getCollection()
+            ->addFilter('entity_id', $addressId)
         ->getItemById($addressId);
     if ($address) {
         Mage::register('order_address', $address);

In my opinion this is equivalent to

$addressId = $this->getRequest()->getParam('address_id');
$address = Mage::getModel('sales/order_address')->load($addressId);
if ($address->getId()) {
    Mage::register('order_address', $address);

What is the advantage of the original patch over my solution?

EDIT:

The explanation from the support was:

[...] this decision was by design and appropriate when creating this code.

like image 886
Alex Avatar asked Dec 05 '25 14:12

Alex


1 Answers

The only reason for that kind of patch seems to be to edit a minimal number of lines.

In Magento2 this is implemented in the second way:

$address = Mage::getModel('Mage_Sales_Model_Order_Address')->load($addressId);
like image 184
Alex Avatar answered Dec 10 '25 08:12

Alex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!