Developer forum

Forum » Development » "Giro kort" checkout complete event question?

"Giro kort" checkout complete event question?

Dmitrij Jazel
Reply
Hello DW guys,
I am trying to get to the event that happens right after the user is done with shopping and clicks on the checkout button.
No matter if transaction was successful or not.
The user will only have a possibility to pay via check "giro kort in danish".
I am using Dynamicweb version 8.0.1.3

I am subscribing to 
[Subscribe(Dynamicweb.Notifications.eCommerce.Cart.CheckoutDoneOrderIsComplete)]
aswell as : 
[Subscribe(Dynamicweb.Notifications.eCommerce.Cart.CheckoutDoneOrderIsNotComplete)]
But on notify method does not seem to be called...
Not sure what can I do to fix this one...

Regards,
Dmitrij

Replies

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi Dmitrij,
 

Can you show the full code for the OnNotify method?
 

Imar

 
Dmitrij Jazel
Reply
Hello Imar,
Here is the implementation:
//[Subscribe(Dynamicweb.Notifications.eCommerce.Cart.CheckoutDoneOrderIsComplete)]

    [Subscribe(Dynamicweb.Notifications.eCommerce.Cart.CheckoutDoneOrderIsNotComplete)]
    public class CheckoutHandler1 : NotificationSubscriber
    {
        // just a basic connection string here
        private string CONNSTR;
        
        public override void OnNotify(string notification, NotificationArgs args)
        {
			// my debugging method
			errorMessage("Method called");

            //Dynamicweb.Notifications.eCommerce.Cart.CheckoutDoneOrderIsCompleteArgs myArgs = (Dynamicweb.Notifications.eCommerce.Cart.CheckoutDoneOrderIsCompleteArgs)args;
            Dynamicweb.Notifications.eCommerce.Cart.CheckoutDoneOrderIsNotCompleteArgs myArgs = (Dynamicweb.Notifications.eCommerce.Cart.CheckoutDoneOrderIsNotCompleteArgs)args;
            string orderID = myArgs.Order.ID;

            string orderState = myArgs.Order.StateID;
            string orderDate = myArgs.Order.Date.ToLongDateString();
            string orderTime = myArgs.Order.Date.ToLongTimeString();
            string totalPrice = myArgs.Order.TotalPrice.ToString();
            // OrderDeliveryData - hardcoded
            string orderStatus = "processing";// my order status - processing.
            string orderUserName = myArgs.Order.CustomerAccessUserUserName;
            string orderAdress = myArgs.Order.CustomerAddress;

            string orderSeller = "DJ";

            string orderOurRef = "CHI";
            string orderTheirRef = "C5ref";
            string orderTheirRek = "C5rek";

            //foreach (Dynamicweb.eCommerce.Products.Product product in myArgs.Order.Products)
            //{
            //    // list products here...
            //    // product. and import them to the 
            //}

            // TODO: make SQL insert here.

            string status = "";
            SqlConnection conn;
            SqlCommand comm;

            string connectionString = CONNSTR;
            conn = new SqlConnection(connectionString);

			// insert into my table
            string query = "INSERT INTO EXPORT_ORDERS Values (@OrderStateID, @OrderNr, @OrderDate, @OrderTime, @OrderTotalPrice, @OrderDeliveryData, @OrderStatus, @OrderUserName, @OrderAdress, @OrderSeller, @OrderOurRef, @OrderTheirRef, @OrderTheirRek, @MyOrderStatus)";

            comm = new SqlCommand(query, conn);

            int counter = 1;
            try
            {
                comm.Connection.Open();

                comm = new SqlCommand(query, conn);
                //OrderStateID
                comm.Parameters.AddWithValue("@OrderStateID", orderState);
                //OrderNr
                comm.Parameters.AddWithValue("@OrderNr", orderID);
                //OrderDate
                comm.Parameters.AddWithValue("@OrderDate", orderDate);
                //OrderTime
                comm.Parameters.AddWithValue("@OrderTime", orderTime);
                //OrderTotalPrice
                comm.Parameters.AddWithValue("@OrderTotalPrice", totalPrice);
                //OrderDeliveryData
                comm.Parameters.AddWithValue("@OrderDeliveryData", "deliveryDataReference");
                //OrderStatus
                comm.Parameters.AddWithValue("@OrderStatus", orderStatus);
                //OrderUserName
                comm.Parameters.AddWithValue("@OrderUserName", orderUserName);
                //OrderAdress
                comm.Parameters.AddWithValue("@OrderAdress", orderAdress);
                //OrderSeller
                comm.Parameters.AddWithValue("@OrderSeller", orderSeller);
                //OrderOurRef
                comm.Parameters.AddWithValue("@OrderOurRef", orderOurRef);
                //OrderTheirRef
                comm.Parameters.AddWithValue("@OrderTheirRef", orderTheirRef);
                //OrderTheirRek
                comm.Parameters.AddWithValue("@OrderTheirRek", orderTheirRek);
                //MyOrderStatus
                comm.Parameters.AddWithValue("@MyOrderStatus", "myStatus");

                try
                {
                    comm.ExecuteNonQuery();
                    counter++;
                    status = "counter++ passed";
                    status = "executeNonQuery passed";
                }
                catch (Exception)
                {
                    status = "Could not execute order insert";
                    errorMessage(status);
                }
                finally
                {
				
                }
            }
            catch
            {
                status = "ERROR AT ORDER counter ID " + counter.ToString();
                errorMessage(status);
            }
            finally
            {
                conn.Close();
                status = "counter: " + counter.ToString();
            }
            passOrderProducts(myArgs.Order.Products);

            ////Product product = new Dynamicweb.eCommerce.Products.Product("ProductID");Order order =Dynamicweb.eCommerce.Common.Context.Cart;

            ////Dynamicweb.eCommerce.Orders.
            ////order.Products.Add(product);

            // ... do stuff

        }

I just want to call the first line since I need to call the method to see the message displayed to make sure the method is called. but I can't see that it is called.

regards,
Dmitrij
 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply
This post has been marked as an answer
Hi Dmitrij,

According to the docs, this subscriber is called *after* the checkout handler passes the order back to Dynamicweb. Is that the location you want to hook into? According to your description, you expect this handler to fire before it is passed to the handler.

Maybe OrderIsPassedToCheckoutHandler is a better subscriber?


Imar

Votes for this answer: 0
 
Dmitrij Jazel
Reply
Hello Imar,
And yes, that was the handler I needed to call.
Thank you very much for quick response :)))

kind regards,
Dmitrij

 

You must be logged in to post in the forum