Should I use a Widget or a Plugin in this scenario (purchases lookup based on customer number)?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
3 years ago
Dear all,
I have been trying to add a plugin to my currently local NopCommerce (subsequently NC) installation. Since I have not made any progress, it occurred to me that my entire approach might have been wrong. I am a bit confused in terms of when to opt for widgets or plugins and using NC or plugin pages in general. Be that as it may, please, allow me to describe what I have been trying to achieve:

Within NC, I would like to create a page with a text box and a button. Users can enter their customer number and once they hit the button, the request is processed, and a second page displays all customer purchases based on the customer number entered, e.g. a user enters “CNR12345” and is redirected to a particular page displaying all purchases related to that customer number.

The page to enter the customer number and the page displaying the purchases made should both be “proper” pages and part of the actual shop(s).
The described above feature is part of an existing application created as a “classic” MVC5 project. A considerable part of the actual logic thus already exists, and I have been able to convert most of it to the NetCore framework.

The problem I am facing is how to create the pages mentioned above and connect the logic layer. What would be the correct approach, plugin or widget or something else?
I am sure I must have misread or misunderstood some section(s) in the documentation. Would be grand if somebody could assist me regarding this matter.

Thanks a mil in advance.
3 years ago
Is this for the public store, or the administration?
3 years ago
Ah, yes ... sorry for not mentioning this in the description.
The feature should be available to the user in the public store user interface(s).
3 years ago
What is a "Customer Number"?  Why should the customer have to enter it?
3 years ago
Customer number like "Customer.Id".
Customers could, for example, review their purchase history instead of creating a support ticket. I am not talking about the entire customer data like account details and the like. One could also think of another scenario in which the "number" can be any number or identifier to be used to look things up in a database (to make it more or less generic).
Example
If my customer number was "1234" and I bought 5 books in the past year since I opened my account in the book store, I would expect to see all my purchases (date of purchase, book title, etc.) in a somewhat nice display on another page. Please note that this is just an example.

My point was that somebody would enter a sequence of characters or numbers or a combination thereof into the text field on a page in the application, would hit the button and the application would look up the details elsewhere (database, cloud, you name it) to be displayed in a table or grid on the next page (to which the user should be redirected automatically). It does not matter much what is actually entered in the text box as long as it can be parsed in some manner, "customer number" was just an example, admittedly a bad one as it seems.

Something along these lines (just trying to sketch out the idea) ... I am not sure how and where to create this "page" and if the Controller processing the action should really be part of a plugin or not

@model Nop.Plugin.Misc.MyCustomPlugin.Models.SomeModel
!<-- [...] -->
<div class="content-wrapper">
    <form asp-controller="MyCustomPluginController"
          asp-action="GoFetchData"
          method="post" asp-anti-forgery-token="true">
        <div>
            <label>Enter some sequence here:</label>
            <input type="text" asp-for="SomeModel.Number"/>
        </div>
        <div>
            <input type="submit"
                   id="btnGoFetchData"
                   value="Fetch Data"
                   class="btn btn-primary btn-lg"/>
        </div>
    </form>
</div>

!<-- [...] -->
3 years ago
Sorry I don’t really understand what you are trying to do with the Customer Number 😊
Anyway RE Plugin vs Widget - A widget is used to display content in a specific location
If you look at some of the views  
i.e. source\Presentation\Nop.Web\Views\Shared\Components\HeaderLinks\Default.cshtml
or
source\Presentation\Nop.Web\Views\Shared\Components\Footer\Default.cshtml
Then you see in these pages various widget locations
For example in the header links there is a widget location called PublicWidgetZones.HeaderLinksBefore
So essentially you create some new content and attach it to a widget location and in this case it will be inserted before the header links
In a simple widget you could make some new content - maybe a new text label with a database value to be displayed or some special text based on a context
Of in fact the Frontpage slider on the nopCommerce Demo is a widget

Plugins are about creating complete new functionality like a new view associated with a new table, a payment plugin or shipping plugin, etc
Although there can be some crossover between the two, plugins are usually a much more detailed containment of new functionality
You can see various posts about the differences here
https://www.google.com/search?q=nopcommerce+widget+vs+plugin

Cres wrote:
... I am not sure how and where to create this "page" and if the Controller processing the action should really be part of a plugin or not

In your case I think you are taking about a plugin although you can equally just change the core code and use existing controllers and models. Although making a plugin allows you to more easily manage the creation of functionality as a project, keep all the changes together, manage and update the changes, especially if you want to make the new functionality available to others then make a plugin.
There is info in the documentation about making plugins – or just examine one of the existing plugins or widgets to see how they work
3 years ago
Thanks a mil for your reply and explaining when to use widgets and when to use plugins. I need to think about a different example then. I am truly sorry about that, usually I do not have that much trouble wrapping my thoughts into more or less meaningful sentences, I blame it on the heat 😎. No, seriously, I do appreciate your help and sincerely thank you for your patience.

It seems I opted for the right approach. I created a new plugin as you and the documentation suggested. The plugin has the views to request and display the data including the corresponding controllers to handle the logic. The question is if my page for entering "something" was a View
located within the plugin architecture, e.g
`[...]\Plugins\Nop.Plugin.Misc.MyCustomPlugin\Pages\MyCustomPlugin\Index` , how and where would I set the Route to be able to open that particular View in the actual shop front? How can I get to that particular page if plugin pages cannot - as far as my current understanding goes - be accessed directly from the shop. Let me rephrase that, considering the demo shops that shipped with the NC installation zip:
If I open the section 'Digital Downloads', I see the tracks, the 'ADD TO CARD' and so on. What I would like to achieve is to add the above example form (without customer number 😁) to this "shop page". It does not matter which shop page, I am only interested about connecting the plugin correctly. I created an image, well a mockup, to elucidate what I am talking about, but I've been unable to upload it here in the forum ...
3 years ago
Although his article is useful, personally, I don't agree with Lavish's distinction between widgets and plugin.  Widgets are plugins too.  Technically they inherent from  : BasePlugin, IWidgetPlugin  (And, note the suffix "Plugin" in both ;)   Plugins extend nopCommerce functionality (without having to touch core code.  The distinction is that widgets are placed in widget zones (in Views / .cshtml files) and 'typically' they will be used to render some 'part' for information for the user to see, although it's not always the case that it's visible - the Google Analytics being an example.

Back to the real question at hand, it sounds to me that what you really want to do is add a new link (and page) to the customer's My Account page.   For example, your request is not that different than the existing links/pages for customer's My Account "Orders" and "Downloadable products" pages.  For that, you would create a regular plugin (not a widget ;), and I think if you search the forum, you will see similar requests in the past.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.