16

During the checkout process even if customer selects existing address form the drop-down the customer_address entity is being re-saved. Any idea what for?

Update:

It starts at Mage_Checkout_Model_Type_Onepage::saveOrder where the following code is executed:

$service = Mage::getModel('sales/service_quote', $this->getQuote());
$service->submitAll();

This submitAll calls Mage_Sales_Model_Service_Quote::submitOrder which executes the following:

$transaction->save();

This method loops through all objects of the quote(?) and saves them.

Update:

The most disgusting thing is that they are doing it for all addresses customer has. So if your visitor get 10 addresses saved in the address book all of them will be re-saved during checkout. Don't wonder why it is the most resource consuming part of Magento.

8
  • In the customer_address_entity or in the quote? May 21, 2014 at 11:44
  • Sorry, not sure what you mean. The customer_address entity is being saved during placing the order. No connection to quote. May 21, 2014 at 11:46
  • 1
    Can you provide the code that does this? It would save me the trouble of searching
    – Marius
    May 21, 2014 at 11:57
  • Updated the question. May 21, 2014 at 12:29
  • @Tim I guess the answer cause they did not think it through would be an acceptable answer ;) My guess is that they did'nt want to check if the address exists so it would be easier/lazier to save everything. Only a guess though May 21, 2014 at 16:45

3 Answers 3

6

Usualy, unless data has changed on a model, calling save() on it will not cause the model to be re-saved.
This must have been the assumption during implementing the logic this way.

However, since the quote address model's method _beforeSave() sets the quote ID, the customer ID, plus possibly the customer address ID and the same_as_billing property via the _populateBeforeSaveData() method, the protection against unnecessary saving is circumvented.

An easy fix in the method populateBeforeSaveData() would be to check if the values about to be set on the address model already present on the current model with the same value.

Fortunately, quote addresses are stored in a flat table, which means the save is fairly efficient. And except for some B2B stores I haven't experienced customers having more then a couple of addresses.

2

I would hazard a guess that this was not thought through.

Maybe it was thought that rather than updating any new address plus any change in default billing and shipping address it would be easier just to save everything, since people wont have that many addresses and the checkout is already slow people wont notice....much.

Note: this is just an idea but I thought it worth sharing, also I can imagine myself making the same assumptions :(

0

address save during checkout is done by _afterSave()-Method in customer resource model.

protected function _afterSave(Varien_Object $customer)
{
    $this->_saveAddresses($customer);
    return parent::_afterSave($customer);
}

as i remember customer model get saved during order placement.

cheers

4
  • Yes, that was clear. The question is "What for?". May 21, 2014 at 15:51
  • @Tim: general i think. No observably reason for checkout atm. May 21, 2014 at 15:56
  • @Tim: For example saveAction in admin needs this behavior. May 21, 2014 at 16:02
  • What for does it need it? May 21, 2014 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.