Dear Support
We had created a custom order line field in checkout page to let the customer choose the delivery date for order line item. I’ve tried a few ways but still there are some issue in different scenarios below.
For case 1 and 2 below, I have written this javascript function to call cartcmd command in custom.js file.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
var SetDeliveryDate = function (cartOrderlinesFeedPageId, orderLineId, productId, quantity, deliveryDate, minDeliveryDate) {
var deliveryDatePara = '&EcomOrderLineFieldInput_Deliverydate=' + deliveryDate;
deliveryDate = new Date(deliveryDate);
minDeliveryDate = new Date(minDeliveryDate);
clearTimeout(updateDelay);
if (deliveryDate >= minDeliveryDate) {
updateDelay = setTimeout(function () {
Cart.UpdateCart('Cart', '/Default.aspx?ID=' + cartOrderlinesFeedPageId,
'CartCmd=DelOrderLine&key=' + orderLineId + '&redirect=false',
true);
Cart.UpdateCart('Cart',
'/Default.aspx?ID=' + cartOrderlinesFeedPageId,
'CartCmd=add&productid=' + productId + '&quantity=' + quantity + deliveryDatePara + '&redirect=false',
true);
}, 800);
} else {
alert("Please choose a delivery date later than " + minDeliveryDate.getDate() + "-" + (minDeliveryDate.getMonth() + 1) + "-" + minDeliveryDate.getFullYear());
}
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- Remove the order line and recreate it with custom orderline value using “cartcmd = add”
For this case, the orderline is recreated with the correct delivery date but user didn’t accept this as the order line will move to last in order summary page (Sorting is not according to the added items). Refer to this video to see the effect, https://www.loom.com/share/7612b4f977764a7cbb8c0ae02220b057
- Did not remove the order line but use the “cartcmd=add” to send the custom order line value
For this case, the new order line is created (duplicate order line) with the correct delivery date at the last position in the cart. Since it create duplicate and order lines didn’t merge as custom order line field value is different.
- I tried the last solution to update the database directly by using custom code below. I am able to see the data is updated if I query using sql but custom order line field values are reset as blank after page is loaded and the value is gone if I query again in database.
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
var cmdBuilder = new CommandBuilder();
cmdBuilder.Add(@"select OrderLineFieldValues FROM [EcomOrderLines] where OrderLineId={0}", orderLineId);
var deliveryDate = HttpContext.Current.Request.QueryString.Get("EcomOrderLineFieldInput_Deliverydate");
var orderLineCustomFields = "";
using (System.Data.IDataReader dr = Dynamicweb.Data.Database.CreateDataReader(cmdBuilder))
{
while (dr.Read())
{
orderLineCustomFields = dr["OrderLineFieldValues"].ToString();
}
}
XmlDocument doc = new XmlDocument();
doc.LoadXml(orderLineCustomFields);
//var nodes = doc.SelectNodes("//OrderLineFieldValueCollection/OrderLineFieldValue");
XmlNodeList xmlnodes = doc.SelectNodes("OrderLineFieldValueCollection/OrderLineFieldValue");
foreach (XmlNode x in xmlnodes)
{
if (x["OrderLineFieldSystemName"].InnerText == "Deliverydate")
{
x["Value"].InnerText = deliveryDate;
}
}
cmdBuilder = new CommandBuilder();
cmdBuilder.Add(@"update [EcomOrderLines] set OrderLineFieldValues={0} where OrderLineId={1}", doc.InnerXml, orderLineId);
Database.ExecuteNonQuery(cmdBuilder);
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Looking forward to hear from you.
Thank you
Pang Lin