Custom code after successful checkout

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 лет назад
Sorry if this has asked already, I did use the search function and it didn't turn up anything.

We are looking to sell a product that we will need to automatically provision on a remote system after checkout. We have the code to provision the product, but I was wondering where the best place to execute that code will be.

We would need access to the previously completed order and be able to determine by sku if the system needs to provision or not. We would also want to use the users email address as the unique id for that product.
13 лет назад
You need to use EventContext and write a plugin. See https://www.nopcommerce.com/boards/t/5809/eventcontext.aspx
13 лет назад
forgive my ignorance but is there any documentation on eventcontext?

as i'm in the solution, it looks like the user control in modules/checkoutcompleted.ascx would be the spot to put my code.
13 лет назад
There's not much documentation beyond what's in that thread I'm afraid.

You create a DLL project, add a reference to that project to the Nop solution, and write your event handler (static). Attach the event handler per that thread in global.asax. You'll want the OrderCompleted event or patch your files per Andrei's recent posts and create an OrderPaid handler.

The beauty of doing it that way is that the only NopCommerce code you need to change is global.asax. This will make your upgrade path easier. By all means hook into the order process as you suggest if that works better for you.

Have to run, microwave is beeping!
13 лет назад
your way makes sense, especially for when we'll eventually want to upgrade. Thanks!
13 лет назад
If you pull this off, could you post a rough outline of the process?  I'll be needing to do this soon myself, and would love to see a recent working example (running 1.8, I hope).
13 лет назад
Open Nop solution. Add a new DLL project. Right click on that project in solution explorer and add a reference to the business logic DLL project.

Right click on the NopCommerceStore project in solution explorer and add a reference to the new DLL project.

Open up EventContext.cs in the business logic DLL and see which event you want to use.

In the new DLL add a static class with a static function to handle the event. Example:

public static class FleetObserverLiteNopCommercePlugin
    {
        /// <summary>
        /// OrderPlaced event handler
        /// </summary>
        /// <remarks>Needs to be threadsafe</remarks>
        public static void OrderPaidHandler(object sender, OrderEventArgs e)
        {
                .... do stuff
        }

Attach the event in global.asax:
      
    void Application_BeginRequest(object sender, EventArgs e)
    {
        NopConfig.Init();
        if (!InstallerHelper.ConnectionStringIsSet())
        {
            InstallerHelper.RedirectToInstallationPage();
        }

        EventContext.Current.OrderPaid += FleetObserverLiteNopCommercePlugin.OrderPlacedHandler;
    }

Test.

That's all there is to it. I've not tested the OrderPaid event (Nop 1.9) yet but OrderCompleted works as you would expect.
13 лет назад
in 1.8 there is only

ordercreated
orderplaced
orderupdated

I do not see ordercompleted.

are you talking about orderplaced?
13 лет назад
Okay, I just went and revisited the original thread that you had posted about EventContext. Apparently you had to modify the source for EventContext?

I've put the code in place in both my created library and global.asax, but will keep it commented out until an upgrade to 1.9

for now I'll use the checkoutcompleted.ascx module to get where we need to be.
13 лет назад
Sorry, I meant order placed.

I had to change the source code to get an order paid event. Order placed is already there and works fine.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.