public void WillCreateAShipmentRequestWithPromoBundle() { BigCommerceController.bigCommerceOrderId = 2244; var kitId = 3854675; ItemFulfillmentLine itemFulfillmentLineOne = CreateItemFulfillmentLine(itemFulfillmentIdOne, carrierOne, itemSkuOne, trackingNumberOne, itemQuantityOne, kitId); ItemFulfillmentLine itemFulfillmentLineTwo = CreateItemFulfillmentLine(itemFulfillmentIdOne, carrierOne, itemSkuTwo, trackingNumberOne, itemQuantityOne, kitId); List <ItemFulfillmentLine> itemFulfillments = new List <ItemFulfillmentLine>() { itemFulfillmentLineOne, itemFulfillmentLineTwo }; var itemFulfillmentGroups = itemFulfillments.GroupBy(itfil => itfil.ItemFulfillmentId); foreach (var itemFulfillmentGroup in itemFulfillmentGroups) { BigCommerceController.currentItemFulfillment = itemFulfillmentGroup; Shipment shipmentToCreate = BigCommerceController.CreateShipmentRequest(itemFulfillmentGroup); Assert.Single(shipmentToCreate.Items); Assert.Equal(2287, shipmentToCreate.Items[0].order_product_id); Assert.Equal(1, shipmentToCreate.Items[0].quantity); } }
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); } }
public void WillCreateAShipmentRequest() { BigCommerceController.bigCommerceOrderId = 130; ItemFulfillmentLine itemFulfillmentLineOne = CreateItemFulfillmentLine(itemFulfillmentIdOne, carrierOne, itemSkuOne, trackingNumberOne, itemQuantityOne, null); ItemFulfillmentLine itemFulfillmentLineTwo = CreateItemFulfillmentLine(itemFulfillmentIdTwo, carrierTwo, itemSkuTwo, trackingNumberTwo, itemQuantityTwo, null); ItemFulfillmentLine itemFulfillmentLineThree = CreateItemFulfillmentLine(itemFulfillmentIdTwo, carrierTwo, itemSkuThree, trackingNumberTwo, itemQuantityThree, null); List <ItemFulfillmentLine> itemFulfillments = new List <ItemFulfillmentLine>() { itemFulfillmentLineOne, itemFulfillmentLineTwo, itemFulfillmentLineThree }; var itemFulfillmentGroups = itemFulfillments.GroupBy(itfil => itfil.ItemFulfillmentId); foreach (var itemFulfillmentGroup in itemFulfillmentGroups) { BigCommerceController.currentItemFulfillment = itemFulfillmentGroup; Shipment shipmentToCreate = BigCommerceController.CreateShipmentRequest(itemFulfillmentGroup); Assert.Equal(orderAddressId, shipmentToCreate.OrderAddressId); if (shipmentToCreate.NetSuiteItemFulfillmentId == itemFulfillmentIdOne) { Assert.Equal(trackingNumberOne, shipmentToCreate.TrackingNumber); Assert.Equal(expectedCarrierOne, shipmentToCreate.ShippingProvider); // Items foreach (var item in shipmentToCreate.Items) { Assert.Equal(expectedOrderProductIdOne, item.order_product_id); Assert.Equal(itemQuantityOne, item.quantity); } } else if (shipmentToCreate.NetSuiteItemFulfillmentId == itemFulfillmentIdTwo) { Assert.Equal(trackingNumberTwo, shipmentToCreate.TrackingNumber); Assert.Equal(expectedCarrierTwo, shipmentToCreate.ShippingProvider); // Items foreach (var item in shipmentToCreate.Items) { if (item.order_product_id == expectedOrderProductIdTwo) { Assert.Equal(expectedOrderProductIdTwo, item.order_product_id); Assert.Equal(itemQuantityTwo, item.quantity); } else if (item.order_product_id == expectedOrderProductIdThree) { Assert.Equal(expectedOrderProductIdThree, item.order_product_id); Assert.Equal(itemQuantityThree, item.quantity); } else { throw new Exception($"Unexpected order product id {item.order_product_id}"); } } } else { throw new Exception($"Unexpected item fulfillment id {shipmentToCreate.NetSuiteItemFulfillmentId}"); } } }