public void WillGetImportedItemFulfillmentIds()
        {
            int orderId    = 126;
            int shipmentId = 10;

            SetItemFulfillmentIdOnShipment(orderId, shipmentId);

            BigCommerceController.bigCommerceOrderId = orderId;
            List <string> importedItemFulfillmentIds = BigCommerceController.GetImportedItemFulfillments();

            Assert.Equal(itemFulfillmentId, importedItemFulfillmentIds[0]);
            Assert.Equal("Janes Order", importedItemFulfillmentIds[1]);

            RemoveItemFulfillmentId(orderId, shipmentId);
        }
Ejemplo n.º 2
0
        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);
            }
        }