public ProductListViewModel GetProductListViewModel(ProductListPart part, ILinkGenerator linkGenerator, ICatalogApi catalogApi)
        {
            var model = new ProductListViewModel {Title = part.Title};

            foreach (var product in part.Products)
            {
                var itemModel = new ProductListItemViewModel
                {
                    Url = product.TargetUrl,
                    Title = product.Title,
                    Text = product.Text
                };
                long pid;
                if (long.TryParse(product.Product, out pid))
                {
                    itemModel.Product = catalogApi.GetProductAsync(catalogApi.GetProductUri(pid)).Result;
                    if (string.IsNullOrEmpty(itemModel.Url))
                        itemModel.Url = linkGenerator.GenerateProductLink(pid);
                    if (string.IsNullOrEmpty(itemModel.Title))
                        itemModel.Title = itemModel.Product.DisplayName;
                    if (string.IsNullOrEmpty(itemModel.Text))
                        itemModel.Text = itemModel.Product.ShortDescription;
                }
                model.Products.Add(itemModel);
            }

            return model;
        }
Пример #2
0
        private CrossSellViewModel MakeCrossSellViewModel(Offers offers, string shoppingCartLink)
        {
            if (offers == null || offers.Offer == null || offers.Offer.Length == 0)
            {
                return(null);
            }
            var offerViewModels = new List <CrossSellOfferViewModel>();

            foreach (var offer in offers.Offer)
            {
                var offerViewModel = OfferToCrossSellOfferViewModel(offer);
                offerViewModels.Add(offerViewModel);
                if (offerViewModel.ProductOffersOfferViewModels == null || offerViewModel.ProductOffersOfferViewModels.Length == 0)
                {
                    continue;
                }
                foreach (var productOfferViewModel in offerViewModel.ProductOffersOfferViewModels)
                {
                    productOfferViewModel.AddToCartLink = MakeAddToCartLink(productOfferViewModel.Product.Id, offer.Id, shoppingCartLink);
                    productOfferViewModel.ProductLink   =
                        _linkGenerator.GenerateProductLink(productOfferViewModel.Product.Id);
                }
            }
            return(new CrossSellViewModel
            {
                Offers = offerViewModels
            });
        }
Пример #3
0
        private ProductOfferViewModel ProductOfferToProductOfferViewModel(long offerId, ProductOffer productOffer)
        {
            var productOfferViewModel = new ProductOfferViewModel();

            productOfferViewModel.InjectFrom(productOffer);
            if (productOffer.Product != null)
            {
                productOfferViewModel.ProductLink   = _linkGenerator.GenerateProductLink(productOffer.Product.Id);
                productOfferViewModel.AddToCartLink = MakeAddToCartLink(productOffer.Product.Id, offerId);
            }
            return(productOfferViewModel);
        }
        private void AddProduct(Product product)
        {
            bool noIndex;
            var  noIndexAttr = product.CustomAttributes.ValueByName("NoIndex");

            if (noIndexAttr == null || !bool.TryParse(noIndexAttr, out noIndex))
            {
                noIndex = false;
            }

            if (!product.DisplayableProduct || noIndex)
            {
                return;
            }

            object pp;
            var    url         = _linkGenerator.GenerateProductLink(product.Id, out pp);
            var    productPage = pp as ProductPage;

            if (productPage != null && !productPage.IncludeInSitemap())
            {
                return;
            }

            var sme = new SiteMapEntry
            {
                Title        = product.DisplayName,
                Url          = url,
                LastModified = DateTime.Now
            };

            if (productPage != null)
            {
                sme.LastModified    = productPage.Published;
                sme.ChangeFrequency = productPage.ChangeFrequency;
                sme.Priority        = productPage.Priority;
                sme.Title           = productPage.Title;
            }
            Add(sme);
        }
Пример #5
0
        public ProductListViewModel GetProductListViewModel(ProductListPart part, ILinkGenerator linkGenerator, ICatalogApi catalogApi)
        {
            var model = new ProductListViewModel {
                Title = part.Title
            };

            foreach (var product in part.Products)
            {
                var itemModel = new ProductListItemViewModel
                {
                    Url   = product.TargetUrl,
                    Title = product.Title,
                    Text  = product.Text
                };
                long pid;
                if (long.TryParse(product.Product, out pid))
                {
                    itemModel.Product = catalogApi.GetProductAsync(catalogApi.GetProductUri(pid)).Result;
                    if (string.IsNullOrEmpty(itemModel.Url))
                    {
                        itemModel.Url = linkGenerator.GenerateProductLink(pid);
                    }
                    if (string.IsNullOrEmpty(itemModel.Title))
                    {
                        itemModel.Title = itemModel.Product.DisplayName;
                    }
                    if (string.IsNullOrEmpty(itemModel.Text))
                    {
                        itemModel.Text = itemModel.Product.ShortDescription;
                    }
                }
                model.Products.Add(itemModel);
            }

            return(model);
        }
Пример #6
0
 public override string GetUrl(ILinkGenerator linkGenerator)
 {
     long pid;
     return linkGenerator.GenerateProductLink(long.TryParse(Product, out pid) ? pid : (long?)null);
 }
        public override string GetUrl(ILinkGenerator linkGenerator)
        {
            long pid;

            return(linkGenerator.GenerateProductLink(long.TryParse(Product, out pid) ? pid : (long?)null));
        }
Пример #8
0
        public override PartAdapterRenderInfo PrepareRenderInfo(HtmlHelper html, ContentItem part)
        {
            var currentItem = (ListofLinksPart)part;

            html.ViewBag.ComponentID = "item_" + part.ID; // unique id for DOM element / CSS


            var viewModel = new ListofLinksViewModel
            {
                Title           = currentItem.Title,
                BackgroundColor = currentItem.BackgroundColor,
                ForegroundColor = currentItem.ForegroundColor,
                Subtitle        = currentItem.Subtitle,
                TemplateItems   = currentItem.TemplateItems,
                UseButton       = currentItem.UseButton,
                Links           = new List <ListOfLinksItem>()
            };

            foreach (var listofLinksItem in currentItem.Links)
            {
                ListOfLinksItem itemViewModel;

                string targetUrl;
                if (listofLinksItem is ProductListofLinksItem)
                {
                    var  item = (ProductListofLinksItem)listofLinksItem;
                    long pid;
                    targetUrl     = html.AbsoluteUrlWithHttp(_linkGenerator.GenerateProductLink(long.TryParse(item.Product, out pid) ? pid : (long?)null));
                    itemViewModel = new ListOfLinksItem(
                        item.Title,
                        item.Target,
                        item.LinkText,
                        targetUrl,
                        item.SuppressLinks);
                }
                else if (listofLinksItem is CategoryListofLinksItem)
                {
                    var item = (CategoryListofLinksItem)listofLinksItem;
                    targetUrl     = html.AbsoluteUrlWithHttp(_linkGenerator.GenerateCategoryLink(long.Parse(item.Category), item.ForceListPage));
                    itemViewModel = new ListOfLinksItem(
                        item.Title,
                        item.Target,
                        item.LinkText,
                        targetUrl,
                        item.SuppressLinks);
                }
                else if (listofLinksItem is ContentPageListofLinksItem)
                {
                    var item = (ContentPageListofLinksItem)listofLinksItem;
                    targetUrl = html.AbsoluteUrlWithHttp(_linkGenerator.GenerateLinkForNamedContentItem(item.ContentPage));

                    itemViewModel = new ListOfLinksItem(
                        item.Title,
                        item.Target,
                        item.LinkText,
                        targetUrl,
                        item.SuppressLinks);
                }
                else
                {
                    //targetUrl = html.AbsoluteUrlWithHttp(listofLinksItem.TargetUrl);
                    itemViewModel = new ListOfLinksItem(listofLinksItem.Title,
                                                        listofLinksItem.Target, listofLinksItem.LinkText, listofLinksItem.TargetUrl,
                                                        listofLinksItem.SuppressLinks);
                }

                // Apply suffix at this point
                if (!string.IsNullOrEmpty(listofLinksItem.UrlSuffix))
                {
                    itemViewModel.TargetUrl = string.Concat(itemViewModel.TargetUrl, listofLinksItem.UrlSuffix);
                }

                viewModel.Links.Add(itemViewModel);
            }

            return(new PartAdapterRenderInfo {
                Path = "ListOfLinks/Index", Model = viewModel
            });
        }