Ejemplo n.º 1
0
        public static void GetProductToUpdate(Dictionary <string, int> skusQuantities, WooCommerceProduct product, List <QuantityUpdate> productsToUpdate)
        {
            var productToUpdate = new QuantityUpdate(product, skusQuantities);

            if (productToUpdate.IsUpdateNeeded)
            {
                productsToUpdate.Add(productToUpdate);
            }
        }
Ejemplo n.º 2
0
        internal QuantityUpdate GetQuantityUpdate()
        {
            QuantityUpdate update = new QuantityUpdate()
            {
                pid      = 1,
                oid      = 1,
                quantity = 2
            };

            return(update);
        }
Ejemplo n.º 3
0
        public void QuantityUpdate_SkuNotFound()
        {
            var testsku        = Testsku;
            var skusQuantities = new Dictionary <string, int>
            {
                { testsku, 3 }
            };
            var variation = new WooCommerceVariation
            {
                Id            = 1,
                Sku           = "another sku",
                Quantity      = 1,
                ManagingStock = true
            };

            var result = new QuantityUpdate(variation, skusQuantities);

            Assert.IsFalse(result.IsUpdateNeeded);
        }
Ejemplo n.º 4
0
        public void QuantityUpdate_QuantityUnchanged()
        {
            var testsku        = Testsku;
            var skusQuantities = new Dictionary <string, int>
            {
                { testsku, 1 }
            };
            var product = new WooCommerceProduct
            {
                Id            = 1,
                Sku           = testsku,
                Quantity      = 1,
                ManagingStock = true
            };

            var result = new QuantityUpdate(product, skusQuantities);

            Assert.IsFalse(result.IsUpdateNeeded);
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> ChangeQuantity([FromBody] QuantityUpdate quantity)
        {
            //get the  order
            var order = await DAL.GetOrder(quantity.oid);

            if (order == null)
            {
                return(BadRequest());
            }
            //get pizza
            var pizza = await DAL.GetPizza(quantity.pid);

            if (pizza == null)
            {
                return(BadRequest());
            }

            GetToppings(pizza);
            var tempPrice   = pizza.Price;
            var oldQuantity = pizza.Quantity;

            //update new quantity and the price of pizza;
            pizza.Quantity = quantity.quantity;

            pizza.Price      = TotalPrice(pizza);
            order.Price      = order.Price - tempPrice + pizza.Price;
            order.TotalPizza = order.TotalPizza - oldQuantity + pizza.Quantity;
            PizzaAndOrder update = new PizzaAndOrder()
            {
                PizzaPrice         = pizza.Price,
                OrderTotalQuantity = order.TotalPizza,
                OrderTotalPrice    = order.Price
            };
            //update both order and pizza detail
            await DAL.UpdateOrder(order);

            await DAL.UpdatePizza(pizza);

            return(Ok(update));
        }
Ejemplo n.º 6
0
        public void QuantityUpdate_CaseInsensitiveSkuUpdatesInventory()
        {
            var skusQuantities = new Dictionary <string, int>
            {
                { Testsku, 3 }
            };
            var testSkuUpper = Testsku.ToUpper();
            var variation    = new WooCommerceVariation
            {
                Id            = 1,
                Sku           = testSkuUpper,
                Quantity      = 1,
                ManagingStock = true
            };

            var result = new QuantityUpdate(variation, skusQuantities);

            Assert.IsTrue(result.IsUpdateNeeded);
            Assert.AreEqual(variation.Id, result.Id);
            Assert.AreEqual(variation.Sku.ToLower(), result.Sku.ToLower());
            Assert.AreEqual(skusQuantities[Testsku], result.Quantity);
        }
Ejemplo n.º 7
0
        public void QuantityUpdate_BlankQuantityInWooCommerce()
        {
            var testsku        = Testsku;
            var skusQuantities = new Dictionary <string, int>
            {
                { testsku, 3 }
            };
            var variation = new WooCommerceVariation
            {
                Id            = 1,
                Sku           = testsku,
                Quantity      = null,
                ManagingStock = true
            };

            var result = new QuantityUpdate(variation, skusQuantities);

            Assert.IsTrue(result.IsUpdateNeeded);
            Assert.AreEqual(variation.Id, result.Id);
            Assert.AreEqual(variation.Sku, result.Sku);
            Assert.AreEqual(skusQuantities[testsku], result.Quantity);
        }
Ejemplo n.º 8
0
        public void QuantityUpdate_QuantityChanged()
        {
            var testsku        = Testsku;
            var skusQuantities = new Dictionary <string, int>
            {
                { testsku, 3 }
            };
            var product = new WooCommerceProduct
            {
                Id            = 1,
                Sku           = testsku,
                Quantity      = 1,
                ManagingStock = true
            };

            var result = new QuantityUpdate(product, skusQuantities);

            Assert.IsTrue(result.IsUpdateNeeded);
            Assert.AreEqual(product.Id, result.Id);
            Assert.AreEqual(product.Sku, result.Sku);
            Assert.AreEqual(skusQuantities[testsku], result.Quantity);
        }
Ejemplo n.º 9
0
 private bool IsQuantityUpdated(KNSIKCInventoryItem kcProduct)
 {
     return(QuantityUpdate.SelectSingle(kcProduct.UsrKCCASyncDate) != null);
 }