Hey all. Complicated one here.
a) I'm logged into episerver so the basket created within episerver commerce is under the logged in user
b) going to a basket page, the controller code can access the current basket using the name "Default"
c) Issue is, the page uses JQuery posts to add to the basket (simple method in the controller with the attribute of post). This is not working as the post method, when getting the current basket comes back with nothing. This is using the same code as the controller code.
d) the same issue also occurs when reading the basket after the page has loaded. The solution i'm working with does a GET after the page load using Jquery to get the current cart. If I'm logged in, the cart comes back as blank, but on the controller method for page load say Index() the cart object is accessable.
This looks to me like an authentication issue since Service API was added to the project.
If I log out of Episerver and use an anomy basket, the JQuery posts all work fine.
Sorry, version of episerver = CMS.Core:9.12.0 Commerce.Core:9.19
Do you see any issue in the browser console (Network tab) or in the server site (debugger attached)?
Hello. I have done some decompiling of the CartHelper and I think the orderform is not being created?
/// Loads the cart. The cart is loaded from current http context if one is present.
///<param name="name">The name.</param>
///<param name="userId">The user id.</param>
///<param name="marketId">The market id.</param>
protectedvirtualvoid LoadCart(string name, Guid userId, MarketId marketId)
Cart cart = OrderContext.Current.GetCart(name, userId, marketId);
if (string.IsNullOrEmpty(cart.CustomerName) || cart.CustomerName.Equals(SecurityContext.Anonymous, StringComparison.OrdinalIgnoreCase) && PrincipalInfo.CurrentPrincipal.Identity.IsAuthenticated)
cart.CustomerName = PrincipalInfo.CurrentPrincipal.Identity.Name;
OrderForm orderForm = cart.OrderForms.FirstOrDefault<OrderForm>();
if (orderForm == null)
orderForm = cart.OrderForms.AddNew();
orderForm.Name = cart.Name;
this._Cart = cart;
Perhaps this line
If this returns false then no order form is added.
But again, this most likely is a red herring as getting the cart works fine on a controller normal GET method. Its only when jquery accesses an endpoint it does not work...
Are you using webapi controller for the jquery method. If so you would need to get an bearer token as the service api requires bearer token access for webapi enedpoints. If you add the method to an mvc controller should use the cookie authencation.
Thanks, i've checked and we are using a controller, which derives from ApiController, so WebAPI yes. I will note this