Esempio n. 1
0
        internal static IEnumerable <ShopifyProduct> GetShopifyAllProduct(ShopifyProductService shopifyProductService, string fields = null)
        {
            var listProduct = default(Task <IEnumerable <ShopifyProduct> >);
            var allProducts = new List <ShopifyProduct>();
            var page        = 1;

            do
            {
                ShopifyCall.ExecuteCall(delegate()
                {
                    listProduct = shopifyProductService.ListAsync(new ShopifyProductFilterOptions
                    {
                        PublishedStatus = "any",
                        Limit           = 250,
                        Page            = page,
                        Fields          = fields
                    });

                    listProduct.Wait();
                });

                allProducts.AddRange(listProduct.Result);

                page++;
            }while (listProduct.Result.Count() == 250);

            return(allProducts);
        }
Esempio n. 2
0
        internal static IEnumerable <ShopifyOrder> GetShopifyOpenOrders(ShopifyOrderService shopifyOrderService)
        {
            var listOrder = default(Task <IEnumerable <ShopifyOrder> >);
            var orders    = new List <ShopifyOrder>();
            var page      = 1;

            do
            {
                ShopifyCall.ExecuteCall(delegate()
                {
                    listOrder = shopifyOrderService.ListAsync(new ShopifyOrderFilterOptions
                    {
                        Limit  = 250,
                        Status = ShopifyOrderStatus.Open,
                        Page   = page
                    });

                    listOrder.Wait();
                });

                orders.AddRange(listOrder.Result);

                page++;
            }while (listOrder.Result.Count() == 250);

            return(orders);
        }
Esempio n. 3
0
        internal static ShopifyProduct UpdateVariantsOnShopify(ShopifyProductService shopifyProductService, AliShopifyProduct refProduct, ShopifyProduct shopifyProduct)
        {
            var updateShopifyProduct = default(ShopifyProduct);

            if (shopifyProduct.Variants.Any())
            {
                shopifyProduct.Variants = shopifyProduct.Variants
                                          .Select(delegate(ShopifyProductVariant shopifyVariant)
                {
                    if (string.IsNullOrWhiteSpace(shopifyVariant.SKU) && shopifyProduct.Variants.Count() == 1)
                    {
                        return(shopifyVariant);
                    }

                    var variant = refProduct.AliProduct.AliProductVariant.FirstOrDefault(i => i.AliProductVariantId.ToString() == shopifyVariant.SKU);

                    if (variant == null || !variant.Enabled)
                    {
                        return(null);
                    }

                    var shopifyImage = default(ShopifyProductImage);

                    if (variant.AliProductImage != null)
                    {
                        shopifyImage = ShopifyHelper.GetShopifyImageFromUrl(variant.AliProductImage.Url, shopifyProduct.Images);
                    }

                    if (shopifyImage != null)
                    {
                        shopifyVariant.ImageId = shopifyImage.Id;
                    }

                    return(shopifyVariant);
                })
                                          .Where(i => i != null)
                                          .ToArray();

                ShopifyCall.ExecuteCall(delegate()
                {
                    var task = shopifyProductService.UpdateAsync(shopifyProduct);

                    task.Wait();

                    updateShopifyProduct = task.Result;
                });
            }

            return(updateShopifyProduct ?? shopifyProduct);
        }
Esempio n. 4
0
        internal static ShopifyProduct GetProductOnShopify(ShopifyProductService shopifyProductService, string handle)
        {
            var shopifyProduct = default(ShopifyProduct);

            ShopifyCall.ExecuteCall(delegate()
            {
                var task = shopifyProductService.ListAsync(new ShopifyProductFilterOptions
                {
                    Handle = handle
                });

                task.Wait();

                shopifyProduct = task.Result.FirstOrDefault();
            });

            return(shopifyProduct);
        }
Esempio n. 5
0
        internal static ShopifyProduct UnpublishProductOnShopify(ShopifyProductService shopifyProductService, long shopifyProductId)
        {
            var updateShopifyProduct = default(ShopifyProduct);
            var shopifyProduct       = new ShopifyProduct
            {
                Id        = shopifyProductId,
                Published = false
            };

            ShopifyCall.ExecuteCall(delegate()
            {
                var task = shopifyProductService.UpdateAsync(shopifyProduct);

                task.Wait();

                updateShopifyProduct = task.Result;
            });

            return(updateShopifyProduct);
        }
Esempio n. 6
0
        public static ShopifyCall StartCall()
        {
            var maximumAchieved = false;
            var maximumBucket   = false;
            var call            = default(ShopifyCall);

            do
            {
                lock (Calls)
                {
                    var lastMinute = DateTime.UtcNow;
                    var lastSecond = DateTime.UtcNow;

                    lastMinute = lastMinute.AddMinutes(-1);
                    lastSecond = lastSecond.AddSeconds(-1);

                    Calls.RemoveWhere(i => i.StartDate < lastMinute);

                    maximumAchieved = Calls.Count(i => i.StartDate >= lastSecond) >= MaxCallPerSecond;
                    maximumBucket   = Calls.Count(i => i.StartDate >= lastMinute) >= MaxBucketSize;

                    if (!maximumAchieved && !maximumBucket)
                    {
                        call = new ShopifyCall(Guid.NewGuid());

                        Calls.Add(call);
                    }
                }

                if (maximumAchieved || maximumBucket)
                {
                    Thread.Sleep(250);
                }
            } while (maximumAchieved || maximumBucket);

            return(call);
        }
Esempio n. 7
0
        internal static ShopifyProduct SaveProductOnShopify(ShopifyProductService shopifyProductService, ShopifyProduct shopifyProduct)
        {
            var saveShopifyProduct = default(ShopifyProduct);

            ShopifyCall.ExecuteCall(delegate()
            {
                var task = default(Task <ShopifyProduct>);

                if (shopifyProduct.Id == null)
                {
                    task = shopifyProductService.CreateAsync(shopifyProduct);
                }
                else
                {
                    task = shopifyProductService.UpdateAsync(shopifyProduct);
                }

                task.Wait();

                saveShopifyProduct = task.Result;
            });

            return(saveShopifyProduct);
        }