public void WillPostShipmentToBigCommerce() { BigCommerceController.bigCommerceOrderId = bigCommerceOrderId; Shipment shipmentToCreate = new Shipment(expectedCarrierOne, orderAddressId, itemFulfillmentIdOne, trackingNumberOne); Item itemOne = new Item(expectedOrderProductIdOne, itemQuantityOne); Item itemTwo = new Item(expectedOrderProductIdTwo, itemQuantityTwo); Item itemThree = new Item(expectedOrderProductIdThree, itemQuantityThree); shipmentToCreate.Items = new List <Item>() { itemOne, itemTwo, itemThree }; Shipment shipmentCreated = BigCommerceController.PostShipmentToBigCommerce(shipmentToCreate); Assert.Null(shipmentCreated.Status); Assert.Equal(itemFulfillmentIdOne, shipmentCreated.NetSuiteItemFulfillmentId); Assert.Equal(trackingNumberOne, shipmentCreated.TrackingNumber); Assert.Equal(expectedCarrierOne, shipmentCreated.ShippingProvider); Assert.Equal(orderAddressId, shipmentCreated.OrderAddressId); foreach (var item in shipmentCreated.Items) { int orderProductId = item.order_product_id; if (orderProductId != expectedOrderProductIdOne && orderProductId != expectedOrderProductIdTwo && orderProductId != expectedOrderProductIdThree) { throw new Exception($"Unexpected order product id {orderProductId}"); } else if (orderProductId == expectedOrderProductIdOne) { Assert.Equal(itemQuantityOne, item.quantity); } else if (orderProductId == expectedOrderProductIdTwo) { Assert.Equal(itemQuantityTwo, item.quantity); } else if (orderProductId == expectedOrderProductIdThree) { Assert.Equal(itemQuantityThree, item.quantity); } } // Get the status and assert that it is marked as shipped string orderStatus = GetOrderStatus(); Assert.Equal("Shipped", orderStatus); DeleteShipment(shipmentCreated.ShipmentId); }
public static void ImportShipmentsToBigCommerce(JArray allOrdersAwaitingShipments) { try { foreach (var order in allOrdersAwaitingShipments) { Order parsedOrder = JsonConvert.DeserializeObject <Order>(order.ToString()); BigCommerceController.bigCommerceOrderId = parsedOrder.id; Log.Information($"Big Commerce Order Id: {BigCommerceController.bigCommerceOrderId}"); // Query NetSuite to get any matching item fulfillments string netsuiteSalesOrderId = parsedOrder.staff_notes; /* Get a list of NetSuite item fulfillment ids (partially shipped orders only) that already exist * in Big Commerce to exclude so we do not create duplicate shipments. */ List <string> importedItemFulfillmentIds = new List <string>(); if (parsedOrder.status.ToLower() == "partially shipped") { importedItemFulfillmentIds = BigCommerceController.GetImportedItemFulfillments(); } var itemFulfillmentGroupsToImport = NetSuiteController.GetItemFulfillmentsNotImported(netsuiteSalesOrderId, importedItemFulfillmentIds); // Skip line if no item fulfillments are found if (itemFulfillmentGroupsToImport.Count() == 0) { Log.Information($"No item fulfillments to import."); continue; } // Send each item fulfillment group to Big Commerce as a Shipment foreach (var itemFulfillmentGroupToImport in itemFulfillmentGroupsToImport) { Log.Information($"Itfil ID: {itemFulfillmentGroupToImport.Key}"); BigCommerceController.currentItemFulfillment = itemFulfillmentGroupToImport; Shipment shipmentToCreate = BigCommerceController.CreateShipmentRequest(itemFulfillmentGroupToImport); // Big Commerce will throw exception if shipment does not have a tracking number if (shipmentToCreate.TrackingNumber == "") { Log.Warning($"No tracking numbers found. Shipment not created."); continue; } // Create the Shipment in Big Commerce try { Shipment shipmentCreated = BigCommerceController.PostShipmentToBigCommerce(shipmentToCreate); Log.Information($"shipment id {shipmentCreated.ShipmentId} created."); } catch (Exception ex) { string errorMessage = $"Error Posting Shipment To Big Commerce. Error: {ex}"; Log.Error(errorMessage); string title = "Error in NestProShipments PostShipmentToBigCommerce"; string text = errorMessage; string color = "yellow"; TeamsHelper teamsMessage = new TeamsHelper(title, text, color, Program.teamsUrl); teamsMessage.LogToMicrosoftTeams(teamsMessage); } } } } catch (Exception ex) { string errorMessage = $"Error in ImportShipmentsToBigCommerce. Error: {ex}"; Log.Error(errorMessage); string title = "Error in NestProShipments ImportShipmentsToBigCommerce"; string text = errorMessage; string color = "red"; TeamsHelper teamsMessage = new TeamsHelper(title, text, color, Program.teamsUrl); teamsMessage.LogToMicrosoftTeams(teamsMessage); } }