processing shoppingCart items

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
7 years ago
in the final stage when nopcommerce has succesfully processed the order, I want to do some additional things with the items.
(transfer the items to an external service)

I would like to know what is the best place (controller-action)  to do this ?



thanks


Richard
7 years ago
You can check orderservice actually.
7 years ago
OIC wrote:
in the final stage when nopcommerce has succesfully processed the order, I want to do some additional things with the items.
(transfer the items to an external service)

I would like to know what is the best place (controller-action)  to do this ?



thanks


Richard


Besy way is to always try to not modify the core source code. So you have to develop a plugin for this - luckily, nopcommerce has an event system implemented, and all you have to do is to listen to the OrderPlaced event (see link below)

https://www.nopcommerce.com/boards/t/18287/how-can-i-execute-plugin-method-when-order-placed.aspx

Alternatively, you can customize the code from your payment plugin, and execute your code after the payment is done - whatever suits your case. But always avoid editing core source code - you'll have problems when you want to upgrade nopcommerce
7 years ago
ok, guys,
7 years ago
Here is a complete solution.




using System;
using Nop.Core;
using Nop.Core.Domain.Orders;
using Nop.Core.Plugins;
using Nop.Services.Events;
using Nop.Services.Orders;

namespace Nop.Plugin.Misc.YourPlugin
{
    public class OrderEventConsumer : IConsumer<OrderPlacedEvent>
    {
        private readonly IPluginFinder _pluginFinder;
        private readonly IOrderService _orderService;
        private readonly IStoreContext _storeContext;
        public OrderEventConsumer(
            IPluginFinder pluginFinder,
            IOrderService orderService,
            IStoreContext storeContext)
        {
            this._pluginFinder = pluginFinder;
            this._orderService = orderService;
            this._storeContext = storeContext;
        }

\  
        public void HandleEvent(OrderPlacedEvent eventMessage)
        {
            var order = eventMessage.Order;
            var products = order.OrderItems;
            foreach (var product in products)
            {
                //Do your stuf
            }
        }
    }
}
7 years ago
ok, thanks !
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.