Ejemplo n.º 1
0
        public override ActionResult Detail()
        {
            if (ColonyContext.Response.UrlExtension != null)
            {
                if ((ColonyContext.Response.UrlParts.Count > 1 && ColonyContext.Response.UrlParts[1] == "paint") ||
                    (ColonyContext.Response.UrlParts.Count == 1 &&
                     ColonyContext.Response.UrlExtensionParts[0] == "paint"))
                {
                    ViewBag.IsPaint = true;

                    var maxRelated = AppSettingsHelper.GetSafeValue <long>("MaxRelatedProducts", 50);
                    var maxRecentlyViewedProducts = AppSettingsHelper.GetSafeValue("MaxRecentlyViewedProducts", 10);

                    var viewModel = GetProductViewModelForProductDetail("paint/" + ColonyContext.Response.UrlExtension);

                    if (viewModel != null)
                    {
                        if (viewModel.SelectedSku.IsOptionProduct != null)
                        {
                            if (viewModel.SelectedSku.IsOptionProduct.Equals("Y",
                                                                             StringComparison.OrdinalIgnoreCase))
                            {
                                var parentSku =
                                    viewModel.Skus.FirstOrDefault(x => x.Sku.Id == viewModel.SelectedSku.ParentSkuId);
                                if (parentSku != null)
                                {
                                    var redirectUrl = new UriBuilder(ColonyContext.Response.Uri.AbsoluteUri);
                                    var query       = HttpUtility.ParseQueryString(ColonyContext.Response.Uri.Query);

                                    query.Remove("code");
                                    query.Add("code", parentSku.Sku.Code);
                                    redirectUrl.Query = query.ToString();

                                    return(Redirect(redirectUrl.ToString()));
                                }
                                return(null);
                            }
                        }
                        //else return null;


                        var trackingEvent = ProductViewedTrackedEvent.Instance;
                        trackingEvent.TrackedEntity = viewModel.Product;
                        VisitorTrackingContext.TrackEvent(trackingEvent, Request.Url.AbsoluteUri);
                        _productsService.AddRecentlyViewedProduct(VisitorTrackingContext.CurrentVisitor.Id,
                                                                  viewModel.Product);
                        var breadcrumbDisplay = "";
                        if (viewModel.SelectedSku.Attributes["Descriptive Colour"] != null)
                        {
                            breadcrumbDisplay = viewModel.SelectedSku.Attributes["Descriptive Colour"];
                        }
                        else
                        {
                            breadcrumbDisplay = "Paint";
                        }
                        if (ViewBag.IsPaint)
                        {
                            ShopHelpers.SetBreadcrumbForProduct(viewModel.Product, breadcrumbDisplay);
                        }
                        else
                        {
                            ShopHelpers.SetBreadcrumbForProduct(viewModel.Product);
                        }
                        if (ColonyContext.Response.Breadcrumbs.Count >= 3)
                        {
                            ColonyContext.Response.Breadcrumbs.RemoveAt(ColonyContext.Response.Breadcrumbs.Count - 3);
                        }
                        Response.AddHeader("Cache-Control", "Cache-Control:public, max-age=1800");
                        return(PartialView("Detail", viewModel));
                    }
                    return(null);
                }
            }
            return(base.Detail());
        }
Ejemplo n.º 2
0
        public ActionResult NewCollections()
        {
            var tab = Request.QueryString["show"];

            var page     = 1;
            var pageSize =
                AppSettingsHelper.GetSafeValue(
                    string.Format("MinCollectionSearchResults.{0}", ColonyContext.Current.CurrentSite.SiteKey), 6);
            var keywords = "";
            var brandKey = "";

            if (ColonyContext.Response.QueryParameters.ContainsKey("page"))
            {
                page = ColonyContext.Response.QueryParameters["page"].AsInt(page);
            }

            if (ColonyContext.Response.QueryParameters.ContainsKey("pagesize"))
            {
                pageSize = ColonyContext.Response.QueryParameters["pagesize"].AsInt(pageSize);
            }

            if (ColonyContext.Response.QueryParameters.ContainsKey("brandKey"))
            {
                brandKey = ColonyContext.Response.QueryParameters["brandKey"];
            }
            else
            {
                brandKey = Request.Form["brandKey"] ?? "";
            }

            if (ColonyContext.Response.QueryParameters.ContainsKey("keywords"))
            {
                keywords = ColonyContext.Response.QueryParameters["keywords"];
            }
            else
            {
                keywords = Request.Form["keywords"] ?? "";
            }

            //string cacheKeyCategory = string.Format("shop_{0}_uri_{1}_category", CurrentShop.Id, ColonyContext.Response.UrlExtension);
            //string cacheKeySubCategories = string.Format("shop_{0}_uri_{1}_subcategories", CurrentShop.Id, ColonyContext.Response.UrlExtension);

            var category =
                _productCategoriesService.GetForFrontEndCategoryListing(
                    new { Uri = ColonyContext.Response.UrlExtension, ShopId = CurrentShop.Id }, page, pageSize)
                .FirstOrDefault();

            if (category == null)
            {
                return(HttpNotFound());
            }

            bool?isB2b = null;

            if (IsB2BUserLoggedIn(HttpContext))
            {
                isB2b = true;
            }

            var parameters = new
            {
                ShopID           = CurrentShop.Id,
                IsNew            = true,
                CategoryKeywords = keywords,
                CategoryBrandKey = brandKey == "" ? null : brandKey,
                IsB2B            = isB2b
            };

            var newCollections =
                _productCategoriesService.GetForFrontEndCategoryListing(parameters, page, pageSize)
                .Where(t => t.ParentID.HasValue)
                .ToList();

            var viewModel = new CategoryViewModel
            {
                IsParent        = true,
                Category        = category,
                CategoryId      = category.Id,
                Name            = category.Name,
                ImageAssetId    = category.ImageAssetId,
                LongDescription = category.LongDescription,
                IsNew           = category.IsNew,
                SearchKeywords  = keywords
            };

            if (category.CategoryImages != null && category.CategoryImages.Any())
            {
                viewModel.Images = category.CategoryImages.ToList();
            }

            viewModel.SubCategories =
                newCollections.Select(
                    subCategory =>
            {
                return(GetCategoryViewModel(subCategory, isB2b, false, 0, 0, page, pageSize,
                                            viewModel.SubCategories.PageCount, viewModel.SubCategories.RecordCount));
            })
                .ToPagedCollection(page, pageSize);

            var minCollectionSearchResults =
                AppSettingsHelper.GetSafeValue(
                    string.Format("MinCollectionSearchResults.{0}", ColonyContext.Current.CurrentSite.SiteKey), 6);

            viewModel.ShouldShowSearch = viewModel.SubCategories.Count >= minCollectionSearchResults;

            if (!string.IsNullOrEmpty(keywords))
            {
                viewModel.ShouldShowSearch = true;
            }

            ViewBag.Title = "Products";

            ShopHelpers.SetBreadcrumbForProductCategory(category);
            return(PartialView("Category", viewModel));
        }