I've a product attribute "Pending Shipping quantity" available for all products. It value will be counted based on Order status. If an order is placed for product having SKU 100 and order state is processing, Pending shipping quantity of this product will be the quantity ordered.
So, for SKU 100, if there is an order in processing state, the quantity ordered in that order will be the Pending shipping quantity.( If same product is available in another order in processing state, Pending shipping quantity will be the sum of the quantity of product ordered in both the orders).
Pending shipping quantity should decrease if the order status changes.
What should be the best approach to achieve it?
Possibility 1:
- Use observer method
sales_order_place_after
orsales_order_save_after
and increase Pending shipping quantity when state changes to processing. - Use observer method
sales_order_save_after
and decrease Pending shipping quantity if state change from processing to something else.
Possibility 2:
Get sales order collection filtered by state processing. Get all items attached to these orders and based on ordered quantity Pending shipping quantity.Though this process looks a bit more complex.
Is there any other way to achieve it keeping performance in mind?