I am trying using product
Dynamicweb.eCommerce.Products.Product
Kind regards,
Dmitrij
Dynamicweb.eCommerce.Products.Product
Hi Dmitrij
If I understand you correctly, you want to know how many of a given product is in the Shopping Cart at the time the Cart is completed?
If that's the case then you'll want to create a notification subscriber to listen for CheckoutDoneOrderIsComplete. The CheckoutDoneOrderIsCompleteArgs object contains a reference to the Order object. Iterate through the OrderLines collection on the Order and check for your Product.
OrderIsPassedToCheckoutHandler
Dynamicweb.eCommerce.Products.ProductCollection
Dynamicweb.eCommerce.Products.Product
double totalCountOfProducts = 0.0; foreach (var orderline in order.OrderLines) { if (orderline.Product == myProduct) { totalCountOfProducts += orderline.Quantity; } }
public override void OnNotify(string notification, NotificationArgs args) { //errorMessage("Method called"); //Dynamicweb.Notifications.eCommerce.Cart.CheckoutDoneOrderIsCompleteArgs myArgs = (Dynamicweb.Notifications.eCommerce.Cart.CheckoutDoneOrderIsCompleteArgs)args; Dynamicweb.Notifications.eCommerce.Cart.OrderIsPassedToCheckoutHandlerArgs myArgs = (Dynamicweb.Notifications.eCommerce.Cart.OrderIsPassedToCheckoutHandlerArgs)args; string orderID = myArgs.Order.ID; string orderState = myArgs.Order.StateID; string orderDate = myArgs.Order.Date.ToLongDateString(); //... SqlConnection conn; SqlCommand comm; string connectionString = CONNSTR; conn = new SqlConnection(connectionString); 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(); // just for test purposes 7 is a standart ammount passed comm = new SqlCommand(query, conn); //OrderStateID comm.Parameters.AddWithValue("@OrderStateID", orderState); //... try { //... } catch (Exception) { errorMessage(status); } finally { } } catch { //... errorMessage(status); } finally { conn.Close(); status = "counter: " + counter.ToString(); } // PASSING PRODUCTS HERE passOrderProducts(myArgs.Order.Products); } // PRODUCTS PASSED - need to iterate through order products and gether information about them... private void passOrderProducts(Dynamicweb.eCommerce.Products.ProductCollection productCollection) { // SQL connection information etc... try { comm.Connection.Open(); foreach (Dynamicweb.eCommerce.Products.Product product in productCollection) { // just for test purposes 7 is a standart ammount passed comm = new SqlCommand(query, conn); //totalCount comm.Parameters.AddWithValue("@totalCount", product.); // <-- need to find how many products where added in the cart here // other parameters here... try { //... } catch (Exception) { //... errorMessage(status); } finally { } } try { } catch (Exception) { //... errorMessage(status); } finally { } } catch { //... errorMessage(status); } finally { conn.Close(); status = "counter: " + counter.ToString(); } }
I would recommend that instead of passing a ProductCollection to the passOrderProducts--or at least in addition to--you send the OrderLineCollection from myArgs.Order.OrderLines and iterate through that. Mainly because you need the number of products which the ProductCollection is unable to tell you.
You must be logged in to post in the forum