Hello,

I'm currently trying to figure out on how to link nopCommerce Customers to my own database tables. My current idea is to create a plugin to extend the 'Nop.Services.CustomerSerive.CustomerService' and override the InsertCustomer implemenation, and Just adding the Id of the costumer in my own database tables.

I tried following several tutorials, but i can't seem to make head or tails from those (among other the one on http://blog.csharpwebdeveloper.com/ ).

Below you will find a rough idea on how i think it should be implemented, but i can't seem to get the nopCommerce to call my implementation.

Any help would be greatly appreciated.

using Nop.Core.Domain.Customers;
using Nop.Services.Customers;
using System.Linq;
using System.Web.Routing;
using System.Web.Security;
using System.Web;
using System;
using Nop.Core.Caching;
using Nop.Core.Data;
using Nop.Core.Events;

namespace Nop.Plugin.CostumerService.Costum
{
    public class CustomCustomerService : CustomerService
    {

        public CustomCustomerService(Nop.Core.Caching.ICacheManager cacheManager,
                                    Nop.Core.Data.IRepository<Nop.Core.Domain.Customers.Customer> customerRepository,
                                    Nop.Core.Data.IRepository<Nop.Core.Domain.Customers.CustomerRole> customerRoleRepository,
                                    Nop.Core.Data.IRepository<Nop.Core.Domain.Customers.CustomerAttribute> customerAttributeRepository,
                                    Nop.Core.Events.IEventPublisher eventPublisher)
            : base(cacheManager, customerRepository, customerRoleRepository, customerAttributeRepository, eventPublisher)
        {

        }

        public override void InsertCustomer(Nop.Core.Domain.Customers.Customer customer)
        {
            //Basic insert
            base.InsertCustomer(customer);

            //You can only make a nopCommerce user once you are logged in as a Membership user
            //So we fetch our Membership user, take the Guid and add it to the link table
            using (PoppetsEntities db = new PoppetsEntities())
            {
                //Fetch guid from current logged in user
                Guid userGuid = (Guid)Membership.GetUser().ProviderUserKey;

                pop_User user = db.pop_User.FirstOrDefault(p => p.userId == userGuid);
                user.nopCommerceUserId = base.GetCustomerByEmail(customer.Email).Id;

                db.SaveChanges();
            }
        }
    }
}