Developer forum

Forum » Development » Create new user at Checkout

Create new user at Checkout

Dmitrij Jazel
Reply

Hello DW Guys,

My question is:

I have yet another eCom shop. No custom modules or anything yet.

During the checkout (after transaction was successful) I need DW to go through a cart, and if one special product was added - the system must generate new user based on information that user entered during checkout.

Could I please ask you guys what would be the best way to solve this one?

I am feeling like crating custom checkout handler (I would need what event is happens after transaction was successful).

In there I think I should be able to generate a new user and add it to a group (I would also need a code snippet for this one).

This is new DW 8.2.

 

Thanks alot for help guys,

Regards,

Dmitrij

 


Replies

 
Morten Snedker
Reply

Hi Dmitriy,

 

There's some 40+ notifications to the cart, so find the one that suits you the best. But something like

 

using Dynamicweb;

namespace AddUserOnCartFlow
{
    [Dynamicweb.Extensibility.Subscribe(Dynamicweb.Notifications.eCommerce.Cart.CheckoutDoneOrderIsComplete)]
    public class EcomCartCheckoutDoneOrderIsCompleteObserver1 : Dynamicweb.Extensibility.NotificationSubscriber
    {
        public override void OnNotify(string notification, Dynamicweb.Extensibility.NotificationArgs args)
        {
            Dynamicweb.Notifications.eCommerce.Cart.CheckoutDoneOrderIsCompleteArgs myArgs = args as Dynamicweb.Notifications.eCommerce.Cart.CheckoutDoneOrderIsCompleteArgs;

            foreach (Dynamicweb.eCommerce.Orders.OrderLine ol in myArgs.Order.OrderLines)
            {
                if (ol.ProductNumber == "blah")
                {
                    
                    Dynamicweb.Modules.UserManagement.User u = new Dynamicweb.Modules.UserManagement.User();
                    u.Name = "something";
                    u.Save();

                    Dynamicweb.Modules.UserManagement.Group g = new Dynamicweb.Modules.UserManagement.Group("groupname");
                    g.AddUser(u.ID);
                    g.Save();
                }
            }
        }
    }
}

 

If you know the AccessUserID of the group you may just use:   u.AddToGroup(10);

- and leave out the UserManagement.Group part.

 

 

Regards /Snedker

 

 

You must be logged in to post in the forum