public void WillGetBasePriceAndQuantityOfProductsOnOrder()
        {
            string productsUrl = $"{BigCommerceHelper.baseUrl}/{bigCommerceOrderId}/products";

            List <Product> productsOnOrder = BigCommerceController.GetProductsOnOrder(productsUrl);

            foreach (var product in productsOnOrder)
            {
                if (product.id < 36 && product.id > 38)
                {
                    throw new Exception($"Unexpected product ID {product.id}");
                }
                else if (product.id == 36)
                {
                    Assert.Equal("149.0000", product.BasePrice);
                    Assert.Equal("149.0000", product.BaseTotal);
                    Assert.Equal(1, product.Quantity);
                    Assert.Equal("T3019US", product.Sku);
                }
                else if (product.id == 37)
                {
                    Assert.Equal("860.0000", product.BasePrice);
                    Assert.Equal("2580.0000", product.BaseTotal);
                    Assert.Equal(3, product.Quantity);
                    Assert.Equal("T3032US", product.Sku);
                }
                else if (product.id == 38)
                {
                    Assert.Equal("221.4500", product.BasePrice);
                    Assert.Equal("1107.2500", product.BaseTotal);
                    Assert.Equal(5, product.Quantity);
                    Assert.Equal("T3016US", product.Sku);
                }
            }
        }
Exemplo n.º 2
0
        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 WillGetProductsOnOrder()
        {
            string productsApiUrl       = $"{BigCommerceHelper.baseUrl}/{bigCommerceOrderId}/products";
            int    expectedProductCount = 3;

            List <Product> productsOnOrder = BigCommerceController.GetProductsOnOrder(productsApiUrl);

            Assert.Equal(expectedProductCount, productsOnOrder.Count);
        }