Widgets... Widgets... Widgets... How do they work? [A question about using Widgets in Admin]

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
4 years ago
Hi All,

I'm trying to play with Widgets a bit to learn how they work. I have the following questions:

1- I tried playing with Nivo Slider to make it show the slider in the Admin Zone widgets, but nothing shows! Changing the Nivo Slider widget zone to any zone inside the Public zone works, but I can't get Nivo Slider widget to render in any Admin zone. How to do that?

2- How can I make my widget call backend code? For example I want to read some data from a backend service before rendering values using the Widget.

3- Is there a useful project to follow/read as a widget guide or template? The nivoslider and google analytics widgets are not enough.


Thanks!
4 years ago
What is nop version?
4 years ago
mhsjaber wrote:
What is nop version?


It's 4.20
4 years ago
WidgetsPlugins is nothing but a plugin that implements the IWidgetPlugin interface. It has 2 methods and 1 property.

The property is "HideInWidgetList" which is nothing but a boolean value which indicates whether to make the widget plugin available in the /Admin/Widget/List for enabling and disabling it/. I think the property is only available in version 4.2.

The methods are :
1) GetWidgetZones()
2) GetWidgetViewComponentName(nameOfZone)

You need to implement the GetWidgetZones() method to specify the zones where the widget functionality will get rendered and becomes available. For example if you want to modify or add some information at the top of the product tab/section of the order's detail page in the admin panel you need to use " AdminWidgetZones.OrderDetailsProductsTop" widget zone and return it as a list of string. Almost every page in NopCommerce has some widget zones made available

GetWidgetViewComponentName should return the name of view component which contains the custom logic you are trying to implement. You can read more about view component here.

In the ViewComponent you have created you need to inherit from NopViewComponent and override the invoke() method and you can return a view or any other IViewComponentResult result containing any additional information you would like to make available.

For your 2nd question: In the ViewComponent class you can inject any service in the constructor (like you can in any services or controllers) and you can use the service to get anything you want from the backend and return it in the view after binding with the new model or any way you like.

For your 3rd question. Here is an article https://dzone.com/articles/what-are-nopcommerce-widgets-and-how-to-create-one but it is outdated since it's written for 3.8 but still you can get some idea on the working mechanism. PS I am planning to write a more descriptive article on the WidgetsPlugin. I will update my post with the link once I publish it.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.