In CommerceBuilder.Services.OrderStatusService, method UpdateInventory(Order, OrderStatus), line 157 of build 6169 I have encountered the following issue:
This line executes a HQL Query against the ac_OrderItems table that updates the inventory status of the order's items. However, since this is being executed as a direct HQL query, the OrderItem objects in memory become stale. Any code that uses the same Order object reference passed to this method and accesses its Items collection is working with objects that are not synchronized with the database. An obvious workaround is to reload the items collection in the client code, but client code does not not know that this is necessary until encountering the problem.
Suggested Change:
a) Modify line 157 so that after NHibernateHelper.CreateSQLQuery executes the update, a call to reload the OrderItem collection occurs.
b) Modify line 157 to not use NHibernateHelper.CreateSQLQuery, but rather iterate over the existing collection, updating each item and then save the collection.
EDIT: Upon further investigation, this may not be the issue after all. What I've noticed instead is that setting the inventory action to Destock on the Order Placed event has no effect. This seems to be because when StoreEventEngine.UpdateOrderStatus is called during the OrderPlaced event, the status does not actually update since the status has not changed from its initial value. I mistakenly thought the order item objects were stale since their InventoryStatuses were not set to Destocked after the OrderPlaced event completed. This is still a bug in my opinion as the expected behavior upon setting the inventory action for an Order Status would be that that action would occur, but it does not when that status is the initial status.
Bug in OrderStatusService?
- ForumsAdmin
- AbleCommerce Moderator
- Posts: 399
- Joined: Wed Mar 13, 2013 7:19 am
Re: Bug in OrderStatusService?
Order status service was one the complicated pieces of code and difficult to get right because of all the different places from where order status could get updated. We believe currently it is working as intended, but since you have an opinon that the behavior should be different in a certain situation, it would be helpful if you can give us an example and help us recreate the situation in practice, and let us know both the actual result and the expected result. We can then update the code accordingly if it makes good sense.