Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

After installing service API, if i'm logged into Episerver cannot post to basket

Vote:
 

Hey all.  Complicated one here.

Situation:

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.

Any ideas?

Thanks

Sorry, version of episerver = CMS.Core:9.12.0 Commerce.Core:9.19

#152091
Edited, Aug 16, 2016 11:34
Vote:
 

Hi,

Do you see any issue in the browser console (Network tab) or in the server site (debugger attached)?

#152098
Aug 16, 2016 13:40
Vote:
 

Hey

Hello.  I have done some decompiling of the CartHelper and I think the orderform is not being created?

/// <summary>

/// Loads the cart. The cart is loaded from current http context if one is present.

///</summary>

///<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;

if (CartHelper.FeatureSwitch.Service.IsVNextWorkflowEnabled())

{

OrderForm orderForm = cart.OrderForms.FirstOrDefault<OrderForm>();

if (orderForm == null)

{

orderForm = cart.OrderForms.AddNew();

orderForm.Name = cart.Name;

}

if (!orderForm.Shipments.Any<Shipment>())

cart.OrderForms.First<OrderForm>().Shipments.AddNew();

}

this._Cart = cart;

}

Perhaps this line

if (CartHelper.FeatureSwitch.Service.IsVNextWorkflowEnabled())

If this returns false then no order form is added. 

#152102
Aug 16, 2016 15:34
Vote:
 

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...

#152103
Aug 16, 2016 15:36
Vote:
 

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.

#152126
Aug 17, 2016 13:33
Vote:
 

Thanks, i've checked and we are using a controller, which derives from ApiController, so WebAPI yes.  I will note this 

Thanks again.

#152177
Aug 18, 2016 18:07
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.