예제 #1
0
 public CsvProduct()
 {
     SeoInfos   = new List <SeoInfo>();
     Reviews    = new List <EditorialReview>();
     Properties = new List <Property>();
     Images     = new List <Image>();
     Assets     = new List <Asset>();
     Price      = new CsvPrice {
         Currency = "USD"
     };
     Prices = new List <Price> {
         Price
     };
     Inventory       = new InventoryInfo();
     EditorialReview = new EditorialReview();
     Reviews         = new List <EditorialReview> {
         EditorialReview
     };
     SeoInfo = new CsvSeoInfo {
         ObjectType = typeof(CatalogProduct).Name
     };
     SeoInfos = new List <SeoInfo> {
         SeoInfo
     };
 }
예제 #2
0
        public CsvProduct()
        {
            SeoInfos       = new List <SeoInfo>();
            Reviews        = new List <EditorialReview>();
            PropertyValues = new List <PropertyValue>();
            Images         = new List <Image>();
            Assets         = new List <Asset>();


            Price = new Price()
            {
                Currency = CurrencyCodes.USD
            };
            Inventory       = new InventoryInfo();
            EditorialReview = new EditorialReview();
            Reviews         = new List <EditorialReview>();
            Reviews.Add(EditorialReview);
            SeoInfo  = new SeoInfo();
            SeoInfos = new List <SeoInfo>();
            SeoInfos.Add(SeoInfo);
        }
예제 #3
0
        public CsvProduct()
        {
            SeoInfos       = new List <SeoInfo>();
            Reviews        = new List <EditorialReview>();
            PropertyValues = new List <PropertyValue>();
            Images         = new List <Image>();
            Assets         = new List <Asset>();


            Price = new Price()
            {
                Currency = "USD"
            };
            Inventory       = new InventoryInfo();
            EditorialReview = new EditorialReview();
            Reviews         = new List <EditorialReview>();
            Reviews.Add(EditorialReview);
            SeoInfo = new SeoInfo()
            {
                ObjectType = typeof(CatalogProduct).Name
            };
            SeoInfos = new List <SeoInfo>();
            SeoInfos.Add(SeoInfo);
        }
예제 #4
0
        public CatalogProduct Convert(ShopifyProduct shopifyProduct, ShopifyImportParams importParams, ShopifyData shopifyData, VirtoData virtoData)
        {
            var retVal = new CatalogProduct
            {
                Id          = shopifyProduct.Handle + "-" + shopifyProduct.Id.ToString(),
                Name        = shopifyProduct.Title,
                Code        = shopifyProduct.Handle,
                StartDate   = shopifyProduct.PublishedAt,
                IsActive    = true,
                CatalogId   = importParams.VirtoCatalogId,
                ProductType = shopifyProduct.ProductType,
                Vendor      = shopifyProduct.Vendor
            };

            //Images
            if (shopifyProduct.Image != null)
            {
                retVal.Images = new List <Image>();
                retVal.Images.Add(Convert(shopifyProduct.Image, true));
            }

            //Review
            if (shopifyProduct.BodyHtml != null)
            {
                retVal.Reviews = new List <EditorialReview>();
                var review = new EditorialReview
                {
                    Content      = shopifyProduct.BodyHtml,
                    LanguageCode = "en-US",
                };
                retVal.Reviews.Add(review);
            }

            //Seo
            retVal.SeoInfos = new List <SeoInfo>();
            var seoInfo = new SeoInfo
            {
                SemanticUrl  = shopifyProduct.Title.GenerateSlug(),
                LanguageCode = "en-US"
            };

            retVal.SeoInfos.Add(seoInfo);

            //TODO: Inventory

            //Variation
            if (shopifyProduct.Variants != null)
            {
                retVal.Variations = new List <CatalogProduct>();
                var isFirst = true;
                foreach (var shopifyVariant in shopifyProduct.Variants)
                {
                    var variation = isFirst ? retVal : new CatalogProduct();
                    variation.Name     = String.Format("{0} ({1})", retVal.Name, shopifyVariant.Title);
                    variation.Code     = (shopifyProduct.Handle + "-" + shopifyVariant.Title).GenerateSlug();
                    variation.IsActive = true;

                    variation.SeoInfos = new List <SeoInfo>();
                    seoInfo            = new SeoInfo
                    {
                        SemanticUrl  = variation.Name.GenerateSlug(),
                        LanguageCode = "en-US"
                    };
                    retVal.SeoInfos.Add(seoInfo);

                    if (shopifyVariant.ImageId != null && shopifyProduct.Images != null)
                    {
                        variation.Images = new List <Image>();
                        var image = shopifyProduct.Images.Where(x => x.Id == shopifyVariant.ImageId).Select(x => Convert(x, true)).FirstOrDefault();
                        if (image != null)
                        {
                            variation.Images.Add(image);
                        }
                    }

                    //Price
                    variation.Prices = new List <Price>();
                    variation.Prices.Add(new Price
                    {
                        Sale     = shopifyVariant.Price,
                        List     = shopifyVariant.Price,
                        Currency = "USD"
                    });


                    //Properties (need refactor)
                    variation.PropertyValues = new List <PropertyValue>();

                    var orderedProperties = shopifyProduct.Options.OrderBy(option => option.Position).ToArray();

                    if (shopifyVariant.Option1 != null)
                    {
                        var propValue = new PropertyValue
                        {
                            PropertyName = orderedProperties[0].Name,
                            Value        = shopifyVariant.Option1,
                            ValueType    = PropertyValueType.ShortText,
                        };
                        variation.PropertyValues.Add(propValue);
                    }
                    if (shopifyVariant.Option2 != null)
                    {
                        var propValue = new PropertyValue
                        {
                            PropertyName = orderedProperties[1].Name,
                            Value        = shopifyVariant.Option2,
                            ValueType    = PropertyValueType.ShortText
                        };
                        variation.PropertyValues.Add(propValue);
                    }
                    if (shopifyVariant.Option3 != null)
                    {
                        var propValue = new PropertyValue
                        {
                            PropertyName = orderedProperties[2].Name,
                            Value        = shopifyVariant.Option3,
                            ValueType    = PropertyValueType.ShortText
                        };
                        variation.PropertyValues.Add(propValue);
                    }

                    if (!isFirst)
                    {
                        retVal.Variations.Add(variation);
                    }
                    isFirst = false;
                }
            }


            if (importParams.ImportCollections)
            {
                var firstCollect = shopifyData.Collects.FirstOrDefault(collect => collect.ProductId == shopifyProduct.Id);
                if (firstCollect != null)
                {
                    retVal.Category = new Category()
                    {
                        Code =
                            shopifyData.Collections.First(collection => collection.Id == firstCollect.CollectionId)
                            .Handle
                    };
                }
            }

            return(retVal);
        }
예제 #5
0
        private void RouteProductCall(Operation op, ProductEntity entry)
        {
            const string ReviewType = "FullReview";

            if (op == Operation.Publish) // publish
            {
                var product = GetCatalogProduct(entry, out bool isNew);
                product.IsActive = true;

                if (entry.Content != null)
                {
                    var list = new List <EditorialReview>();
                    foreach (var lang in entry.Content.Keys)
                    {
                        var review = new EditorialReview()
                        {
                            Content      = entry.Content[lang],
                            ReviewType   = ReviewType,
                            LanguageCode = lang
                        };

                        list.Add(review);
                    }

                    // add new reviews or update existing ones
                    if (product.Reviews == null)
                    {
                        product.Reviews = list.ToArray();
                    }
                    else
                    {
                        foreach (var review in list)
                        {
                            var existingReview = product.Reviews.Where(x => x.ReviewType == ReviewType && x.LanguageCode == review.LanguageCode).SingleOrDefault();
                            if (existingReview == null)
                            {
                                product.Reviews.Add(review);
                            }
                            else
                            {
                                existingReview.Content = review.Content;
                            }
                        }
                    }
                }

                // now add all the properties
                if (entry.Properties != null)
                {
                    var propValuesList = new List <PropertyValue>();
                    foreach (var key in entry.Properties.Keys)
                    {
                        var prop = entry.Properties[key];

                        foreach (var lang in prop.Keys)
                        {
                            var proValue = new PropertyValue()
                            {
                                LanguageCode = lang,
                                PropertyName = key,
                                Value        = prop[lang]
                            };

                            propValuesList.Add(proValue);
                        }
                    }

                    propValuesList.Add(new PropertyValue()
                    {
                        PropertyName = "contentfulid", Value = entry.Id
                    });

                    // add new properties or update existing ones
                    if (product.PropertyValues == null)
                    {
                        product.PropertyValues = propValuesList.ToArray();
                    }
                    else
                    {
                        foreach (var propertyValue in propValuesList)
                        {
                            var existingPropertyValue = product.PropertyValues.Where(x => x.PropertyName == propertyValue.PropertyName && x.LanguageCode == propertyValue.LanguageCode).SingleOrDefault();
                            if (existingPropertyValue == null)
                            {
                                product.PropertyValues.Add(propertyValue);
                            }
                            else
                            {
                                existingPropertyValue.Value = propertyValue.Value;
                            }
                        }
                    }
                }

                if (isNew)
                {
                    _itemService.Create(product);
                }
                else
                {
                    _itemService.Update(new[] { product });
                }
            }
            else if (op == Operation.Unpublish || op == Operation.Delete) // unpublish
            {
                var criteria = new ProductSearchCriteria();
                criteria.Terms = new[] { string.Format("contentfulid:{0}", entry.Id) };
                var result = _productSearchService.SearchAsync(criteria).Result;

                if (result.TotalCount > 0)
                {
                    var product = _itemService.GetById(result.Items[0].Id, ItemResponseGroup.ItemLarge); // reload complete product now
                    product.IsActive = false;
                    _itemService.Update(new[] { product });
                }
            }
        }