Posted on 09/08/2022 08:11:24
Hi Nicolai,
Thanks a lot for helping with the base of the NotificationSubscriber, was something of that sort we were going to do.
But now that i think of it, it sort of "breaks" the whole meaning of drafts in the standard DW implementation, since it would load your lastest draft order if you emptied your cart before logging out, if you just saved your current cart as a draft and then logs out, or if you just completed your current cart and then logs out, since those scenarios leaves you with no "active" cart.
Which leads into another scenario with the dwapi with the whole talk of standard DW "active" cart.
When you get all your carts with the dwapi, you have no way of knowing if it's a draft or an "active" DW cart.
In the GET carts (/dwapi/ecommerce/carts/) request below here, i get two carts. Both are actual draft carts.
So if i log into the webshop, i'll have no current cart.
But when i get all carts for the user for our app, i can only use Modified as what i "think" might be the current webshop cart.
If we just always load the lastest modified cart, we'll have two different scenarios for our users, where on the webshop you have no cart, but the app loads your lastest edited draft cart.
So i think a solution could maybe be to extend the cart model with an "active" property, both in the UserCartsResponse model so you can see if the current user has an active cart, and which one it is, else you can create a new cart. And then in the OrderViewModel so you can change which cart is the "active" one from the dwapi.
But that would probably mean something have to change in standard DW to use the same logic with the "active" cart.
Since the only thing i've found that DW uses for selecting "active" cart is some sort of sessionid on the cart, but i'm not sure that's the only thing that get used.
EDIT: just a note on the above line i've made italic (doesn't seem it allows me to cross over text). I've been made aware that it seems to be stored in the AccessUser table in the AccessUserCartId column. Maybe that's something we can hook into? So another approach could be extending UserViewModel with an "ActiveCartSecret". That way you can get the information without checking through every order in /dwapi/ecommerce/carts/ for an "active" property (though it would still be a welcome change to have it labeled on there). Then you can just call /dwapi/ecommerce/carts/{secret} to check if the cart is still available. But there a "mismatch" with AccessUser storing it as Cart Id, and the dwapi needing the cart secret, but it still seems as a possible route to go aswell :)
Hope it makes sense :)
Best regards,
Mikkel Hammer