cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

I have created a cart with products inside a webservice . How do I generate storefront url to show the cart page to user with this cart?

Former Member

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member387866
Active Contributor
0 Likes

Hi Aditi,

Surely the cart is a secured area, unless you are talking about a Public Gift List for a wedding.

In the OOTB Storefront, the Cart Page being a secured area, the user will need to login. So the standard URL to the Cart page will be sufficient.

If you're using OCC v2, the Sample Flows can guide you.

If you're talking about a custom storefront, the WebService API - Reference documentation there isn't a direct way to get a User's Carts. So we'll have to write our own.

From the logged in User use:

 @GetMapping("user/{userId}/cart")
 public CartModel getLastModifiedCartForUser(@PathVariable String userId) {
   return userService.getUserForUID(userId)
            .getCarts()
            .stream()
            .sorted(Comparator.comparing(CartModel::getModifiedtime)
                .reversed())
            .collect(Collectors.toList())
            .first();
 }

Obviously, lastModifiedtime presents it's own problems, as an older User's Cart could've been modified by a CronJob. But this is just a trivial example.

JavaDoc: userService.getUserforUID | userModel.getCarts | CartModel

Regards,
Luke

Former Member
0 Likes

Hello Luke,

Thanks for the response. But we do not have user details with us . Its for anonymous users.