Beispiel #1
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);
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }