Ucommerce (Umbraco) basket deletes orderlines when switching context

160 views Asked by At

I started a demo project to get familiar with Ucommerce for Umbraco. Within the catalog library (category navigation, product detail pages etc.) everything works fine, but when it comes to transaction library (putting stuff into my basket) i have some great troubles.

On my product details page (for example: https://localhost:44395/services/p/apps/android-app), i have a button, which triggers an ajax request, to put the product into the basket.

@inherits Umbraco.Web.Mvc.UmbracoViewPage<UComBP.Models.ProductModel>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>

<h2>This is the product detail page of "@Model.Name"</h2>

<h3>Price: @Model.Price</h3>

<button>Add to basket</button>

<script type="text/javascript">
    $("button").click(function () {
        $.ajax({
            type: "POST",
            url: '/Umbraco/Surface/ToCart/[email protected]',
            contentType: "application/json; charset=utf-8",
        });
    });
</script>
public class ToCartController : SurfaceController
    {
        [HttpPost]
        public ActionResult AddProduct(string sku)
        {
            ITransactionLibrary transactionLibrary = Ucommerce.Infrastructure.ObjectFactory.Instance.Resolve<ITransactionLibrary>();
            transactionLibrary.AddToBasket(1, sku);
            return null;
        }
    }

This works as expected. I can also put the same product into the basket a second time. Quantity in the orderline counts up, as expected. The orderline got created

But when i switch to the details page of any other product (for example: https://localhost:44395/services/p/apps/ios-app) , all orderlines inside my basket get deleted, while the basketId stays the same. (basketId cookie is still there, and doesn't change it's value)

Orderline got deleted

Basket is still there

When i add a product (on the details page) and switch directly to my basket page (https://localhost:44395/cart), there is only the last kind of product, i added inside my basket.

Anybody knows what to do here to get this working?

Setup details:

Visual Studio Version: v16.8.3

Umbraco Installation: v8.10.2

Ucommerce: v9.3.1.20275 (I'm using the free version => https://ucommerce.net/pricing/free/)

1

There are 1 answers

1
Jigar Pandya On

We had a similar issue and we fixed it by adding below in web.config

<httpCookies sameSite="None" requireSSL="true" />

Also please add TransactionLibrary.ExecuteBasketPipeline(); in the backend code