/// <summary> /// NewInternationalConsignment controller /// Based on the specified order IDs by Shopify, write required variables /// to front-end in hidden inputs for further queries /// International only process one order at a time /// Filter out domestic orders /// </summary> public async Task <ActionResult> NewInternationalConsignment(string shop, string[] ids) { //Get order numbers string orders = Request.QueryString["ids[]"]; if (orders.Contains(',')) { Response.Write("<input id='shopUrl' type='hidden' value='" + shop + "'>"); //passing shopUrl to View() for further queries Response.Write("<input id='addString' type='hidden' value='" + "MoreThanOne" + "'>"); //passing shopUrl to View() for further queries return(View()); } else { //DB connection required to query store details DbEngine conn = new DbEngine(); //Get Shopify Token to access Shopify API string token = conn.GetStringValues(shop, "ShopifyToken"); int cCode = conn.GetIntergerValues(shop, "CountryCode"); //ShopifyAPI object ShopifyAPI api = new ShopifyAPI(); Order o = await api.GetOrder(shop, token, orders); string address = ""; string email = ""; JavaScriptSerializer jsonSerialiser = new JavaScriptSerializer(); if (o.ShippingAddress.Country != "New Zealand") { address = jsonSerialiser.Serialize(o.ShippingAddress); email = o.Email; } Response.Write("<input id='shopUrl' type='hidden' value='" + shop + "'>"); //passing shopUrl to View() for further queries Response.Write("<input id='emailString' type='hidden' value='" + email + "'>"); //passing address string to View() for further queries Response.Write("<input id='addString' type='hidden' value='" + address + "'>"); //passing address string to View() for further queries return(View()); } }
/// <summary> /// NewConsignment controller /// Based on the specified order IDs by Shopify, write required variables /// to front-end in hidden inputs for further queries /// Used for both single or multiple orders /// Filter out international orders /// </summary> public async Task <ActionResult> NewConsignment(string shop, string[] ids, string id) { //Get order numbers string orders; if (id != null) { orders = id; } else { orders = Request.QueryString["ids[]"]; if (orders == null) { orders = Request.QueryString["ids[][]"]; } } //required objects List <string> orderIds = new List <string>(); //list of orderIds List <string> processingOrderIds = new List <string>(); //list of orderIds List <string> processingOrderPreferences = new List <string>(); //list of orderIds List <Order> orderDetails = new List <Order>(); //list of order details List <ShopifySharp.Address> deliveryAddress = new List <ShopifySharp.Address>(); //list of delivery details List <string> emails = new List <string>(); //list of emails addresses if (orders == null || orders == "") //No order select (in case customer reach this page from outside of their admin page { return(View()); //NOTE: might need to redirect them to their admin page } if (orders.Contains(','))//if there are more than one order { //get a list of order numbers received orderIds = orders.Split(',').ToList(); } else { //get a list of ONE order number orderIds.Add(orders); } //DB connection required to query store details DbEngine conn = new DbEngine(); //Get Shopify Token to access Shopify API string token = conn.GetStringValues(shop, "ShopifyToken"); int cCode = conn.GetIntergerValues(shop, "CountryCode"); List <CustomParcel> lCustomParcels = conn.GetCustomParcel(shop); //ShopifyAPI object ShopifyAPI api = new ShopifyAPI(); //foreach order number from list, get a list of delivery details for (int i = 0; i < orderIds.Count; i++) { //get the order with order number Order k = await api.GetOrder(shop, token, orderIds[i]); if (k.ShippingAddress != null) {//if shipping address exist, add to list of delivery details bool check = true; //check if order is international switch (cCode) { case 6: if (k.ShippingAddress.Country != "New Zealand") { check = false; } break; case 1: if (k.ShippingAddress.Country != "Australia") { check = false; } break; } //check if duplicate addresses if (deliveryAddress.Count > 0) { for (var l = 0; l < deliveryAddress.Count; l++) { if (deliveryAddress[l].Name == k.ShippingAddress.Name) { check = false; break; } } } if (check == true) { deliveryAddress.Add(k.ShippingAddress); emails.Add(k.Email); processingOrderIds.Add(orderIds[i]); processingOrderPreferences.Add(k.OrderNumber.ToString()); } } orderDetails.Add(k);//add order details into list of order details } ////jsonserialiser object to form json from list JavaScriptSerializer jsonSerialiser = new JavaScriptSerializer(); ////creating json about orders to pass back to View() //string orderJson = jsonSerialiser.Serialize(orderDetails); string stringCP = jsonSerialiser.Serialize(lCustomParcels); string stringOrderReference = string.Join(",", processingOrderPreferences); //Forming data to pass back string address = ""; string note = ""; string addresses = ""; string strOrderIds = ""; if (deliveryAddress.Count == 0) {//No delivery address found address = "NoAddress"; } else if (deliveryAddress.Count > 1) {//More than one addresses found address = "MoreThanOne"; addresses = jsonSerialiser.Serialize(deliveryAddress); strOrderIds = string.Join(",", processingOrderIds); } else {//one address address = jsonSerialiser.Serialize(deliveryAddress[0]); switch (cCode) { case 6: if (deliveryAddress[0].Country != "New Zealand") { address = "International"; } break; case 1: if (deliveryAddress[0].Country != "Australia") { address = "International"; } break; } for (int i = 0; i < orderDetails.Count; i++) { if (orderDetails[i].Note != "") { note += orderDetails[i].Note; } } } Response.Write("<input id='shopUrl' type='hidden' value='" + shop + "'>"); //passing shopUrl to View() for further queries Response.Write("<input id='cpStrings' type='hidden' value='" + stringCP + "'>"); //passing Custom Parcels if any to View() for further queries Response.Write("<input id='orderReference' type='hidden' value='" + stringOrderReference + "'>"); //passing order reference number if any to View() for further queries Response.Write("<input id='countryCode' type='hidden' value='" + cCode + "'>"); //passing countryCode to View() for further queries Response.Write("<input id='orderDetails' type='hidden' value='" + orders + "'>"); //passing orderIds to View() for further queries Response.Write("<input id='deliveryAddress' type='hidden' value='" + address + "'>"); //passing address to View() for further queries Response.Write("<input id='ordersAddresses' type='hidden' value='" + addresses + "'>"); //passing ordersdetails to View() for further queries Response.Write("<input id='orderIds' type='hidden' value='" + strOrderIds + "'>"); //passing ordersdetails to View() for further queries if (emails.Count >= 1) { Response.Write("<input id='emailAddress' type='hidden' value='" + string.Join(",", emails) + "'>"); //passing email address } if (note != "") { Response.Write("<input id='specialInstruction' type='hidden' value='" + note + "'>"); } return(View()); }
/// <summary> /// Listen to calls from shopify admin page, receive shop url and order ids. Parse orders and pass details to View() /// </summary> /// <param name="shop">shopUrl received from Shopify</param> /// <param name="ids">orderIds received from Shopify</param> /// <returns></returns> public async Task <ActionResult> NewConsignment(string shop, string[] ids) { //Get order numbers string orders = Request.QueryString["ids[]"]; //required objects List <string> orderIds = new List <string>(); //list of orderIds List <Order> orderDetails = new List <Order>(); //list of order details List <Address> deliveryAddress = new List <Address>(); //list of delivery details List <string> emails = new List <string>(); //list of emails addresses if (orders == null) //No order select (in case customer reach this page from outside of their admin page { return(View()); //NOTE: might need to redirect them to their admin page } if (orders.Contains(','))//if there are more than one order { //get a list of order numbers received orderIds = orders.Split(',').ToList(); } else { //get a list of ONE order number orderIds.Add(orders); } //DB connection required to query store details DbEngine conn = new DbEngine(); //Get Shopify Token to access Shopify API string token = conn.GetStringValues(shop, "ShopifyToken"); int cCode = conn.GetIntergerValues(shop, "CountryCode"); //ShopifyAPI object ShopifyAPI api = new ShopifyAPI(); //foreach order number from list, get a list of delivery details for (int i = 0; i < orderIds.Count; i++) { //get the order with order number Order k = await api.GetOrder(shop, token, orderIds[i]); if (k.ShippingAddress != null) {//if shipping address exist, add to list of delivery details bool check = true; if (deliveryAddress.Count > 0) { for (var l = 0; l < deliveryAddress.Count; l++) { if (deliveryAddress[l].Name == k.ShippingAddress.Name) { check = false; } } } if (check == true) { deliveryAddress.Add(k.ShippingAddress); emails.Add(k.Email); } } orderDetails.Add(k);//add order details into list of order details } ////jsonserialiser object to form json from list JavaScriptSerializer jsonSerialiser = new JavaScriptSerializer(); ////creating json about orders to pass back to View() //string orderJson = jsonSerialiser.Serialize(orderDetails); //creating json about delivery address to pass back to View() string address = ""; string note = ""; if (deliveryAddress.Count == 0) {//No delivery address found address = "NoAddress"; } else if (deliveryAddress.Count > 1) {//More than one addresses found address = "MoreThanOne"; } else {//one address address = jsonSerialiser.Serialize(deliveryAddress[0]); for (int i = 0; i < orderDetails.Count; i++) { if (orderDetails[i].Note != "") { note += orderDetails[i].Note; } } } Response.Write("<input id='shopUrl' type='hidden' value='" + shop + "'>"); //passing shopUrl to View() for further queries Response.Write("<input id='countryCode' type='hidden' value='" + cCode + "'>"); //passing countryCode to View() for further queries Response.Write("<input id='orderDetails' type='hidden' value='" + orders + "'>"); //passing orderIds to View() for further queries Response.Write("<input id='deliveryAddress' type='hidden' value='" + address + "'>"); //passing address to View() for further queries if (emails.Count >= 1) { Response.Write("<input id='emailAddress' type='hidden' value='" + emails[0] + "'>"); //passing email address } if (note != "") { Response.Write("<input id='specialInstruction' type='hidden' value='" + note + "'>"); } return(View()); }