获取客户订单数
Get customers number of orders
如何在 public 商店的客户订单页面上获取客户订单数。我已经看到管理页面上已经存在,但是是否有任何应该激活的设置,因为这可以在 public 商店中显示。
假设您正在使用的控制器注入了 _storeContext
、_workContext
和 _orderService
变量,这样就可以了:
var orderCount = _orderService.SearchOrders(
storeId: _storeContext.CurrentStore.Id,
customerId: _workContext.CurrentCustomer.Id)
.Count();
如果这些变量中的任何一个不存在,请手动将它们添加到您的控制器中。玩具需要添加私有变量:
private readonly IStoreContext _storeContext;
private readonly IOrderService _orderService;
private readonly IWorkContext _workContext;
扩展控制器的构造函数并添加代码以保存注入的值:
public YourController(/* other parameters */
IOrderService orderService,
IWorkContext workContext,
IStoreContext storeContext)
{
//snip
this._orderService = orderService;
this._shipmentService = shipmentService;
this._workContext = workContext;
this._storeContext = storeContext;
}
如何在 public 商店的客户订单页面上获取客户订单数。我已经看到管理页面上已经存在,但是是否有任何应该激活的设置,因为这可以在 public 商店中显示。
假设您正在使用的控制器注入了 _storeContext
、_workContext
和 _orderService
变量,这样就可以了:
var orderCount = _orderService.SearchOrders(
storeId: _storeContext.CurrentStore.Id,
customerId: _workContext.CurrentCustomer.Id)
.Count();
如果这些变量中的任何一个不存在,请手动将它们添加到您的控制器中。玩具需要添加私有变量:
private readonly IStoreContext _storeContext;
private readonly IOrderService _orderService;
private readonly IWorkContext _workContext;
扩展控制器的构造函数并添加代码以保存注入的值:
public YourController(/* other parameters */
IOrderService orderService,
IWorkContext workContext,
IStoreContext storeContext)
{
//snip
this._orderService = orderService;
this._shipmentService = shipmentService;
this._workContext = workContext;
this._storeContext = storeContext;
}