CustomOrders in progress....
This commit is contained in:
parent
2b6e022f8b
commit
35378d9b0d
|
|
@ -1,29 +1,64 @@
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using AyCode.Services.SignalRs;
|
||||||
using Nop.Services.Orders;
|
using FruitBank.Common.Server.Interfaces;
|
||||||
using Nop.Web.Areas.Admin.Controllers;
|
using FruitBank.Common.SignalRs;
|
||||||
using Nop.Web.Framework.Mvc.Filters;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Nop.Web.Framework;
|
|
||||||
using Nop.Web.Areas.Admin.Models.Orders;
|
|
||||||
using Nop.Services.Security;
|
|
||||||
using Nop.Plugin.Misc.FruitBankPlugin.Factories;
|
using Nop.Plugin.Misc.FruitBankPlugin.Factories;
|
||||||
using Nop.Web.Areas.Admin.Factories;
|
|
||||||
using Nop.Plugin.Misc.FruitBankPlugin.Models;
|
using Nop.Plugin.Misc.FruitBankPlugin.Models;
|
||||||
|
using Nop.Services.Orders;
|
||||||
|
using Nop.Services.Security;
|
||||||
|
using Nop.Web.Areas.Admin.Controllers;
|
||||||
|
using Nop.Web.Areas.Admin.Factories;
|
||||||
|
using Nop.Web.Areas.Admin.Models.Orders;
|
||||||
|
using Nop.Web.Framework;
|
||||||
|
using Nop.Web.Framework.Mvc.Filters;
|
||||||
|
|
||||||
namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
|
namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
|
||||||
{
|
{
|
||||||
|
public class CustomOrderService(IOrderService orderService, IOrderModelFactory orderModelFactory) : ICustomOrderControllerServer
|
||||||
|
{
|
||||||
|
private readonly IOrderService _orderService = orderService;
|
||||||
|
private readonly CustomOrderModelFactory _orderModelFactory = orderModelFactory as CustomOrderModelFactory;
|
||||||
|
|
||||||
|
public async Task<OrderListModelExtended> GetOrderModelsByFilter(OrderSearchModel searchModel)
|
||||||
|
{
|
||||||
|
var orderListModel = await _orderModelFactory.PrepareOrderListModelExtendedAsync(searchModel);
|
||||||
|
|
||||||
|
Console.WriteLine($"Total: {orderListModel.RecordsTotal}, Data Count: {orderListModel.Data.Count()}");
|
||||||
|
foreach (var item in orderListModel.Data.Take(3))
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Order: {item.Id}, {item.CustomOrderNumber}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return orderListModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
[SignalR(SignalRTags.GetPendingOrderModels)]
|
||||||
|
public async Task<OrderListModelExtended> GetPendingOrderModels()
|
||||||
|
{
|
||||||
|
var orderSearchModel = new OrderSearchModel
|
||||||
|
{
|
||||||
|
OrderStatusIds = new List<int> { 1 }
|
||||||
|
};
|
||||||
|
|
||||||
|
return await GetOrderModelsByFilter(orderSearchModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Area(AreaNames.ADMIN)]
|
[Area(AreaNames.ADMIN)]
|
||||||
[AuthorizeAdmin]
|
[AuthorizeAdmin]
|
||||||
public class CustomOrderController : BaseAdminController
|
public class CustomOrderController : BaseAdminController, ICustomOrderControllerServer
|
||||||
{
|
{
|
||||||
private readonly IOrderService _orderService;
|
private readonly IOrderService _orderService;
|
||||||
private readonly IOrderModelFactory _orderModelFactory;
|
private readonly CustomOrderModelFactory _orderModelFactory;
|
||||||
|
private readonly ICustomOrderControllerServer _customOrderService;
|
||||||
private readonly IPermissionService _permissionService;
|
private readonly IPermissionService _permissionService;
|
||||||
// ... other dependencies
|
// ... other dependencies
|
||||||
|
|
||||||
public CustomOrderController(IOrderService orderService, IOrderModelFactory orderModelFactory, IPermissionService permissionService)
|
public CustomOrderController(IOrderService orderService, IOrderModelFactory orderModelFactory, ICustomOrderControllerServer customOrderService, IPermissionService permissionService)
|
||||||
{
|
{
|
||||||
_orderService = orderService;
|
_orderService = orderService;
|
||||||
_orderModelFactory = orderModelFactory;
|
_orderModelFactory = orderModelFactory as CustomOrderModelFactory;
|
||||||
|
_customOrderService = customOrderService;
|
||||||
_permissionService = permissionService;
|
_permissionService = permissionService;
|
||||||
// ... initialize other deps
|
// ... initialize other deps
|
||||||
}
|
}
|
||||||
|
|
@ -44,20 +79,39 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[CheckPermission(StandardPermission.Orders.ORDERS_VIEW)]
|
[CheckPermission(StandardPermission.Orders.ORDERS_VIEW)]
|
||||||
public virtual async Task<IActionResult> OrderList(OrderSearchModel searchModel)
|
public async Task<IActionResult> OrderList(OrderSearchModel searchModel)
|
||||||
{
|
{
|
||||||
//prepare model
|
//prepare model
|
||||||
var model = await _orderModelFactory.PrepareOrderListModelAsync(searchModel);
|
var orderListModel = await GetOrderModelsByFilter(searchModel);
|
||||||
|
|
||||||
|
var valami = Json(orderListModel);
|
||||||
|
Console.WriteLine(valami);
|
||||||
|
return valami;
|
||||||
|
}
|
||||||
|
|
||||||
Console.WriteLine($"Total: {model.RecordsTotal}, Data Count: {model.Data.Count()}");
|
public async Task<OrderListModelExtended> GetOrderModelsByFilter(OrderSearchModel searchModel)
|
||||||
foreach (var item in model.Data.Take(3))
|
{
|
||||||
|
//return _customOrderService.
|
||||||
|
var orderListModel = await _orderModelFactory.PrepareOrderListModelExtendedAsync(searchModel);
|
||||||
|
|
||||||
|
Console.WriteLine($"Total: {orderListModel.RecordsTotal}, Data Count: {orderListModel.Data.Count()}");
|
||||||
|
foreach (var item in orderListModel.Data.Take(3))
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Order: {item.Id}, {item.CustomOrderNumber}");
|
Console.WriteLine($"Order: {item.Id}, {item.CustomOrderNumber}");
|
||||||
}
|
}
|
||||||
var valami = Json(model);
|
|
||||||
Console.WriteLine(valami);
|
return orderListModel;
|
||||||
return valami;
|
}
|
||||||
|
|
||||||
|
[SignalR(SignalRTags.GetPendingOrderModels)]
|
||||||
|
public async Task<OrderListModelExtended> GetPendingOrderModels()
|
||||||
|
{
|
||||||
|
var orderSearchModel = new OrderSearchModel
|
||||||
|
{
|
||||||
|
OrderStatusIds = new List<int> { 1 }
|
||||||
|
};
|
||||||
|
|
||||||
|
return await GetOrderModelsByFilter(orderSearchModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual IActionResult Test()
|
public virtual IActionResult Test()
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ using FruitBank.Common.Interfaces;
|
||||||
using FruitBank.Common.Loggers;
|
using FruitBank.Common.Loggers;
|
||||||
using FruitBank.Common.Models;
|
using FruitBank.Common.Models;
|
||||||
using FruitBank.Common.Server;
|
using FruitBank.Common.Server;
|
||||||
|
using FruitBank.Common.Server.Interfaces;
|
||||||
using FruitBank.Common.SignalRs;
|
using FruitBank.Common.SignalRs;
|
||||||
using LinqToDB;
|
using LinqToDB;
|
||||||
using Mango.Nop.Core.Dtos;
|
using Mango.Nop.Core.Dtos;
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,15 @@
|
||||||
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Routing;
|
using Microsoft.AspNetCore.Mvc.Routing;
|
||||||
|
using Microsoft.AspNetCore.Mvc.TagHelpers;
|
||||||
|
using Nop.Core;
|
||||||
using Nop.Core.Domain.Catalog;
|
using Nop.Core.Domain.Catalog;
|
||||||
using Nop.Core.Domain.Common;
|
using Nop.Core.Domain.Common;
|
||||||
using Nop.Core.Domain.Directory;
|
using Nop.Core.Domain.Directory;
|
||||||
using Nop.Core.Domain.Orders;
|
using Nop.Core.Domain.Orders;
|
||||||
using Nop.Core.Domain.Shipping;
|
using Nop.Core.Domain.Shipping;
|
||||||
using Nop.Core.Domain.Tax;
|
using Nop.Core.Domain.Tax;
|
||||||
using Nop.Core;
|
using Nop.Plugin.Misc.FruitBankPlugin.Helpers;
|
||||||
|
using Nop.Plugin.Misc.FruitBankPlugin.Models;
|
||||||
using Nop.Plugin.Misc.FruitBankPlugin.Services;
|
using Nop.Plugin.Misc.FruitBankPlugin.Services;
|
||||||
using Nop.Services.Affiliates;
|
using Nop.Services.Affiliates;
|
||||||
using Nop.Services.Catalog;
|
using Nop.Services.Catalog;
|
||||||
|
|
@ -28,10 +31,7 @@ using Nop.Services.Tax;
|
||||||
using Nop.Services.Vendors;
|
using Nop.Services.Vendors;
|
||||||
using Nop.Web.Areas.Admin.Factories;
|
using Nop.Web.Areas.Admin.Factories;
|
||||||
using Nop.Web.Areas.Admin.Models.Orders;
|
using Nop.Web.Areas.Admin.Models.Orders;
|
||||||
using Nop.Plugin.Misc.FruitBankPlugin.Models;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Nop.Plugin.Misc.FruitBankPlugin.Helpers;
|
|
||||||
using Microsoft.AspNetCore.Mvc.TagHelpers;
|
|
||||||
|
|
||||||
namespace Nop.Plugin.Misc.FruitBankPlugin.Factories
|
namespace Nop.Plugin.Misc.FruitBankPlugin.Factories
|
||||||
{
|
{
|
||||||
|
|
@ -166,32 +166,30 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Factories
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<OrderListModel> PrepareOrderListModelAsync(OrderSearchModel searchModel)
|
public override async Task<OrderListModel> PrepareOrderListModelAsync(OrderSearchModel searchModel)
|
||||||
|
=>await base.PrepareOrderListModelAsync(searchModel);
|
||||||
|
|
||||||
|
public async Task<OrderListModelExtended> PrepareOrderListModelExtendedAsync(OrderSearchModel searchModel)
|
||||||
{
|
{
|
||||||
// get the default model first
|
var orderListModel = await PrepareOrderListModelAsync(searchModel);
|
||||||
var baseModel = await base.PrepareOrderListModelAsync(searchModel);
|
|
||||||
|
|
||||||
var extendedRows = new List<OrderModelExtended>();
|
var orderListModelExtended = new OrderListModelExtended();
|
||||||
|
var extendedRows = new List<OrderModelExtended>(orderListModel.RecordsFiltered);
|
||||||
|
|
||||||
foreach (var order in baseModel.Data)
|
CopyModelHelper.CopyPublicProperties(orderListModel, orderListModelExtended);
|
||||||
|
|
||||||
|
foreach (var orderModel in orderListModel.Data)
|
||||||
{
|
{
|
||||||
var extendedOrder = new OrderModelExtended();
|
var orderModelExtended = new OrderModelExtended();
|
||||||
CopyModelHelper.CopyPublicProperties(order, extendedOrder);
|
CopyModelHelper.CopyPublicProperties(orderModel, orderModelExtended);
|
||||||
extendedOrder.NeedsMeasurement = await ShouldMarkAsNeedsMeasurementAsync(order);
|
|
||||||
Console.WriteLine(extendedOrder.Id);
|
orderModelExtended.NeedsMeasurement = await ShouldMarkAsNeedsMeasurementAsync(orderModel);
|
||||||
extendedRows.Add(extendedOrder);
|
|
||||||
|
Console.WriteLine(orderModelExtended.Id);
|
||||||
|
extendedRows.Add(orderModelExtended);
|
||||||
}
|
}
|
||||||
|
|
||||||
//var model = new OrderListModel
|
orderListModelExtended.Data = extendedRows; // Different cast approach
|
||||||
//{
|
return orderListModelExtended;
|
||||||
// Data = extendedRows.Cast<OrderModel>().ToList(),
|
|
||||||
// RecordsTotal = baseModel.RecordsTotal
|
|
||||||
//};
|
|
||||||
|
|
||||||
var model = new OrderListModel();
|
|
||||||
CopyModelHelper.CopyPublicProperties(baseModel, model);
|
|
||||||
model.Data = extendedRows.ToList<OrderModel>(); // Different cast approach
|
|
||||||
|
|
||||||
return model;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// example async custom logic
|
// example async custom logic
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,9 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Helpers
|
||||||
{
|
{
|
||||||
public static class CopyModelHelper
|
public static class CopyModelHelper
|
||||||
{
|
{
|
||||||
public static void CopyPublicProperties<TSource, TDestination>(TSource src, TDestination dest)
|
public static TDestination CopyPublicProperties<TSource, TDestination>(TSource src, TDestination dest)
|
||||||
{
|
{
|
||||||
if (src == null || dest == null) return;
|
if (src == null || dest == null) return dest;
|
||||||
|
|
||||||
var srcProps = typeof(TSource)
|
var srcProps = typeof(TSource)
|
||||||
.GetProperties(BindingFlags.Public | BindingFlags.Instance)
|
.GetProperties(BindingFlags.Public | BindingFlags.Instance)
|
||||||
|
|
@ -23,6 +23,8 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Helpers
|
||||||
if (dp == null || !dp.CanWrite) continue;
|
if (dp == null || !dp.CanWrite) continue;
|
||||||
dp.SetValue(dest, sp.GetValue(src));
|
dp.SetValue(dest, sp.GetValue(src));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return dest;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,8 @@ using Nop.Services.Events;
|
||||||
using Nop.Web.Areas.Admin.Factories;
|
using Nop.Web.Areas.Admin.Factories;
|
||||||
using Nop.Web.Areas.Admin.Models.Catalog;
|
using Nop.Web.Areas.Admin.Models.Catalog;
|
||||||
using Nop.Web.Areas.Admin.Models.Orders;
|
using Nop.Web.Areas.Admin.Models.Orders;
|
||||||
using FruitBankDataController = Nop.Plugin.Misc.FruitBankPlugin.Controllers.FruitBankDataController;
|
using FruitBank.Common.Server.Interfaces;
|
||||||
|
using Nop.Plugin.Misc.FruitBankPlugin.Controllers;
|
||||||
|
|
||||||
namespace Nop.Plugin.Misc.FruitBankPlugin.Infrastructure;
|
namespace Nop.Plugin.Misc.FruitBankPlugin.Infrastructure;
|
||||||
|
|
||||||
|
|
@ -73,9 +74,11 @@ public class PluginNopStartup : INopStartup
|
||||||
services.AddScoped<IConsumer<OrderPlacedEvent>, EventConsumer>();
|
services.AddScoped<IConsumer<OrderPlacedEvent>, EventConsumer>();
|
||||||
services.AddScoped<IOrderMeasurementService, OrderMeasurementService>();
|
services.AddScoped<IOrderMeasurementService, OrderMeasurementService>();
|
||||||
services.AddScoped<PendingMeasurementCheckoutFilter>();
|
services.AddScoped<PendingMeasurementCheckoutFilter>();
|
||||||
services.AddScoped<OrderListModel, OrderListModelExtended>();
|
|
||||||
services.AddScoped<OrderModel, OrderModelExtended>();
|
//services.AddScoped<OrderListModel, OrderListModelExtended>();
|
||||||
services.AddScoped<OrderSearchModel, OrderSearchModelExtended>();
|
//services.AddScoped<OrderModel, OrderModelExtended>();
|
||||||
|
//services.AddScoped<OrderSearchModel, OrderSearchModelExtended>();
|
||||||
|
|
||||||
services.AddScoped<IOrderModelFactory, CustomOrderModelFactory>();
|
services.AddScoped<IOrderModelFactory, CustomOrderModelFactory>();
|
||||||
services.AddScoped<IGenericAttributeService, GenericAttributeService>();
|
services.AddScoped<IGenericAttributeService, GenericAttributeService>();
|
||||||
services.AddScoped<CerebrasAPIService>();
|
services.AddScoped<CerebrasAPIService>();
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
using Nop.Web.Framework.Models;
|
||||||
|
|
||||||
|
namespace Nop.Plugin.Misc.FruitBankPlugin.Models;
|
||||||
|
|
||||||
|
public interface IOrderListModelExtended<T>: IPagedModel<T> where T : BaseNopModel
|
||||||
|
{
|
||||||
|
public bool? NeedsMeasurement { get; set; }
|
||||||
|
}
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
using Nop.Web.Areas.Admin.Models.Orders;
|
using Nop.Web.Areas.Admin.Models.Orders;
|
||||||
|
using Nop.Web.Framework.Models;
|
||||||
|
|
||||||
namespace Nop.Plugin.Misc.FruitBankPlugin.Models
|
namespace Nop.Plugin.Misc.FruitBankPlugin.Models
|
||||||
{
|
{
|
||||||
public partial record OrderListModelExtended : OrderListModel
|
public partial record OrderListModelExtended : BasePagedListModel<OrderModelExtended>, IOrderListModelExtended<OrderModelExtended>
|
||||||
{
|
{
|
||||||
public bool? NeedsMeasurement { get; set; }
|
public bool? NeedsMeasurement { get; set; }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue