2

Situation

A payment provider redirects customers back to Magento after a successful payment. At the same time the payment provider also sends a push to Magento. Both of these actions result in the same order being loaded, data being changed and the order being saved.

Problem

The above actions both load the same order, process different data and save the order. When the customer gets back to Magento at the same time as the push is sent the process that saves last overwrites the earlier process' already saved data.

  1. flow a: load order
  2. flow b: load order
  3. flow a: process order (set status 'a')
  4. flow b: process order (doesn't change status)
  5. flow a: save order (order now correctly has status 'a')
  6. flow b: save order (and overwrite the order data saved at step 5, reverting the status back to the old status)

Tried solutions

I have tried the following solutions without success.

  • Putting a sleep() in the push handling, this does not work due to the random timing of the user redirect. Anywhere between 1 second and 30 seconds of sleep and this problem still happens.
  • Reloading order object before save, this means I have to do all processing again and is basically an expensive sleep()

Question

The only way I can think of is setting some kind of flag file on order load and removing it on order save which would stop anything from loading the order while it's being processed. I am afraid this would cause problems elsewhere and is generally not a neat solution.

Is there a way to ensure that both sets of order data are processed without anything being lost?

1 Answer 1

1

Before flow b saves the order, try this:

$order->unsetData('state');

I haven't tested this, but in theory it should prevent the state from being included in the SET clause of the final query, though it might just delete it instead. Give it a try and let me know how it works.

Your Answer

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

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