c# - 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/)
解决方案
我们遇到了类似的问题,我们通过在 web.config 中添加以下内容来修复它
<httpCookies sameSite="None" requireSSL="true" />
另请添加 TransactionLibrary.ExecuteBasketPipeline(); 在后端代码中
推荐阅读
- python - 如何在不保留大量值的情况下获取 Python 中不同值的计数
- php - 如何访问嵌套 JSON 的某些部分?
- php - 如何让 PHP 理解 * 或 * 一个数组或函数参数的 splat 运算符(3 点 ...)?
- sql - 允许空 SET 语句(没有 SET 选项分配)
- python - ImportError:在执行 python3 manage.py 迁移时无法导入名称“memoize”
- ios - 如何转换 MyResult
到我的数据? - php - 需要帮助从 php codeigntier 中的数据库中获取数据
- vue.js -
vuetify material Icon (mdi) showing problem in vuetify and nuxt app? - spring - 您如何在 Spring 代码库中找到自己的方式?
- asp.net - CS0101: The namespace already contains a definition for className