STORY (Sad): I'v been assigned to fix this bug we had for a long time, unfortunately the module was written 2 years back by a Dev who already left the company :(
FUNCTION : Module is develop to fetch some order/customer details from Magento and write them to few other custom tables, then a different system in production will fetch them to make and deliver all orders to their customers.
HOW : Module has a Model extends from Mage_Sales_Model_Order
and a method _afterSave()
which overrides Mage_Sales_Model_Order::_afterSave()
. This method includes all code that writes to these additional tables.
BUG : At some odd occasions, some orders has additional order line items, as an example in one scenario it had an order that has 3 order line items, when the real order had only 1 order line item. After doing some deep digging found that one of the order lines were from a old order by the same customer, and the other additional line item was a duplicate of the real order line item.
CLUES : Tried so many things and few clues I manage to find, I can see _afterSave
was getting called twice when I was debugging through xDebug. But couldn't find where it get called twice.
Tried to re-create the issue by my safe so many time but every thing works fine in dev environment as it always does.
We use $this->getAllItems()
to get the order item data.
HELP :This happens in a really random manner, Just looking for help to get my self to look different avenues, coz I know no one will be able to provide me with a total solution. Some guidance please, since I have ran in to few rabbit wholes already.
Thanx Heaps!!! If you need more details, please let me know.