From 1522f4cd5b61efe7cc4fde394a224794634eab4c Mon Sep 17 00:00:00 2001 From: Kezia Sulami Date: Wed, 5 Aug 2020 10:22:58 +0700 Subject: [PATCH] Fix multiply item price by quantity --- src/checkoutservice/main.go | 3 ++- src/frontend/handlers.go | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/checkoutservice/main.go b/src/checkoutservice/main.go index db78a5f..e7c7a0f 100644 --- a/src/checkoutservice/main.go +++ b/src/checkoutservice/main.go @@ -233,7 +233,8 @@ func (cs *checkoutService) PlaceOrder(ctx context.Context, req *pb.PlaceOrderReq Nanos: 0} total = money.Must(money.Sum(total, *prep.shippingCostLocalized)) for _, it := range prep.orderItems { - total = money.Must(money.Sum(total, *it.Cost)) + multPrice := money.MultiplySlow(*it.Cost, uint32(it.GetItem().GetQuantity())) + total = money.Must(money.Sum(total, multPrice)) } txID, err := cs.chargeCard(ctx, &total, req.CreditCard) diff --git a/src/frontend/handlers.go b/src/frontend/handlers.go index 10fff5f..751543f 100644 --- a/src/frontend/handlers.go +++ b/src/frontend/handlers.go @@ -333,7 +333,8 @@ func (fe *frontendServer) placeOrderHandler(w http.ResponseWriter, r *http.Reque totalPaid := *order.GetOrder().GetShippingCost() for _, v := range order.GetOrder().GetItems() { - totalPaid = money.Must(money.Sum(totalPaid, *v.GetCost())) + multPrice := money.MultiplySlow(*v.GetCost(), uint32(v.GetItem().GetQuantity())) + totalPaid = money.Must(money.Sum(totalPaid, multPrice)) } currencies, err := fe.getCurrencies(r.Context()) @@ -415,7 +416,7 @@ func renderHTTPError(log logrus.FieldLogger, r *http.Request, w http.ResponseWri "status": http.StatusText(code), }); templateErr != nil { log.Println(templateErr) - } + } } func currentCurrency(r *http.Request) string {