Replacing the PDF generation routines

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Il y a 12 ans
Hi Guys,

I'm trying to replace the default pdf generation routines with my own (to make use of user-definable templates), I'm attempting to do this as plugin.

It works great except for one thing, it always uses my routines even when i "uninstall" the plugin....

I would like to be able to switch this plugin on or off depending on it's "installed" status, any help anyone could give would be very much appreciated.

Cheers

James
Il y a 12 ans
this is using nopCommerce 2.50
Il y a 12 ans
I presume that you override the default PdfService with your one in the plugin using IDependencyRegistrar. The issue is that IDependencyRegistrar.Register is always invoked no matter whether a plugin is installed or not. That's why you have to add a validation to your Register method whether it's installed. Something like


//is plugin installed?
var pluginDescriptor = _pluginFinder.GetPluginDescriptorBySystemName("YourSystemNameHere");
if (pluginDescriptor == null || !pluginDescriptor.Installed)
   return;
Il y a 12 ans
Thanks a lot!
Il y a 11 ans
Hi

I'm working to solve the same problem not to register a new service/plugin if it's not yetinstalled.

I have tried to use the code snippet shown but I don't know how to inject the _pluginFinder (IPlugFinder).

I have tried with the following sample, added to the Register method in my DependencyRegistrar class in my Plugin:

IPluginFinder _pluginFinder = DependencyResolver.Current.GetService<IPluginFinder>();
var pluginDescriptor = _pluginFinder.GetPluginDescriptorBySystemName("Misc.PDFReports");
if (pluginDescriptor == null || !pluginDescriptor.Installed)
   return;

But no pluginfinder is found?

Objecta, Denmark
Il y a 11 ans
I finally find a solution to both find the IPluginFinder instance and to check if my plugin is already installed.

            var pluginFinderTypes = typeFinder.FindClassesOfType<IPluginFinder>();

            bool isInstalled = false;

            foreach (var pluginFinderType in pluginFinderTypes)
            {
                var pluginFinder = Activator.CreateInstance(pluginFinderType) as IPluginFinder;
                var pluginDescriptor = pluginFinder.GetPluginDescriptorBySystemName("Misc.PDFReports");

                if(pluginDescriptor != null && pluginDescriptor.Installed)
                {
                    isInstalled = true;
                    break;
                }
            }

            if(isInstalled)
                builder.RegisterType<ReportPDFService>().As<IPdfService>().InstancePerHttpRequest();

Objecta
Denmark
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.