Beispiel #1
0
        public SingleItemRequest DecodeItemLink(string link)
        {
            try
            {
                var uri          = new Uri(link);
                var routeMatcher = new RouteMatcher();
                var values       = routeMatcher.Match(aliexpressItemLinkTemplate, uri.LocalPath);

                var singleItem = new SingleItemRequest()
                {
                    Source = "Aliexpress"
                };

                singleItem.Title = values.ContainsKey("itemTitle") ? values["itemTitle"].ToString() : String.Empty;
                singleItem.ID    = values.ContainsKey("itemid") ? values["itemid"].ToString() : String.Empty;
                singleItem.Link  = link;

                return(singleItem);
            }
            catch (Exception e)
            {
                return(new SingleItemRequest()
                {
                    Link = link
                });
            }
        }
        public override async Task <ItemDetail> SearchItem(SingleItemRequest item)
        {
            if (item.ID.EmptyOrNull() && item.Title.EmptyOrNull())
            {
                if (item.Link.EmptyOrNull())
                {
                    throw new AllowedException("ID, Title and Link cannot be empty");
                }

                item = new AliexpressQueryString().DecodeItemLink(item.Link);

                //Means there was a translation error in the URI format
                if (item.ID.EmptyOrNull() & item.Title.EmptyOrNull())
                {
                    return(null);
                }
            }

            string endpoint = SearchEndpoints.AliexpressItemUrl(item.Title, item.ID);

            var        response = "";
            ItemDetail detail   = null;

            try
            {
                var responseMessage = await http.Get(endpoint);

                response = await responseMessage.Content.ReadAsStringAsync();
            }
            catch (Exception e)
            {
            }

            try
            {
                detail = new AliexpressPageDecoder().ScrapeSingleItem(response);

                var freights = await CalculateFreight(new FreightAjaxRequest()
                {
                    ProductID    = item.ID,
                    Country      = item.ShipCountry,
                    CurrencyCode = "USD"
                });

                if (freights.Length > 0)
                {
                    var def = freights.FirstOrDefault(x => x.IsDefault == true);
                    detail.ShippingPrice = def.LocalPrice;
                    detail.ShippingType  = def.CompanyDisplayName;
                }
            }
            catch (Exception e)
            {
                await raven.CaptureNetCoreEventAsync(e);
            }

            return(detail);
        }
Beispiel #3
0
        public async Task <GroupResponse> GetSingleResponseAsync(SingleItemRequest request)
        {
            using var client = CreateElvantoClient("groups/getInfo");
            var response = await client.PostAsync("", new StringContent(JsonConvert.SerializeObject(request, Formatting.None), Encoding.UTF8, "application/json")).ConfigureAwait(false);

            await response.EnsureSuccessElvantoAsync().ConfigureAwait(false);

            return(await response.Content.ReadAsJsonAsync <GroupResponse>().ConfigureAwait(false));
        }
Beispiel #4
0
        public async Task <Group> GetInfoAsync(Guid groupId)
        {
            var request = new SingleItemRequest
            {
                Id = groupId
            };

            return((await GetSingleResponseAsync(request).ConfigureAwait(false))?.Groups.FirstOrDefault());
        }
        public async Task <HttpResponseMessage> AddProduct(SingleItemRequest item)
        {
            var json        = JsonConvert.SerializeObject(item);
            var jsonContent = new JsonContent(json);

            var response = await api.Post(ApiEndpoints.DropshipAddProduct, jsonContent);

            return(response);
        }
Beispiel #6
0
        public async Task <Person> GetInfoAsync(Guid personId)
        {
            var request = new SingleItemRequest
            {
                Id = personId
            };

            return(await GetInfoAsync(request));
        }
        public async Task <IActionResult> GetSingleItem([FromQuery] SingleItemRequest request)
        {
            var response = await search.ItemSearch(request);

            if (response == null)
            {
                return(NotFound());
            }

            return(Json(response));
        }
Beispiel #8
0
        public async Task <IActionResult> Add(SingleItemRequest item)
        {
            var response = await dropship.AddProduct(item);

            if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
            {
                return(RedirectToAction("Integrations"));
            }

            return(RedirectToAction("Products"));
        }
Beispiel #9
0
        public async Task <ItemDetail> ItemSearch(SingleItemRequest model)
        {
            var detail = new ItemDetail();

            switch (model.Source)
            {
            case "Aliexpress":
                detail = await services.First(x => x.ServiceType == SearchServiceType.Aliexpress).SearchItem(model);

                break;
            }

            return(detail);
        }
Beispiel #10
0
 public async Task <Group> GetInfoAsync(SingleItemRequest request)
 {
     return((await GetSingleResponseAsync(request).ConfigureAwait(false))?.Groups.FirstOrDefault());
 }
 public abstract Task <ItemDetail> SearchItem(SingleItemRequest item);
        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);
        }
Beispiel #13
0
 public override async Task <ItemDetail> SearchItem(SingleItemRequest item)
 {
     return(new ItemDetail());
 }
        private SingleItemRequest ConvertAliexpressURL(SingleItemRequest item)
        {
            var link = item.Link;

            return(new AliexpressQueryString().DecodeItemLink(link));
        }
Beispiel #15
0
 public async Task <Person> GetInfoAsync(SingleItemRequest request) => (await GetSingleResponseAsync(request))?.People.FirstOrDefault();
        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());
        }