Override a service in GV V2

Friday, April 26, 2024 12:55:39 AM
  • Posted: Thursday, July 29, 2021 7:05 AM
  • 17
Hi,
I try to override ShoppingCartService from my plugin.
I register my class:
services.AddScoped<IShoppingCartService, MyShoppingCartService>();


I create my class :

    public class MyShoppingCartService : ShoppingCartService ,IShoppingCartService
    {
        public MyShoppingCartService(IWorkContext workContext, IProductService productService, IProductAttributeParser productAttributeParser, ICheckoutAttributeParser checkoutAttributeParser, ICustomerService customerService, IMediator mediator, IUserFieldService userFieldService, IProductReservationService productReservationService, IShoppingCartValidator shoppingCartValidator, ShoppingCartSettings shoppingCartSettings) : base(workContext, productService, productAttributeParser, checkoutAttributeParser, customerService, mediator, userFieldService, productReservationService, shoppingCartValidator, shoppingCartSettings)
        {
        }

        public override Task<IList<string>> AddToCart(Customer customer, string productId, ShoppingCartType shoppingCartType, string storeId,
            string warehouseId = null, IList<CustomAttribute> attributes = null, double? customerEnteredPrice = null,
            DateTime? rentalStartDate = null, DateTime? rentalEndDate = null, int quantity = 1,
            bool automaticallyAddRequiredProductsIfEnabled = true, string reservationId = "", string parameter = "",
            string duration = "", bool getRequiredProductWarnings = true)
        {
            return base.AddToCart(customer, productId, shoppingCartType, storeId, warehouseId, attributes, customerEnteredPrice, rentalStartDate, rentalEndDate, quantity, automaticallyAddRequiredProductsIfEnabled, reservationId, parameter, duration, getRequiredProductWarnings);
        }
    }


My code not working.
Is there any additional task that I should do?

Thanks.
0
  • Posted: Thursday, July 29, 2021 7:14 AM
  • 17
I work on Grandnode V2
0
  • Posted: Thursday, July 29, 2021 10:49 AM
  • Team
  • 151
You need to register your new class:
  

public class StartupApplication : IStartupApplication
    {
        public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
        {
            services.AddScoped<IShoppingCartService, MyShoppingCartService>();
        }

        public void Configure(IApplicationBuilder application, IWebHostEnvironment webHostEnvironment)
        {

        }

        public int Priority => 102;

        public bool BeforeConfigure => false;
    }
1
  • Posted: Thursday, July 29, 2021 4:16 PM
  • 17
Thanks Mr. Krzysztof

I set Priority => 10 that's why my code didn't work.

Is there any guide about Priority?

Best regards
0
back to top
Filters