首页 > 解决方案 > Ucommerce (Umbraco) 购物篮在切换上下文时删除订单行

问题描述

我开始了一个演示项目来熟悉 Ucommerce for Umbraco。在目录库(类别导航、产品详细信息页面等)中,一切正常,但在交易库(将东西放入我的购物篮)方面,我遇到了一些很大的麻烦。

在我的产品详细信息页面(例如:https://localhost:44395/services/p/apps/android-app)上,我有一个按钮,用于触发 ajax 请求,将产品放入购物篮。

@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/AddProduct?sku=@Model.Sku',
            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;
        }
    }

这按预期工作。我还可以第二次将相同的产品放入篮子中。正如预期的那样,订单行中的数量会增加。 订单线已创建

但是,当我切换到任何其他产品的详细信息页面时(例如:https://localhost:44395/services/p/apps/ios-app),我的购物篮中的所有订单行都会被删除,而购物篮Id 保持不变。(basketId cookie 仍然存在,并且不会改变它的值)

订单被删除

篮子还在

当我添加产品(在详细信息页面上)并直接切换到我的购物篮页面(https://localhost:44395/cart)时,只有最后一种产品,我添加在我的购物篮中。

任何人都知道在这里做什么才能使其正常工作?

设置细节:

Visual Studio 版本:v16.8.3

Umbraco 安装:v8.10.2

Ucommerce:v9.3.1.20275(我使用的是免费版=> https://ucommerce.net/pricing/free/

标签: c#umbraco8umbraco-ucommerce

解决方案


我们遇到了类似的问题,我们通过在 web.config 中添加以下内容来修复它

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

另请添加 TransactionLibrary.ExecuteBasketPipeline(); 在后端代码中


推荐阅读