【问题标题】:Nopcommerce ShoppingService -- I want to get the information of all the products in the shopping cartNopcommerce ShoppingService -- 我想获取购物车中所有产品的信息
【发布时间】:2021-11-06 05:39:38
【问题描述】:

我想获取购物车中所有产品和供应商的信息。非常感谢

nopcommerce 4.40 版

我想做 Shoppingcart

我可以, 我能够找出篮子里有多少物品。

MyShoppingcart

@{
var shoppingCartItems = default(IList<ShoppingCartItem>);
var shoppingCartEnabled = await _permissionService.AuthorizeAsync(StandardPermissionProvider.EnableShoppingCart);

var customer = _workContext.GetCurrentCustomerAsync().Result;
if (customer.HasShoppingCartItems)
{
    var storeScope = await _storeContext.GetActiveStoreScopeConfigurationAsync();
    shoppingCartItems = await _shoppingCartService.GetShoppingCartAsync(customer, ShoppingCartType.ShoppingCart, storeScope);
}

}

【问题讨论】:

  • 您到底需要什么?客户购物车中的商品数量?
  • 我想获取购物车中所有产品和供应商的信息。
  • 只能得到count,找不到产品信息。

标签: c# asp.net .net .net-core nopcommerce


【解决方案1】:

当您加载 shoppingCartItems 时,您已检索到购物车中的所有商品。购物车,在 4.2 版本中(不是你的版本,而是我使用的版本)有 ProductID 字段。您可以使用此字段检索所有产品信息,并使用 shoppingCartItems 上的 foreach cicle 填充到购物车项目中。

var shoppingCarts = _shoppingCartService.GetShoppingCart(_workContext.CurrentCustomer, ShoppingCartType.Wishlist, _storeContext.CurrentStore.Id);

foreach(var sci in shoppingCarts)
{
    sci.Product = _productService.GetProductById(sci.ProductId);
}

这里是 4.2 服务版本的示例。但是,4.2 有 EntityFramework,我不需要加载产品信息,因为 EF 为我加载(sci.Product 包含产品信息)。我不知道 4.4 是否使用 EF 或其他,但如果 sci.Product 刚刚填充,您可以使用断点进行检查。

【讨论】:

  • 你能举一个4.2代码的例子吗?
【解决方案2】:

在 4.4 版中,如果您查看数据库或域,您会看到购物车项目具有属性 ProductId,并且每个产品项目都有一个属性 VendorId 。按照上面的答案,您将能够从购物车中检索产品信息,然后是购物车中每个产品的供应商信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-19
    • 1970-01-01
    • 2017-04-27
    • 1970-01-01
    • 2015-04-19
    • 1970-01-01
    • 2014-02-06
    • 1970-01-01
    相关资源
    最近更新 更多