Yidna wrote:Here is the override file for OrderProcessingService
and the routine MoveShoppingCartItemsToOrderItemsAsync
Called CustomOrderProcessingService.cs
using System;
using System.Linq;
using System.Threading.Tasks;
using Nop.Core;
using Nop.Core.Domain.Customers;
using Nop.Core.Domain.Directory;
using Nop.Core.Domain.Localization;
using Nop.Core.Domain.Orders;
using Nop.Core.Domain.Payments;
using Nop.Core.Domain.Shipping;
using Nop.Core.Domain.Tax;
using Nop.Core.Events;
using Nop.Services.Affiliates;
using Nop.Services.Catalog;
using Nop.Services.Common;
using Nop.Services.Customers;
using Nop.Services.Directory;
using Nop.Services.Discounts;
using Nop.Services.Localization;
using Nop.Services.Logging;
using Nop.Services.Messages;
using Nop.Services.Orders;
using Nop.Services.Payments;
using Nop.Services.Security;
using Nop.Services.Shipping;
using Nop.Services.Tax;
using Nop.Services.Vendors;
namespace Nop.Plugin.Group.Name.Services
{
/// <summary>
/// Order processing service
/// </summary>
public partial class CustomOrderProcessingService : OrderProcessingService
{
#region Fields
private readonly CurrencySettings _currencySettings;
private readonly IAddressService _addressService;
private readonly IAffiliateService _affiliateService;
private readonly ICheckoutAttributeFormatter _checkoutAttributeFormatter;
private readonly ICountryService _countryService;
private readonly ICurrencyService _currencyService;
private readonly ICustomerActivityService _customerActivityService;
private readonly ICustomerService _customerService;
private readonly ICustomNumberFormatter _customNumberFormatter;
private readonly IDiscountService _discountService;
private readonly IEncryptionService _encryptionService;
private readonly IEventPublisher _eventPublisher;
private readonly IGenericAttributeService _genericAttributeService;
private readonly IGiftCardService _giftCardService;
private readonly ILanguageService _languageService;
private readonly ILocalizationService _localizationService;
private readonly ILogger _logger;
private readonly IOrderService _orderService;
private readonly IOrderTotalCalculationService _orderTotalCalculationService;
private readonly IPaymentPluginManager _paymentPluginManager;
private readonly IPaymentService _paymentService;
private readonly IPdfService _pdfService;
private readonly IPriceCalculationService _priceCalculationService;
private readonly IPriceFormatter _priceFormatter;
private readonly IProductAttributeFormatter _productAttributeFormatter;
private readonly IProductAttributeParser _productAttributeParser;
private readonly IProductService _productService;
private readonly IReturnRequestService _returnRequestService;
private readonly IRewardPointService _rewardPointService;
private readonly IShipmentService _shipmentService;
private readonly IShippingService _shippingService;
private readonly IShoppingCartService _shoppingCartService;
private readonly IStateProvinceService _stateProvinceService;
private readonly ITaxService _taxService;
private readonly IVendorService _vendorService;
private readonly IWebHelper _webHelper;
private readonly IWorkContext _workContext;
private readonly IWorkflowMessageService _workflowMessageService;
private readonly LocalizationSettings _localizationSettings;
private readonly OrderSettings _orderSettings;
private readonly PaymentSettings _paymentSettings;
private readonly RewardPointsSettings _rewardPointsSettings;
private readonly ShippingSettings _shippingSettings;
private readonly TaxSettings _taxSettings;
#endregion
#region Ctor
public CustomOrderProcessingService(CurrencySettings currencySettings,
IAddressService addressService,
IAffiliateService affiliateService,
ICheckoutAttributeFormatter checkoutAttributeFormatter,
ICountryService countryService,
ICurrencyService currencyService,
ICustomerActivityService customerActivityService,
ICustomerService customerService,
ICustomNumberFormatter customNumberFormatter,
IDiscountService discountService,
IEncryptionService encryptionService,
IEventPublisher eventPublisher,
IGenericAttributeService genericAttributeService,
IGiftCardService giftCardService,
ILanguageService languageService,
ILocalizationService localizationService,
ILogger logger,
IOrderService orderService,
IOrderTotalCalculationService orderTotalCalculationService,
IPaymentPluginManager paymentPluginManager,
IPaymentService paymentService,
IPdfService pdfService,
IPriceCalculationService priceCalculationService,
IPriceFormatter priceFormatter,
IProductAttributeFormatter productAttributeFormatter,
IProductAttributeParser productAttributeParser,
IProductService productService,
IReturnRequestService returnRequestService,
IRewardPointService rewardPointService,
IShipmentService shipmentService,
IShippingService shippingService,
IShoppingCartService shoppingCartService,
IStateProvinceService stateProvinceService,
ITaxService taxService,
IVendorService vendorService,
IWebHelper webHelper,
IWorkContext workContext,
IWorkflowMessageService workflowMessageService,
LocalizationSettings localizationSettings,
OrderSettings orderSettings,
PaymentSettings paymentSettings,
RewardPointsSettings rewardPointsSettings,
ShippingSettings shippingSettings,
TaxSettings taxSettings) : base(currencySettings,
addressService,
affiliateService,
checkoutAttributeFormatter,
countryService,
currencyService,
customerActivityService,
customerService,
customNumberFormatter,
discountService,
encryptionService,
eventPublisher,
genericAttributeService,
giftCardService,
languageService,
localizationService,
logger,
orderService,
orderTotalCalculationService,
paymentPluginManager,
paymentService,
pdfService,
priceCalculationService,
priceFormatter,
productAttributeFormatter,
productAttributeParser,
productService,
returnRequestService,
rewardPointService,
shipmentService,
shippingService,
shoppingCartService,
stateProvinceService,
taxService,
vendorService,
webHelper,
workContext,
workflowMessageService,
localizationSettings,
orderSettings,
paymentSettings,
rewardPointsSettings,
shippingSettings,
taxSettings)
{
_currencySettings = currencySettings;
_addressService = addressService;
_affiliateService = affiliateService;
_checkoutAttributeFormatter = checkoutAttributeFormatter;
_countryService = countryService;
_currencyService = currencyService;
_customerActivityService = customerActivityService;
_customerService = customerService;
_customNumberFormatter = customNumberFormatter;
_discountService = discountService;
_encryptionService = encryptionService;
_eventPublisher = eventPublisher;
_genericAttributeService = genericAttributeService;
_giftCardService = giftCardService;
_languageService = languageService;
_localizationService = localizationService;
_logger = logger;
_orderService = orderService;
_orderTotalCalculationService = orderTotalCalculationService;
_paymentPluginManager = paymentPluginManager;
_paymentService = paymentService;
_pdfService = pdfService;
_priceCalculationService = priceCalculationService;
_priceFormatter = priceFormatter;
_productAttributeFormatter = productAttributeFormatter;
_productAttributeParser = productAttributeParser;
_productService = productService;
_returnRequestService = returnRequestService;
_rewardPointService = rewardPointService;
_shipmentService = shipmentService;
_shippingService = shippingService;
_shoppingCartService = shoppingCartService;
_stateProvinceService = stateProvinceService;
_taxService = taxService;
_vendorService = vendorService;
_webHelper = webHelper;
_workContext = workContext;
_workflowMessageService = workflowMessageService;
_localizationSettings = localizationSettings;
_orderSettings = orderSettings;
_paymentSettings = paymentSettings;
_rewardPointsSettings = rewardPointsSettings;
_shippingSettings = shippingSettings;
_taxSettings = taxSettings;
}
#endregion
#region Methods
/// <summary>
/// Move shopping cart items to order items
/// </summary>
/// <param name="details">Place order container</param>
/// <param name="order">Order</param>
protected async override Task MoveShoppingCartItemsToOrderItemsAsync(PlaceOrderContainer details, Order order)
{
if (false) //your test case to deturime if you need to run the customisation - change to a test that returns true to run your code
{
// Your version of the routine goes in here
// only call this code if your requirement for customisation applies otherwise call the base
}
else
{
// Alternatively just call the base - should be called for initial debug as test above is false
await base.MoveShoppingCartItemsToOrderItemsAsync(details, order);
}
}
}
}
And the Startup File
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Nop.Core.Infrastructure;
using Nop.Plugin.Group.Name.Services;
using Nop.Services.Orders;
namespace Nop.Plugin.Group.Name.Infrastructure
{
/// <summary>
/// Represents object for the configuring services on application startup
/// </summary>
public class NopStartup : INopStartup
{
/// <summary>
/// Add and configure any of the middleware
/// </summary>
/// <param name="services">Collection of service descriptors</param>
/// <param name="configuration">Configuration of the application</param>
public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
{
services.AddScoped<IOrderProcessingService, CustomOrderProcessingService>();
}
/// <summary>
/// Configure the using of added middleware
/// </summary>
/// <param name="application">Builder for configuring an application's request pipeline</param>
public void Configure(IApplicationBuilder application)
{
}
/// <summary>
/// Gets order of this startup configuration implementation
/// </summary>
public int Order => 4000;
}
}
I just have it calling the base at the moment
Check if that works then you can copy the code from the origi
That was it my friend! I was missing that Infrastructure folder and the startup file!
Thank you Yidna! :)
Rob