private static bool ApplyStockRules(DropshipListingRules rules, ItemDetail detail, ShopifyProductModel product)
        {
            var actualStock = detail.Stock;
            var adjusted    = actualStock;

            switch (rules.StockRule)
            {
            case StockRule.FixedStock:
                adjusted = rules.Stock;
                break;

            case StockRule.StockAdjustment:
                adjusted = actualStock - rules.Stock;
                break;

            default:
                break;
            }

            if (adjusted < 0)
            {
                adjusted = 0;
            }                                   //cant have negative inventory

            var variant = product.Variants.FirstOrDefault() ?? new ShopifyVarant();

            if (variant.InventoryQuantity != adjusted)
            {
                variant.InventoryQuantity = adjusted;
                return(true);
            }

            return(false);
        }
        public static bool ApplyRules(this DropshipListingRules rules, ItemDetail detail, ShopifyProductModel product)
        {
            var changes = false;

            changes = changes.Consume(ApplyPricingRules(rules, detail, product));
            changes = changes.Consume(ApplyStockRules(rules, detail, product));

            return(changes);
        }
示例#3
0
        public string PriceAdjustment(DropshipListingRules rules)
        {
            var element = "";

            switch (rules.PriceRule)
            {
            case PriceRule.FixedPrice:
                break;

            case PriceRule.PriceAdjustment:
                if (rules.Price > 0)
                {
                    element += $"<i class=\"fa fa-angle-up\" aria-hidden=\"true\"></i> $ {rules.Price}";
                }
                else
                {
                    element += $"<i class=\"fa fa-angle-down\" aria-hidden=\"true\"></i> $ {rules.Price}";
                }
                break;

            case PriceRule.PricePercentage:
                element += $"{rules.Price} %";
                break;

            case PriceRule.None:
                element += "None";
                break;
            }

            return(element);

            /*
             * if(rules.FixedPricePercentage.HasValue)
             * {
             *  return (rules.FixedPricePercentage.Value * 100).ToString() + "%";
             * }
             *
             * if(rules.FixedPriceAdjustment.HasValue)
             * {
             *  var unit = (rules.FixedPriceAdjustment.Value > 0) ? "+" : "";
             *
             *  return unit + rules.FixedPriceAdjustment.ToString();
             * }
             *
             * if(rules.FixedPrice.HasValue)
             * {
             *  return rules.FixedPrice.ToString();
             * } */
        }
        private static bool ApplyPricingRules(DropshipListingRules rules, ItemDetail detail, ShopifyProductModel product)
        {
            var actualPrice = detail.Price + detail.ShippingPrice;
            var adjusted    = actualPrice;

            switch (rules.PriceRule)
            {
            case PriceRule.FixedPrice:
                adjusted = rules.Price;
                break;

            case PriceRule.PriceAdjustment:
                adjusted = actualPrice + rules.Price;
                break;

            case PriceRule.PricePercentage:
                adjusted = actualPrice * (1.00m + rules.Price / 100);     //Convert to percentage
                break;

            default:
                break;
            }

            if (adjusted < 0)
            {
                adjusted = 0.01m;
            }                                      //Cant have negative price

            var variant = product.Variants.FirstOrDefault() ?? new ShopifyVarant();

            if (variant.Price != Math.Truncate(adjusted * 100) / 100)
            {
                variant.Price = adjusted;
                return(true);
            }

            return(false);
        }
示例#5
0
        public string StockAdjustment(DropshipListingRules rules)
        {
            string element = "";

            switch (rules.StockRule)
            {
            case StockRule.FixedStock:
                element += $"{rules.Stock} Fixed";
                break;

            case StockRule.StockAdjustment:
                if (rules.Stock > 0)
                {
                    element += $"<i class=\"fa fa-angle-down\" aria-hidden=\"true\"></i> $ {rules.Stock}";
                }
                else
                {
                    element += $"<i class=\"fa fa-angle-up\" aria-hidden=\"true\"></i> $ {rules.Stock}";
                }
                break;
            }

            return(element);

/*
 *          if(rules.FixedStockAdjustment.HasValue)
 *          {
 *              var unit = (rules.FixedStockAdjustment.Value > 0) ? "+" : "";
 *
 *              return unit + rules.FixedStockAdjustment.ToString();
 *          }
 *
 *          if(rules.FixedStock.HasValue)
 *          {
 *              return rules.FixedStock.ToString();
 *          }
 */
        }