Exemple #1
0
        public string GenerateInterstitialLink(long?productId)
        {
            string ret;
            var    cacheKey = string.Format("{0} {1} {2} {3}",
                                            WebSession.Current.SiteId, WebSession.Current.LanguageCode, "InterstitialLink", productId);

            if (!_urlCache.TryGet(cacheKey, out ret))
            {
                try
                {
                    var interstitialPages      = CmsFinder.FindDescendentsOrFallbackOfCurrentPageLanguageRoot <ShoppingCartInterstitialPage>();
                    var targetInterstitialPage =
                        interstitialPages.FirstOrDefault(
                            ip => ip.ProductID.Split().Any(pid => pid.Equals(productId.ToString(), StringComparison.InvariantCultureIgnoreCase)));

                    if (targetInterstitialPage == null)
                    {
                        ret = null;
                    }
                    else
                    {
                        var url = new Url(GetNormalizedPageUrl(targetInterstitialPage));

                        if ((string.IsNullOrEmpty(targetInterstitialPage.ProductID) || targetInterstitialPage.ProductID.Split().Length > 1) &&
                            productId != null)
                        {
                            url = url.Append(productId.ToString());
                        }

                        ret = url.ToString();
                    }

                    AddCache(cacheKey, ret);
                }
                catch (Exception e)
                {
                    _logger.Error(e, "Unable to create shopping cart interstitial link for product {0}", productId);
                }
            }

            return(ret);
        }
Exemple #2
0
 public Partner(string displayName, string url)
 {
     DisplayName = displayName;
     Url.Append(url);
 }
Exemple #3
0
        public string GenerateCategoryLink(long?categoryId, bool?forceListPage, out object matchingCategoryPage)
        {
            //~~  a cheap and nasty chaos monkey
            //if (DateTime.Now.Minute % 2 == 1)
            //    throw new Exception("chaos happened " + categoryId);
            //~~

            string ret;
            var    cacheKey = string.Format("{0} {1} {2} {3} {4}",
                                            WebSession.Current.SiteId, WebSession.Current.LanguageCode, "CategoryLink", categoryId, forceListPage);

            if (!_urlCache.TryGet(cacheKey, out ret))
            {
                var catPages = CmsFinder.FindDescendentsOrFallbackOfCurrentPageLanguageRoot <CatalogPage>();

                if (catPages.All(cps => cps.CategoryID.Length != 0))
                {
                    // find a category page from the root level that has no category ID
                    var defaultCatPage = CmsFinder.FindAllNonSiteDescendentsOfRoot <CatalogPage>()
                                         .LastOrDefault(cps => cps.CategoryID.Length == 0);

                    if (defaultCatPage != null)
                    {
                        catPages.Add(defaultCatPage);
                    }
                }

                CatalogPage cp;

                if (forceListPage.HasValue && forceListPage.Value)
                {
                    cp = catPages.LastOrDefault(catalogPage => catalogPage.CategoryID.Length == 0);
                }
                else
                {
                    cp = catPages.FirstOrDefault(catalogPage => catalogPage.CategoryID.Equals(categoryId.ToString(), StringComparison.InvariantCultureIgnoreCase)) ??
                         catPages.LastOrDefault(catalogPage => catalogPage.CategoryID.Length == 0);
                }

                if (cp == null)
                {
                    ret = null;
                }
                else
                {
                    // If the category page came from the root, append it's name and parameters to the current page's url
                    var url = new Url(GetNormalizedPageUrl(cp));

                    if (string.IsNullOrEmpty(cp.CategoryID) && categoryId != null)
                    {
                        url = url.Append(categoryId.Value.ToString(CultureInfo.InvariantCulture));
                    }

                    if (forceListPage.HasValue && forceListPage.Value && string.IsNullOrEmpty(cp.CategoryID))
                    {
                        url = url.AppendQuery("list=true");
                    }

                    ret = url.ToString();
                }

                AddCache(cacheKey, ret, cp);
            }

            _itemCache.TryGet(cacheKey, out matchingCategoryPage);

            return(ret);
        }