public async Task <ShopifyProductModel> UpdateProduct(string username, ShopifyProductModel product, OAuthShopifyModel creds) { string endpoint = ShopifyEndpoints.BaseEndpoint(creds.Shop, "products") + $"/{product.ID}.json"; var requestType = new { Product = product }; var requestContent = JsonConvert.SerializeObject(requestType, jsonSettings); var content = new StringContent(requestContent); content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); var response = await http.Put(endpoint, content, (client) => { addAuthenticatoin(client, creds.AccessToken); }); string message = await response.Content.ReadAsStringAsync(); if (response.IsSuccessStatusCode) { var productResponse = JObject.Parse(message).SelectToken("product").ToString(); var ret = JsonConvert.DeserializeObject <ShopifyProductModel>(productResponse, jsonSettings); return(ret); } else { return(null); } }
public ShopifyProductModel MakeProductModel(ShopifyProduct input, bool includeVariantGraph = false) { var output = new ShopifyProductModel(); output.ProductTitle = input.ShopifyTitle; output.ProductType = input.ShopifyProductType; output.Vendor = input.ShopifyVendor; output.ShopifyProductId = input.ShopifyProductId; output.VariantCount = input.NonMissingVariants().Count(); output.ShopifyUrl = _shopifyUrlService.ShopifyProductUrl(input.ShopifyProductId); output.SyncedVariantCount = input.NonMissingVariants().Count(x => x.AcumaticaStockItems.Any()); if (includeVariantGraph) { output.Variants = input.NonMissingVariants().Select(x => MakeVariantModel(x)).ToList(); } return(output); }
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); }
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); }
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); }