What's the best way to detect if a Plugin is installed from a View?
Can you elaborate on what exactly you mean? Is this view within your plugin? Is this supposed to be outside the administration section, because within the administration section you will get a list of plugins and their installed/uninstalled status.
In your controller constructor add a parameter IPluginFinder and map it to a readonly field. Inside of your action that returns the view in question add the code below replace "MyViewModel" with the model you are sending to the view. You're going to need to create a new property on your view model. I've called it "IsPluginInstalled" and it is a boolean property.
I don't have a controller for my view, so I'm relying on the Nop.Web one - and I think that would be the Catalog controller in my example above. I really don't want to copy/modify that controller because of big risk that it will be updated by nop team. (maybe I don't understand the nop controllers well enough at this point - could this be a bit of a flaw in the level of granularity chosen by nop design? - the Catalog controller returns many views)
It may not be best MVC practices, but could I somehow call _pluginFinder.GetPluginDescriptorBySystemName("NewPluginSystemName") from inside the view?
It would seem this is a needed feature - could the nop team provide such a "global" function similar to how @T("...") returns localized strings? ( @P( ) :)
It would seem this is a needed feature - could the nop team provide such a "global" function similar to how @T("...") returns localized strings? ( @P( ) :)
There's no need to bloat code just for one function which is not widely used (I mean views). @T is used several thousand times.
It would seem this is a needed feature - could the nop team provide such a "global" function similar to how @T("...") returns localized strings? ( @P( ) :) There's no need to bloat code just for one function which is not widely used (I mean views). @T is used several thousand times.
I have to agree with Andrei on this one. Right now there is no demand for such a function and if it were to be created now it would probably experience significant change when developers actually started using it. Also the functionality you're asking for isn't all that appropriate to be put into a view. It should be handled in the controller and exposed via the model.
If you're absolutely required to use a function like this and do not want to use a model then you can create a static method to provide this functionality. However, you should try and make the first example work if at all possible.
I was being a bit faceious regarding @P(). I don't expect that IsPluginInstalled() would be used in html context, but rather as @if(... )
However, I respectfully disagree with your comments for several reasons
1) This is a "helper" function that taps into nop framework; it's not related to a "business" entity/concern. IMHO Is...PluginInstalled just does not belong in a model, and in the case of a Theme just needing to adjust the presentation, I think my point regarding risk above has merit.
2) I don't see it being much different in concept to html helper functions, e.g. _ColumnsThree @if (IsSectionDefined("left")) except that it's just a nop framework helper function
2) I don't understand the "bloat". This is just a 2-line function
3) There are several nop Views that have "code", and I suspect there were good reasons not to put that code into a controller & add to the model. E.g.
_Root @{ var storeLocation = EngineContext.Current.Resolve<Nop.Core.IWebHelper>().GetStoreLocation(); var displayMiniProfiler = EngineContext.Current.Resolve<Nop.Core.Domain.StoreInformationSettings>().DisplayMiniProfilerInPublicStore; }
4) re: no demand ... would probably experience significant change There is yet no demand because developers have not really started creating plugins and themes - there are very few in the Extensions https://www.nopcommerce.com/extensions.aspx for Nop 2 - two payment, and your sample RequestQuote. I don't see why an IsPluginInstalled() would ever experience change. I would think as more Plugins and Themes are developed, they could potentially interact with other Plugins; knowing if that other plugin is available is useful.
I decided for now just to put the code into my View: