//Obsolete version of this method /* public async Task AddProduct(string username, DropshipItemModel model) * { * if (model.Source.Link.EmptyOrNull()) * return; * * switch(model.Source.Source) * { * case "Aliexpress": * await AddProduct(username, model.Source); * break; * * default: * throw new Exception("Invalid DropshipItemModel Source"); * } * } */ //Obsolete method, this is now done in the DropshippingController /* * public async Task UpdateProduct(string username, DropshipItem item) * { * await shopify.UpdateProduct(username, item.Product); * } */ public async Task SyncProduct(string username, DropshipItem item) { var sourceItem = await search.ItemSearch(item.Dropshipping.Source); if (sourceItem == null) { return; } var rules = item.Dropshipping.Rules ?? DropshipListingRules.Default; var creds = await oauthdb.RetrieveOAuth <OAuthShopifyModel>(username); if (rules.ApplyRules(sourceItem, item.Product) && creds != null) { await shopify.UpdateProduct(username, item.Product, creds); } }
public async Task <IActionResult> Products(int page = 1) { var response = await api.Get(ApiEndpoints.DropshipGetProducts(productsPerPage * (page - 1), productsPerPage)); var products = new DropshipItem[0]; if (response.IsSuccessStatusCode) { var json = await response.Content.ReadAsStringAsync(); products = JsonConvert.DeserializeObject <DropshipItem[]>(json); } //Add total count for pagination ViewBag.MaxCount = response.Headers.Contains("X-Total-Count") ? Convert.ToInt32(response.Headers.GetValues("X-Total-Count").First()) : productsPerPage; ViewBag.Page = page; ViewBag.ItemsPerPage = productsPerPage; return(View(products)); }
public async Task <IActionResult> GetProduct(int itemid) { var username = HttpContext.User.Identity.Name; var oauth = await oauthdb.RetrieveOAuth <OAuthShopifyModel>(username); var item = await dbItems.GetOneByID(itemid); if (item.Username != username) { return(NotFound("No item was found")); } var shopifyItems = await shopify.GetProductsByID(username, new string[] { item.ListingID }, oauth); var dropshipItem = new DropshipItem() { Dropshipping = item, Product = shopifyItems.FirstOrDefault() }; return(Json(dropshipItem)); }
public async Task AddProduct(string username, SingleItemRequest item) { var detail = await search.ItemSearch(item); if (detail == null) { return; } //Get integration access tokens var oauth = await oauthdb.RetrieveOAuth <OAuthShopifyModel>(username); if (oauth == null) { return; } //Create the dropship item and model var dropshipItem = new DropshipItem() { Dropshipping = new DropshipItemModel() { Source = item, Username = item.Username, Rules = DropshipListingRules.Default, OAuthID = oauth.ID }, Product = new ShopifyProductModel() { BodyHtml = detail.Description, Title = detail.Name.Replace("/", "-"), //Fix slash in name issue Variants = new List <ShopifyVarant>() { new ShopifyVarant() { InventoryPolicy = InventoryPolicy.Deny, InventoryManagement = InventoryManagement.Shopify, RequiresShipping = true, Taxable = true } } } }; //Add images from shopify var images = new List <ShopifyImageType>(); foreach (var image in detail.ImageUrls) { images.Add(new ShopifyImageType() { Src = image }); } //Set the first image to the main dropship model image if (images.Count > 0) { dropshipItem.Dropshipping.Image = images[0].Src; } dropshipItem.Product.Images = images.ToArray(); //Apply dropshipping rules dropshipItem.Dropshipping.Rules.ApplyRules(detail, dropshipItem.Product); //Add product var product = await shopify.AddProduct(username, dropshipItem.Product, oauth); dropshipItem.Dropshipping.ListingID = product.ID; await dbItems.Save(dropshipItem.Dropshipping); }
public async Task <IActionResult> Add([FromBody] SingleItemRequest item) { var username = "******"; if (HttpContext.User.Identity.IsAuthenticated) { username = HttpContext.User.Identity.Name; } if (item.Link.EmptyOrNull() && !item.Title.EmptyOrNull() && !item.ID.EmptyOrNull()) { item.Link = SearchEndpoints.AliexpressItemUrl(item.Title, item.ID); } var detail = await search.ItemSearch(item); if (detail == null) { return(NotFound("Aliexpress link was incorrect")); } //Get integration access tokens var oauth = await oauthdb.RetrieveOAuth <OAuthShopifyModel>(username); if (oauth == null) { return(NotFound("No dropshipping integration setup for user")); } //Create the dropship item and model var dropshipItem = new DropshipItem() { Dropshipping = new DropshipItemModel() { Source = item, Username = username, Rules = DropshipListingRules.Default, OAuthID = oauth.ID }, Product = new ShopifyProductModel() { BodyHtml = detail.Description, Title = detail.Name.Replace("/", "-"), //Fix slash in name issue Variants = new List <ShopifyVarant>() { new ShopifyVarant() { InventoryPolicy = InventoryPolicy.Deny, InventoryManagement = InventoryManagement.Shopify, RequiresShipping = true, Taxable = true } } } }; if (detail.ImageUrls != null) { //Add images from shopify var images = new List <ShopifyImageType>(); foreach (var image in detail.ImageUrls) { images.Add(new ShopifyImageType() { Src = image }); } //Set the first image to the main dropship model image if (images.Count > 0) { dropshipItem.Dropshipping.Image = images[0].Src; } dropshipItem.Product.Images = images.ToArray(); } //Apply dropshipping rules dropshipItem.Dropshipping.Rules.ApplyRules(detail, dropshipItem.Product); //Add product var product = await shopify.AddProduct(username, dropshipItem.Product, oauth); dropshipItem.Dropshipping.ListingID = product.ID; await dbItems.InsertItem(dropshipItem.Dropshipping); return(Ok()); }
public async Task <IActionResult> AddToIntegration(int itemid) { var model = await dbItems.GetOneByID(itemid); var username = HttpContext.User.Identity.Name; model.Username = username; var oauth = await oauthdb.RetrieveOAuth <OAuthShopifyModel>(username); if (oauth == null) { return(NotFound("No integrations")); } var detail = await search.ItemSearch(model.Source); if (detail == null) { return(NotFound("Aliexpress source is incorrect")); } //Create the dropship item and model var dropshipItem = new DropshipItem() { Dropshipping = model, Product = new ShopifyProductModel() { BodyHtml = detail.Description, Title = detail.Name.Replace("/", "-"), //Fix slash in name issue Variants = new List <ShopifyVarant>() { new ShopifyVarant() { InventoryPolicy = InventoryPolicy.Deny, InventoryManagement = InventoryManagement.Shopify, RequiresShipping = true, Taxable = true } } } }; //Add images from shopify var images = new List <ShopifyImageType>(); foreach (var image in detail.ImageUrls) { images.Add(new ShopifyImageType() { Src = image }); } //Set the first image to the main dropship model image if (images.Count > 0) { dropshipItem.Dropshipping.Image = images[0].Src; } dropshipItem.Product.Images = images.ToArray(); //Apply dropshipping rules dropshipItem.Dropshipping.Rules.ApplyRules(detail, dropshipItem.Product); //Add product var product = await shopify.AddProduct(username, dropshipItem.Product, oauth); dropshipItem.Dropshipping.ListingID = product.ID; await dbItems.UpdateListing(dropshipItem.Dropshipping); return(Ok()); }