checkoutservice: empty cart after order
Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
parent
99cefc46c9
commit
f9fa569d41
2 changed files with 16 additions and 1 deletions
|
@ -96,6 +96,8 @@ func (cs *checkoutService) PlaceOrder(ctx context.Context, req *pb.PlaceOrderReq
|
||||||
return nil, status.Errorf(codes.Unavailable, "shipping error: %+v", err)
|
return nil, status.Errorf(codes.Unavailable, "shipping error: %+v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_ = cs.emptyUserCart(ctx, req.UserId)
|
||||||
|
|
||||||
orderResult := &pb.OrderResult{
|
orderResult := &pb.OrderResult{
|
||||||
OrderId: orderID.String(),
|
OrderId: orderID.String(),
|
||||||
ShippingTrackingId: shippingTrackingID,
|
ShippingTrackingId: shippingTrackingID,
|
||||||
|
@ -175,6 +177,19 @@ func (cs *checkoutService) getUserCart(ctx context.Context, userID string) ([]*p
|
||||||
return cart.GetItems(), nil
|
return cart.GetItems(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cs *checkoutService) emptyUserCart(ctx context.Context, userID string) error {
|
||||||
|
conn, err := grpc.DialContext(ctx, cs.cartSvcAddr, grpc.WithInsecure())
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not connect cart service: %+v", err)
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
if _, err = pb.NewCartServiceClient(conn).EmptyCart(ctx, &pb.EmptyCartRequest{UserId: userID}); err != nil {
|
||||||
|
return fmt.Errorf("failed to empty user cart during checkout: %+v", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (cs *checkoutService) prepOrderItems(ctx context.Context, items []*pb.CartItem, userCurrency string) ([]*pb.OrderItem, error) {
|
func (cs *checkoutService) prepOrderItems(ctx context.Context, items []*pb.CartItem, userCurrency string) ([]*pb.OrderItem, error) {
|
||||||
out := make([]*pb.OrderItem, len(items))
|
out := make([]*pb.OrderItem, len(items))
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{{ define "footer" }}
|
{{ define "footer" }}
|
||||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>
|
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>
|
||||||
<small class="text-muted mx-auto">This is a demo application. ({{$.session_id}})</small>
|
<small class="text-muted mx-auto">This is a demo application, not a real retail business. ({{$.session_id}})</small>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
Loading…
Reference in a new issue