in order/utils/orders.py [0:0]
def getOrderItemsForOrder(orderId):
''' get order items and products associated with the order (also calculates total price)
params:
orderId: order id
returns:
dict: dict containing list of order items, and total price and count
'''
orderItems = OrderItem.objects.filter(order_id=orderId)
orderItems_list = []
totalPrice = 0
totalItems = 0
for item in orderItems:
product = Product.objects.filter(id=item.product_id).values()[0]
totalPrice += product["amount"] * item.quantity
totalItems += item.quantity
orderItems_list.append(
{
**{
"quantity": item.quantity,
"price_for_item": product["amount"] * item.quantity,
},
**product,
}
)
return {
"items": orderItems_list,
"total_price": totalPrice,
"total_items": totalItems,
}