private static void ImportOrdersToNetSuite(JArray ordersAwaitingFulfillment) { try { foreach (var order in ordersAwaitingFulfillment) { Order parsedOrder = JsonConvert.DeserializeObject <Order>(order.ToString()); if (parsedOrder.is_deleted == true) { Log.Information($"Skipping order {parsedOrder.customer_id} because it is marked as deleted/archived."); continue; } BigCommerceController.customerId = parsedOrder.customer_id; int bigCommerceOrderId = parsedOrder.id; Log.Information($"bigCommerceOrderId Id {bigCommerceOrderId}"); // Get the shipping information string shippingAddressUrl = parsedOrder.shipping_addresses.url; ShippingAddress customerShippingAddress = BigCommerceController.GetCustomerShippingAddress(shippingAddressUrl); // Format the request object to send to CreateCustomerRESTlet OrderToImport netsuiteRequest = NetSuiteController.CreateNetSuiteRequest(parsedOrder, customerShippingAddress); if (netsuiteRequest.NestProId == "") { // We alert these to B2B so they can contact the customer ordersMissingProId.Add(bigCommerceOrderId); continue; } netsuiteCustomerId = NetSuiteController.GetNetSuiteCustomerId(netsuiteRequest); netsuiteRequest.CustomerId = Convert.ToInt32(netsuiteCustomerId); // Call the Products API to get the products on the order string productsUrl = parsedOrder.products.url; netsuiteRequest.Items = BigCommerceController.GetProductsOnOrder(productsUrl); NetSuiteController.SetNetSuiteItemIdAndPersonalItemFlag(netsuiteRequest); // Import order to Netsuite string netsuiteOrderId = NetSuiteController.ImportOrderToNetSuite(netsuiteRequest); // Set the Big Commerce status to 'awaiting shipment' and add the NetSuite order ID to 'staff notes' BigCommerceController.SetOrderStatus(bigCommerceOrderId, netsuiteOrderId); } } catch (Exception ex) { Log.Error($"Error: {ex}"); string title = "Error in ImportOrdersToNetSuite"; string text = $"Error message: {ex.Message}"; string color = "red"; TeamsHelper teamsMessage = new TeamsHelper(title, text, color, errorLogsUrl); teamsMessage.LogToMicrosoftTeams(teamsMessage); } }
public void WillSetOrderStatusToAwaitingShipmentAndNetSuiteOrderId() { string netsuiteOrderId = "70169180"; var exception = Record.Exception(() => BigCommerceController.SetOrderStatus(bigCommerceOrderId, netsuiteOrderId)); string[] results = GetOrderStatusAndNetSuiteOrderId(bigCommerceOrderId); Assert.Null(exception); Assert.Equal(netsuiteOrderId, results[0]); Assert.Equal("Awaiting Shipment", results[1]); ResetOrderStatusAndNetSuiteOrderId(bigCommerceOrderId, netsuiteOrderId); }