Esempio n. 1
0
        /// <summary>
        /// Sets discount price for the first variation with a price
        /// </summary>
        /// <param name="findProduct"></param>
        /// <param name="content"></param>
        /// <param name="market"></param>
        public static void SetPriceData(this FindProduct findProduct, List <VariationContent> content, IMarket market)
        {
            VariationContent variation = null;

            if (content.Any())
            {
                foreach (var item in content)
                {
                    var price = item.GetPrice(market);
                    if (price != null)
                    {
                        variation = item;
                        break;
                    }
                }
            }

            if (variation == null)
            {
                return;
            }

            PriceModel priceModel = variation.GetPriceModel(market);

            findProduct.DefaultPrice       = priceModel.DefaultPrice.UnitPrice.ToString();
            findProduct.DefaultPriceAmount = content.GetDefaultPriceAmountWholeNumber(market);

            DiscountPrice discountPrice = priceModel.DiscountPrice;

            findProduct.DiscountedPriceAmount = (double)discountPrice.GetDiscountPriceWithCheck();
            findProduct.DiscountedPrice       = discountPrice.GetDiscountDisplayPriceWithCheck();

            findProduct.CustomerClubPriceAmount = (double)priceModel.CustomerClubPrice.GetPriceAmountSafe();
            findProduct.CustomerClubPrice       = priceModel.CustomerClubPrice.GetPriceAmountStringSafe();
        }
        public FindProduct GetFindProduct(Mediachase.Commerce.IMarket market)
        {
            var language    = (Language == null ? string.Empty : Language.Name);
            var findProduct = new FindProduct(this, language);

            findProduct.Color = Color != null ? new List <string>()
            {
                Color
            } : new List <string>();
            findProduct.Description = Description;
            findProduct.Overview    = Overview;
            EPiServer.Commerce.SpecializedProperties.Price defaultPrice = this.GetDefaultPrice();
            findProduct.DefaultPrice       = this.GetDisplayPrice(market);
            findProduct.DefaultPriceAmount = this.GetDefaultPriceAmount(market);

            PriceAndMarket discountPrice = this.GetDiscountPrice(market);

            findProduct.DiscountedPriceAmount = GetPriceWithCheck(discountPrice);
            findProduct.DiscountedPrice       = GetDisplayPriceWithCheck(discountPrice);

            PriceAndMarket customerClubPrice = this.GetCustomerClubPrice(market);

            findProduct.CustomerClubPriceAmount = customerClubPrice != null ? (double)customerClubPrice.UnitPrice.Amount : 0;
            findProduct.CustomerClubPrice       = customerClubPrice != null ? customerClubPrice.Price : string.Empty;

            findProduct.Brand = this.Facet_Brand;
            return(findProduct);
        }
        public FindProduct GetFindProduct(IMarket market)
        {
            List <VariationContent> productVariants = GetVariants(this);
            var variations = GetFashionVariants(productVariants, market);

            var    language = (Language == null ? string.Empty : Language.Name);
            string sizeType = string.IsNullOrEmpty(SizeType) ? "" : SizeType.First().ToString(CultureInfo.InvariantCulture);

            var findProduct = new FindProduct(this, language);

            findProduct.Description = Description;
            findProduct.Color       = FacetColor == null ? new List <string>() : FacetColor.Split(',').ToList();
            findProduct.Sizes       =
                variations.Select(x => x.Size == null ? string.Empty : x.Size.TrimEnd('-')).Distinct().ToList();
            findProduct.SizeType  = sizeType;
            findProduct.SizeUnit  = SizeUnit;
            findProduct.Fit       = Fit;
            findProduct.SizesList = CreateSizeList(variations.Select(x => x.Size).Distinct().ToList(), SizeUnit,
                                                   sizeType);

            EPiServer.Commerce.SpecializedProperties.Price defaultPrice = productVariants.GetDefaultPrice(market);

            findProduct.DefaultPrice       = productVariants.GetDisplayPrice(market);
            findProduct.DefaultPriceAmount = productVariants.GetDefaultPriceAmount(market);
            findProduct.DiscountedPrice    = productVariants.GetDiscountDisplayPrice(defaultPrice, market);

            // TODO: Set if not the same as default price
            findProduct.DiscountedPriceAmount = 0;

            findProduct.CustomerClubPrice = productVariants.GetCustomerClubDisplayPrice(market);
            findProduct.Variants          = variations;
            findProduct.NewItemText       = NewItemText;
            return(findProduct);
        }
        public FindProduct GetFindProduct(Mediachase.Commerce.IMarket market)
        {
            var language    = (Language == null ? string.Empty : Language.Name);
            var findProduct = new FindProduct(this, language);

            findProduct.Description = Description;
            findProduct.Overview    = Overview;
            EPiServer.Commerce.SpecializedProperties.Price defaultPrice = this.GetDefaultPrice();
            findProduct.DefaultPrice       = this.GetDisplayPrice(market);
            findProduct.DefaultPriceAmount = this.GetDefaultPriceAmount(market);

            PriceAndMarket discountPrice = this.GetDiscountPrice(market);

            findProduct.DiscountedPriceAmount = GetPriceWithCheck(discountPrice);
            findProduct.DiscountedPrice       = GetDisplayPriceWithCheck(discountPrice);

            PriceAndMarket customerClubPrice = this.GetCustomerClubPrice(market);

            findProduct.CustomerClubPriceAmount = GetPriceWithCheck(customerClubPrice);
            findProduct.CustomerClubPrice       = GetDisplayPriceWithCheck(customerClubPrice);

            findProduct.Brand          = Facet_Brand;
            findProduct.Resolution     = Resolution;
            findProduct.LensMount      = LensMount;
            findProduct.CameraFormat   = CameraFormat;
            findProduct.FileFormat     = FileFormat;
            findProduct.Connectivity   = Connectivity;
            findProduct.Battery        = Battery;
            findProduct.MemoryCardType = MemoryCardType;
            findProduct.Weight         = Weight;


            return(findProduct);
        }
        // --- End of property definitions

        public FindProduct GetFindProduct(IMarket market)
        {
            var language    = (Language == null ? string.Empty : Language.Name);
            var findProduct = new FindProduct(this, language);

            findProduct.Description = Info_Description;
            findProduct.Sizes       = new List <string>()
            {
                this.Size
            };
            EPiServer.Commerce.SpecializedProperties.Price defaultPrice = this.GetDefaultPrice();
            findProduct.DefaultPrice       = this.GetDisplayPrice(market);
            findProduct.DefaultPriceAmount = this.GetDefaultPriceAmount(market);
            findProduct.DiscountedPrice    = this.GetDiscountDisplayPrice(defaultPrice, market);
            findProduct.CustomerClubPrice  = this.GetCustomerClubDisplayPrice(market);
            findProduct.GrapeMixList       = GetGrapeMixList();

            findProduct.Varieties = GrapeMix;
            findProduct.Vintage   = Vintage;
            findProduct.Taste     = Taste;
            findProduct.Style     = Style;
            findProduct.Country   = Country;
            findProduct.Region    = Region;
            findProduct.Maturity  = Maturity;
            findProduct.Alcohol   = Alcohol;
            findProduct.Closure   = Closure;
            findProduct.Brand     = Facet_Brand;

            return(findProduct);
        }
Esempio n. 6
0
        public FindProduct GetFindProduct(IMarket market)
        {
            List <VariationContent> productVariants = GetVariants(this);
            var variations = GetFashionVariants(productVariants, market);

            var    language = (Language == null ? string.Empty : Language.Name);
            string sizeType = string.IsNullOrEmpty(SizeType) ? "" : SizeType.First().ToString(CultureInfo.InvariantCulture);

            var findProduct = new FindProduct(this, language);

            findProduct.Description = Description;
            findProduct.Color       = FacetColor == null ? new List <string>() : FacetColor.Split(',').ToList();
            findProduct.Sizes       =
                variations.Select(x => x.Size == null ? string.Empty : x.Size.TrimEnd('-')).Distinct().ToList();
            findProduct.SizeType  = sizeType;
            findProduct.SizeUnit  = SizeUnit;
            findProduct.Fit       = Fit;
            findProduct.SizesList = CreateSizeList(variations.Select(x => x.Size).Distinct().ToList(), SizeUnit,
                                                   sizeType);

            findProduct.SetPriceData(productVariants, market);

            findProduct.Variants    = variations;
            findProduct.NewItemText = NewItemText;
            return(findProduct);
        }
        // --- End of property definitions

        public FindProduct GetFindProduct(IMarket market)
        {
            var language    = (Language == null ? string.Empty : Language.Name);
            var findProduct = new FindProduct(this, language);

            findProduct.Description = Info_Description;
            findProduct.Sizes       = new List <string>()
            {
                this.Size
            };

            findProduct.SetPriceData(this, market);

            findProduct.GrapeMixList = GetGrapeMixList();

            findProduct.Varieties = GrapeMix;
            findProduct.Vintage   = Vintage;
            findProduct.Taste     = Taste;
            findProduct.Style     = Style;
            findProduct.Country   = Country;
            findProduct.Region    = Region;
            findProduct.Maturity  = Maturity;
            findProduct.Alcohol   = Alcohol;
            findProduct.Closure   = Closure;
            findProduct.Brand     = Facet_Brand;

            return(findProduct);
        }
Esempio n. 8
0
        private string GetDefaultImage(IEnumerable <FindProduct> productList)
        {
            FindProduct firstProduct = productList.FirstOrDefault(x => !string.IsNullOrEmpty(x.DefaultImageUrl));

            if (firstProduct != null)
            {
                return(firstProduct.DefaultImageUrl);
            }
            return(NoImagePath);
        }
Esempio n. 9
0
        public static void SetPriceData(this FindProduct findProduct, VariationContent content, IMarket market)
        {
            PriceModel priceModel = content.GetPriceModel(market);

            findProduct.DefaultPrice       = priceModel.DefaultPrice.UnitPrice.ToString();
            findProduct.DefaultPriceAmount = content.GetDefaultPriceAmountWholeNumber(market);

            DiscountPrice discountPrice = priceModel.DiscountPrice;

            findProduct.DiscountedPriceAmount = (double)discountPrice.GetDiscountPriceWithCheck();
            findProduct.DiscountedPrice       = discountPrice.GetDiscountDisplayPriceWithCheck();

            findProduct.CustomerClubPriceAmount = (double)priceModel.CustomerClubPrice.GetPriceAmountSafe();
            findProduct.CustomerClubPrice       = priceModel.CustomerClubPrice.GetPriceAmountStringSafe();
        }
Esempio n. 10
0
        public FindProduct GetFindProduct(Mediachase.Commerce.IMarket market)
        {
            var language    = (Language == null ? string.Empty : Language.Name);
            var findProduct = new FindProduct(this, language);

            findProduct.Color = Color != null ? new List <string>()
            {
                Color
            } : new List <string>();
            findProduct.Description = Description;
            findProduct.Overview    = Overview;

            findProduct.SetPriceData(this, market);

            findProduct.Brand = this.Facet_Brand;
            return(findProduct);
        }
Esempio n. 11
0
 private static void IndexProduct(FindHelper helper, IIndexableContent p)
 {
     if (p.ShouldIndex())
     {
         var         currentMarket = ServiceLocator.Current.GetInstance <Mediachase.Commerce.ICurrentMarket>().GetCurrentMarket();
         FindProduct findProduct   = p.GetFindProduct(currentMarket);
         if (findProduct != null)
         {
             IClient client = SearchClient.Instance;
             client.Index(findProduct);
         }
     }
     else
     {
         //TODO: remove product from index
         //IClient client = SearchClient.Instance;
         //var lang = p.Language;
         //client.Delete<FindProduct>(productContent.ContentLink.ID + "_" + (lang == null ? string.Empty : lang.Name));
     }
 }
Esempio n. 12
0
        public object GetSimilarProducts(string indexId)
        {
            try
            {
                SetLanguage();
                string      language       = Language;
                var         client         = SearchClient.Instance;
                FindProduct currentProduct = client.Search <FindProduct>()
                                             .Filter(x => x.IndexId.Match(indexId)).Take(1).StaticallyCacheFor(TimeSpan.FromMinutes(1)).GetResult().FirstOrDefault();
                if (currentProduct != null)
                {
                    List <SimilarProductObject> similarProductObjects = new List <SimilarProductObject>();

                    var result = client.Search <FindProduct>()
                                 .Filter(x => x.CategoryName.Match(currentProduct.CategoryName))
                                 .Filter(x => x.MainCategoryName.Match(currentProduct.MainCategoryName))
                                 .Filter(x => !x.DisplayName.Match(currentProduct.DisplayName))
                                 //.Filter(x => x.ShowInList.Match(true))
                                 .Filter(x => x.Language.Match(language))
                                 .StaticallyCacheFor(TimeSpan.FromMinutes(1))
                                 .GetResult();

                    similarProductObjects = result.Select(y => new SimilarProductObject
                    {
                        Name            = y.DisplayName,
                        Image           = y.DefaultImageUrl,
                        Url             = y.ProductUrl,
                        DefaultPrice    = y.DefaultPrice,
                        DiscountedPrice = y.DiscountedPrice
                    }).ToList();


                    return(similarProductObjects);
                }
                return(null);
            }
            catch (ServiceException)
            {
                return(null);
            }
        }
 protected void IndexProduct(IIndexableContent p)
 {
     if (p.ShouldIndex())
     {
         var         currentMarket = ServiceLocator.Current.GetInstance <Mediachase.Commerce.ICurrentMarket>().GetCurrentMarket();
         FindProduct findProduct   = p.GetFindProduct(currentMarket);
         if (findProduct != null)
         {
             _log.Debug("Indexing {0} - {1}", findProduct.Code, findProduct.Name);
             IClient client = SearchClient.Instance;
             client.Index(findProduct);
         }
     }
     else
     {
         //TODO: remove product from index
         _log.Debug("TODO: Remove from index {0}", p.Name);
         //IClient client = SearchClient.Instance;
         //var lang = p.Language;
         //client.Delete<FindProduct>(productContent.ContentLink.ID + "_" + (lang == null ? string.Empty : lang.Name));
     }
 }
Esempio n. 14
0
        public FindProduct GetFindProduct(Mediachase.Commerce.IMarket market)
        {
            var language    = (Language == null ? string.Empty : Language.Name);
            var findProduct = new FindProduct(this, language);

            findProduct.Description = Description;
            findProduct.Overview    = Overview;

            findProduct.SetPriceData(this, market);

            findProduct.Brand          = Facet_Brand;
            findProduct.Resolution     = Resolution;
            findProduct.LensMount      = LensMount;
            findProduct.CameraFormat   = CameraFormat;
            findProduct.FileFormat     = FileFormat;
            findProduct.Connectivity   = Connectivity;
            findProduct.Battery        = Battery;
            findProduct.MemoryCardType = MemoryCardType;
            findProduct.Weight         = Weight;


            return(findProduct);
        }
        public FindProduct GetFindProduct(IMarket market)
        {
            List <VariationContent> productVariants = this.GetVaritions().ToList();
            var variations = GetGenericVariants(productVariants, market);

            var language = (Language == null ? string.Empty : Language.Name);

            var findProduct = new FindProduct(this, language);

            findProduct.Description = Description;
            findProduct.Color       = Color != null ? new List <string>()
            {
                Color
            } : new List <string>();
            findProduct.Sizes =
                variations.Select(x => x.Size ?? string.Empty).Distinct().ToList();
            findProduct.Brand = this.Facet_Brand;

            EPiServer.Commerce.SpecializedProperties.Price defaultPrice = productVariants.GetDefaultPrice(market);

            findProduct.DefaultPrice       = productVariants.GetDisplayPrice(market);
            findProduct.DefaultPriceAmount = productVariants.GetDefaultPriceAmount(market);

            PriceAndMarket discountPrice = productVariants.GetDiscountPrice(market);

            findProduct.DiscountedPrice       = GetDisplayPriceWithCheck(discountPrice);
            findProduct.DiscountedPriceAmount = GetPriceWithCheck(discountPrice);

            PriceAndMarket customerClubPrice = productVariants.GetCustomerClubPrice(market);

            findProduct.CustomerClubPriceAmount = GetPriceWithCheck(customerClubPrice);
            findProduct.CustomerClubPrice       = GetDisplayPriceWithCheck(customerClubPrice);

            findProduct.GenericVariants = variations;

            return(findProduct);
        }
        public FindProduct GetFindProduct(IMarket market)
        {
            List <VariationContent> productVariants = this.GetVaritions().ToList();
            var variations = GetGenericVariants(productVariants, market);

            var language = (Language == null ? string.Empty : Language.Name);

            var findProduct = new FindProduct(this, language);

            findProduct.Description = Description;
            findProduct.Color       = Color != null ? new List <string>()
            {
                Color
            } : new List <string>();
            findProduct.Sizes =
                variations.Select(x => x.Size ?? string.Empty).Distinct().ToList();
            findProduct.Brand = this.Facet_Brand;

            findProduct.SetPriceData(productVariants, market);

            findProduct.GenericVariants = variations;

            return(findProduct);
        }
        /// <summary>
        /// Starts the job
        /// </summary>
        /// <returns>A status message that will be logged</returns>
        public override string Execute()
        {
            IndexInformation info = new IndexInformation();
            Stopwatch        tmr  = Stopwatch.StartNew();

            IClient client = SearchClient.Instance;


            //Delete all
            client.Delete <FindProduct>(x => x.MatchType(typeof(FindProduct)));


            var language            = LanguageSelector.MasterLanguage();
            var localizationService = ServiceLocator.Current.GetInstance <LocalizationService>();
            var marketService       = ServiceLocator.Current.GetInstance <IMarketService>();
            var allMarkets          = marketService.GetAllMarkets();
            var priceService        = ServiceLocator.Current.GetInstance <IPriceService>();
            var linksRepository     = ServiceLocator.Current.GetInstance <ILinksRepository>();


            // TODO: Add support for multiple catalogs. This will pick the first one.
            IEnumerable <ContentReference> contentLinks = contentLoader.GetDescendents(Root);

            int bulkSize = 100;

            foreach (CultureInfo availableLocalization in localizationService.AvailableLocalizations)
            {
                var market = allMarkets.FirstOrDefault(m => m.DefaultLanguage.Equals(availableLocalization));
                if (market == null)
                {
                    continue;
                }
                string language2 = availableLocalization.Name.ToLower();


                int allContentsCount = contentLinks.Count();
                for (var i = 0; i < allContentsCount; i += bulkSize)
                {
                    var items  = contentLoader.GetItems(contentLinks.Skip(i).Take(bulkSize), new LanguageSelector(availableLocalization.Name));
                    var items2 = items.OfType <IIndexableContent>().ToList();

                    foreach (var content in items2)
                    {
                        info.NumberOfProductsFound++;

                        OnStatusChanged(String.Format("Searching product {0}/{1} - {2}", i + 1, allContentsCount, content.Name));

                        if (content.ShouldIndex())
                        {
                            info.NumberOfProductsFoundAfterExpiredFilter++;

                            FindProduct findProduct = null;
                            try
                            {
                                findProduct = content.GetFindProduct(market);
                            }
                            catch (Exception ex)
                            {
                                string msg = string.Format("Cannot generate FindProduct for {0}", content.Name);
                                _log.Error(msg, ex);
                            }

                            if (findProduct != null)
                            {
                                client.Index(findProduct);
                                info.NumberOfProductsIndexed++;
                            }
                        }

                        //For long running jobs periodically check if stop is signaled and if so stop execution
                        if (_stopSignaled)
                        {
                            tmr.Stop();
                            info.Duration = tmr.ElapsedMilliseconds;
                            break;
                        }
                    }

                    //For long running jobs periodically check if stop is signaled and if so stop execution
                    if (_stopSignaled)
                    {
                        tmr.Stop();
                        info.Duration = tmr.ElapsedMilliseconds;
                        break;
                    }
                }
            }

            if (_stopSignaled)
            {
                return("Stop of job was called. " + info.ToString());
            }


            tmr.Stop();
            info.Duration = tmr.ElapsedMilliseconds;

            return(info.ToString());
        }