How to get override GetFinalPrice from plugin

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
9 years ago
Did you change the order in which it gets called?  If yes, break point it, does it get hit?

It's crucial you change the order or else the original will get hit.
9 years ago
I'd be interested in seeing the answer to this, as I want to do something similar.
9 years ago
Yes i have change order in plugin. but not hit on my plugin services.

Please let me know if you have solution or idea for same.
9 years ago
Seems like that your service isn't registered.

Look at autofac same interface different concrete class.  You may have to do a named instance.
9 years ago
I have register services in plugin "DependencyRegistrar.cs".  if your want to check code is below.


  builder.RegisterType<PreciousMetalsPriceCalculationService>().As<IPriceCalculationService>().SingleInstance().PreserveExistingDefaults();


using Autofac;
using Autofac.Core;
using Autofac.Integration.Mvc;
using Nop.Core.Caching;
using Nop.Core.Data;
using Nop.Core.Infrastructure;
using Nop.Core.Infrastructure.DependencyManagement;
using Nop.Data;
using Nop.Plugin.Pricing.PreciousMetals.Data;
using Nop.Plugin.Pricing.PreciousMetals.Domain;
using Nop.Plugin.Pricing.PreciousMetals.Services;
using Nop.Services.Catalog;
using Nop.Services.Orders;
using Nop.Web.Framework.Mvc;

namespace Nop.Plugin.Pricing.PreciousMetals
{
    public class DependencyRegistrar : IDependencyRegistrar
    {
        const string objectContextName = "nop_object_context_preciousmetals_pricing";      

        public void Register(ContainerBuilder builder, ITypeFinder typeFinder)
        {
            //data layer
            var dataSettingsManager = new DataSettingsManager();
            var dataProviderSettings = dataSettingsManager.LoadSettings();

            const string objectContextName = "nop_object_context_preciousmetals_pricing";

            if (dataProviderSettings != null && dataProviderSettings.IsValid())
            {
                //register named context
                builder.Register<IDbContext>(c => new PreciousMetalsPricingObjectContext(dataProviderSettings.DataConnectionString))
                    .Named<IDbContext>(objectContextName)
                   .InstancePerLifetimeScope();

                builder.Register(c => new PreciousMetalsPricingObjectContext(dataProviderSettings.DataConnectionString))
                    .InstancePerLifetimeScope();
            }
            else
            {
                //register named context
                builder.Register<IDbContext>(c => new PreciousMetalsPricingObjectContext(c.Resolve<DataSettings>().DataConnectionString))
                    .Named<IDbContext>(objectContextName)
                    .InstancePerLifetimeScope();

                builder.Register(c => new PreciousMetalsPricingObjectContext(c.Resolve<DataSettings>().DataConnectionString))
                    .InstancePerLifetimeScope();
            }

            // register custom objects
            builder.RegisterType<EfRepository<PreciousMetalsDetail>>()
                .As<IRepository<PreciousMetalsDetail>>()
                .WithParameter(ResolvedParameter.ForNamed<IDbContext>(objectContextName))
              .InstancePerLifetimeScope();

            builder.RegisterType<EfRepository<PreciousMetalsQuote>>()
                .As<IRepository<PreciousMetalsQuote>>()
                .WithParameter(ResolvedParameter.ForNamed<IDbContext>(objectContextName))
               .InstancePerLifetimeScope();


            //Register services
            builder.RegisterType<PreciousMetalsDetailService>().As<IPreciousMetalsDetailService>().InstancePerLifetimeScope();
            builder.RegisterType<PreciousMetalsQuoteService>().As<IPreciousMetalsQuoteService>().InstancePerLifetimeScope();

            builder.RegisterType<PreciousMetalsPriceCalculationService>().As<IPriceCalculationService>().SingleInstance().PreserveExistingDefaults();
            builder.RegisterType<PreciousMetalsOrderTotalCalculationService>().As<IOrderTotalCalculationService>().SingleInstance().PreserveExistingDefaults();
            builder.RegisterType<PreciousMetalsProductService>().As<IProductService>().SingleInstance().PreserveExistingDefaults();


            //builder.RegisterType<PreciousMetalsPriceCalculationService>().As<IPriceCalculationService>().InstancePerLifetimeScope();
            //builder.RegisterType<PreciousMetalsOrderTotalCalculationService>().As<IOrderTotalCalculationService>().InstancePerLifetimeScope();
            //builder.RegisterType<PreciousMetalsProductService>().As<IProductService>().InstancePerLifetimeScope();

          
        }


        public int Order
        {
            get { return 100; }
        }
    }
}
9 years ago
Ok, lets stop a minute.  Best thing to do is break point in the core package and see what gets registered.  Step through it and see if your service even ever gets registered.

Shouldn't take you too long to do that.  Do it and tell me the results.

P.s i'll be starting my version of Friday night and hopefully be finished in a couple of hours or so.  If you don't have it done by then, I may be able to help you (well as long as i get it working that is)
9 years ago
i have put break point in NopEngine.cs. below method.

protected virtual void RegisterDependencies(NopConfig config)


My service is registered. please check screen shot on below link.

http://site3.zupple.com/Untitled.jpg
9 years ago
Try giving an order of 0.  I wonder whether autofac has a list rather than a stack. FIFO.

Breakpoint your plugin and see if it works.  Breakpoint the RegisterDependencies to ensure that your service gets registered first.

Oh by the way, in the debug that you tried earlier, did your instance get registered AFTER the original?  Did you check this?
9 years ago
Check this link

http://xharze.blogspot.co.uk/2010/07/autofac-part-2-ordering-keyed-named.html

Basically, it says that the last one should get called.  Therefore, it shows to me that your service may be getting called BEFORE the original.  Step through it and ensure that the order is correct.
9 years ago
Have you resolved this?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.