/// <summary> /// get the stockist pages with logos /// </summary> /// <returns></returns> public ActionResult GetStockistSliders() { //create the default model var displayModel = new List <LinkItemModel>(); //get the stockist pages with logo images only var stockistPages = _homePage.Descendants().Where(page => page.ContentType.Alias == "stockistPage" && !page.Value <bool>("hideFromMenu") && page.HasProperty("stockistLogo") && page.HasValue("stockistLogo") && page.IsPublished()) .ToList(); //if we have any stockist then add them to the model if (stockistPages.Any()) { //order the stockist randomly var r = new Random(); var orderedStockists = stockistPages.OrderBy(x => r.Next()).ToList(); //create the menu item links for the slider foreach (var stockist in orderedStockists) { //set the default stockist page title var stockistName = stockist.Name; //check if we have the page title set on the current page if (stockist.HasProperty("pageTitle") && stockist.HasValue("pageTitle")) { // set the page title to override the default stockistName = stockist.GetProperty("pageTitle").Value().ToString(); } //create the stockist page item var stockistLink = new LinkItemModel { LinkTitle = stockistName, LinkUrl = stockist.Url, LinkPage = stockist, ThumbLinkImage = "/Images/NatureQuest-Logo-square.png" }; //set feature product image var stockistLogo = stockist.Value <IPublishedContent>("stockistLogo"); if (stockistLogo != null && stockistLogo.Id > 0) { var defaultCropSize = stockistLogo.GetCropUrl("thumbNail"); var logoImage = !string.IsNullOrEmpty(defaultCropSize) ? defaultCropSize : stockistLogo.GetCropUrl(250, 250); if (!string.IsNullOrWhiteSpace(logoImage)) { stockistLink.ThumbLinkImage = logoImage; } } //add the menu link to the model displayModel.Add(stockistLink); } } return(View("/Views/Partials/Global/StockistSlider.cshtml", displayModel)); }
public StandardPageViewModel PreparePageContent(StandardPageViewModel model) { //get the breadcrumb parents var pageAncestors = model.CurrentPage.Ancestors().OrderBy(page => page.Level).ToList(); //get the breadcrumb links if (pageAncestors.Any()) { foreach (var ancestor in pageAncestors) { //get the page title var pageTitle = ancestor.Name; //check if we have the page title set on the current page if (ancestor.HasProperty("pageTitle") && ancestor.HasValue("pageTitle")) { // set the page title to override the default pageTitle = ancestor.GetProperty("pageTitle").Value().ToString(); } //create the breadcrumb link var breadcrumbLink = new LinkItemModel { LinkTitle = ancestor.Id == _homePage.Id ? "Home" : pageTitle, LinkUrl = ancestor.Url, LinkPage = ancestor }; //add the link to the model model.BreadCrumbLinks.Add(breadcrumbLink); } } //get the page image if (model.CurrentPage.HasProperty("bannerImage") && model.CurrentPage.HasValue("bannerImage")) { //set the global site name var mediaItem = model.CurrentPage.Value <IPublishedContent>("bannerImage"); if (mediaItem != null && mediaItem.Id > 0) { var defaultCropSize = mediaItem.GetCropUrl("pageHeader"); var headerImagelink = !string.IsNullOrEmpty(defaultCropSize) ? defaultCropSize : mediaItem.GetCropUrl(900, 420); if (!string.IsNullOrWhiteSpace(headerImagelink)) { model.PageHeaderImage = headerImagelink; } } } //get the page html text if (model.CurrentPage.HasProperty("pageText") && model.CurrentPage.HasValue("pageText")) { model.PageContentText = model.CurrentPage.GetProperty("pageText").Value().ToString(); } //return the model with the page content return(model); }
/// <summary> /// add the menu items to the model /// </summary> /// <param name="model"></param> /// <returns></returns> public StandardPageViewModel PrepareSiteMenu(StandardPageViewModel model) { //get the menu item from the model to use var menuItem = model.SiteMenu; //set the site name menuItem.SiteName = _siteName; //get the site menu categories headline menuItem.CategoriesMenuTitle = _categoriesHeadline; //get the site menu email address menuItem.SiteEmailAddress = _siteEmailAddress; //get the side menu phone number menuItem.SitePhoneNumber = _sitePhoneNumber; //get the side menu facebook menuItem.SiteFacebook = _siteFacebook; //get the side menu instagram menuItem.SiteInstagram = _siteInstagram; //get the side menu twitter menuItem.SiteTwitter = _siteTwitter; //check if we have the home page set if (_homePage?.Id > 0) { //set the home link item menuItem.HomeLinkItem = new LinkItemModel { LinkTitle = _siteName, LinkUrl = "/", LinkPage = _homePage }; //get the 1st level child pages from the home page var landingPages = _homePage.Children.Where(page => !page.Value <bool>("hideFromMenu")).ToList(); //add these to the model if (landingPages.Any()) { //go through each landing page and add it to the list foreach (var landingPage in landingPages) { //set the default landing page title var landingPageTitle = landingPage.Name; //check if we have the page title set on the current page if (landingPage.HasProperty("pageTitle") && landingPage.HasValue("pageTitle")) { // set the page title to override the default landingPageTitle = landingPage.GetProperty("pageTitle").Value().ToString(); } //create the landing page item var pageItemLink = new LinkItemModel { LinkTitle = landingPageTitle, LinkUrl = landingPage.Url, LinkPage = landingPage, IsProductLinks = landingPage.ContentType.Alias == "productLandingPage" }; //check if this is a product link //check if this landing page has got child pages which can be displayed in the menu var landingPageChildren = landingPage.Children.Where(page => !page.Value <bool>("hideFromMenu")).ToList(); if (landingPageChildren.Any()) { //set tht flag to indicate this has children pageItemLink.HasChildLinks = true; //go through each of the child links and add them to the item foreach (var childPage in landingPageChildren) { //set the default child page title var childPageTitle = childPage.Name; //check if we have the page title set on the current page if (childPage.HasProperty("pageTitle") && childPage.HasValue("pageTitle")) { // set the page title to override the default childPageTitle = childPage.GetProperty("pageTitle").Value().ToString(); } //create the child page item var childPageLink = new LinkItemModel { LinkTitle = childPageTitle, LinkUrl = childPage.Url, LinkPage = childPage }; //check if the child link has got level 2 children for products var childPageChildren = childPage.Children.Where(page => !page.Value <bool>("hideFromMenu")).ToList(); if (childPageChildren.Any()) { //set tht flag to indicate this has children childPageLink.HasChildLinks = true; //go through each of the child links and add them to the item foreach (var grandChildPage in childPageChildren) { //set the default child page title var grandChildPageTitle = grandChildPage.Name; //check if we have the page title set on the current page if (grandChildPage.HasProperty("pageTitle") && grandChildPage.HasValue("pageTitle")) { // set the page title to override the default grandChildPageTitle = grandChildPage.GetProperty("pageTitle").Value().ToString(); } //create the child page item var grandChildPageLink = new LinkItemModel { LinkTitle = grandChildPageTitle, LinkUrl = grandChildPage.Url, LinkPage = grandChildPage }; //add the grand child link to the child links children childPageLink.ChildLinkItems.Add(grandChildPageLink); } } //add this to the items child links pageItemLink.ChildLinkItems.Add(childPageLink); } } //after getting the children, add this item ot our menu links menuItem.MenuLinks.Add(pageItemLink); } } //get the feature products to display var featureProducts = _homePage.Descendants().Where(page => page.ContentType.Alias == "productPage" && !page.Value <bool>("hideFromMenu") && page.Value <bool>("featureProduct") && page.HasProperty("productImages") && page.HasValue("productImages") && page.IsPublished()) .ToList(); //check if we have any feature products if (featureProducts.Any()) { //order the features randomly var r = new Random(); var menuFeatureProducts = featureProducts.OrderBy(x => r.Next()).ToList(); //create the mega menu items for the feature products foreach (var featureProduct in menuFeatureProducts) { //set the default landing page title var productTitle = featureProduct.Name; //check if we have the page title set on the current page if (featureProduct.HasProperty("pageTitle") && featureProduct.HasValue("pageTitle")) { // set the page title to override the default productTitle = featureProduct.GetProperty("pageTitle").Value().ToString(); } //create the landing page item var featureProductLink = new LinkItemModel { LinkTitle = productTitle, LinkUrl = featureProduct.Url, LinkPage = featureProduct, LinkImage = "/Images/NatureQuest-Logo-square.png", ThumbLinkImage = "/Images/NatureQuest-Logo-square.png" }; //get the price child items var productPrices = featureProduct.Children().Where(page => page.ContentType.Alias == "productPrice").ToList(); if (productPrices.Any()) { //if we have a featured price use that 1 var displayedPrice = productPrices.FirstOrDefault(price => price.HasProperty("featuredPrice") && price.HasValue("featuredPrice") && price.Value <bool>("featuredPrice")); //if we don't have the featured price then just get the 1st 1 if (displayedPrice == null) { displayedPrice = productPrices.FirstOrDefault(price => price.HasProperty("normalPrice") && price.HasValue("normalPrice") && price.Value <decimal>("normalPrice") != 0); } //go through the prices and add the if (displayedPrice != null) { //set the default price decimal productOriginalPrice = 0; //check if we have a price set if (displayedPrice.HasProperty("normalPrice") && displayedPrice.HasValue("normalPrice")) { // set the product price productOriginalPrice = displayedPrice.Value <decimal>("normalPrice"); } //set the default sale price decimal productSalePrice = 0; //check if we have a sale price if (displayedPrice.HasProperty("salePrice") && displayedPrice.HasValue("salePrice")) { // set the sale price productSalePrice = displayedPrice.Value <decimal>("salePrice"); } //set the variant name var priceVariant = displayedPrice.Name; //check if we have the price variant set if (displayedPrice.HasProperty("productVariant") && displayedPrice.HasValue("productVariant")) { // set the page title to override the default priceVariant = displayedPrice.GetProperty("productVariant").Value().ToString(); } // get the flag ti indicate its a featured price var isFeaturedPrice = false; if (displayedPrice.HasProperty("featuredPrice") && displayedPrice.HasValue("featuredPrice")) { // set the page flag from the value isFeaturedPrice = displayedPrice.Value <bool>("featuredPrice"); } // calculate the percentage var salePercentage = 0; if (productSalePrice > 0) { salePercentage = 100 - Convert.ToInt32(productSalePrice / productOriginalPrice * 100); } //create the new price model var priceModel = new ProductPriceModel { ProductPrice = productOriginalPrice, SalePrice = productSalePrice, ProductVariant = priceVariant, IsFeaturedPrice = isFeaturedPrice, SalePercentage = salePercentage }; // add the price to the model featureProductLink.ProductPrice = priceModel; } } //set feature product image var productImages = featureProduct.Value <IEnumerable <IPublishedContent> >("productImages").ToList(); if (productImages.Any()) { var firstImage = productImages.FirstOrDefault(); if (firstImage != null && firstImage.Id > 0) { //get the normal image size var defaultCropSize = firstImage.GetCropUrl("product"); var normaImagelink = !string.IsNullOrEmpty(defaultCropSize) ? defaultCropSize : firstImage.GetCropUrl(1000, 670); if (!string.IsNullOrWhiteSpace(normaImagelink)) { featureProductLink.LinkImage = normaImagelink; } //get the thumbnail image var thumbCropSize = firstImage.GetCropUrl("thumbNail"); var thumbImagelink = !string.IsNullOrEmpty(thumbCropSize) ? thumbCropSize : firstImage.GetCropUrl(250, 250); if (!string.IsNullOrWhiteSpace(thumbImagelink)) { featureProductLink.ThumbLinkImage = thumbImagelink; } } } //add the feature link to the model menuItem.FeaturedProductsLinks.Add(featureProductLink); } } //get the category products to display var categoryProducts = _homePage.Descendants().Where(page => page.ContentType.Alias == "productCategoryPage" && page.IsPublished() && !page.Value <bool>("hideFromMenu")) .ToList(); //check if we have the category pages if (categoryProducts.Any()) { //go through each category page and add it to the list foreach (var categoryPage in categoryProducts) { //set the default category page title var categoryPageTitle = categoryPage.Name; //check if we have the page title set on the current page if (categoryPage.HasProperty("pageTitle") && categoryPage.HasValue("pageTitle")) { // set the page title to override the default categoryPageTitle = categoryPage.GetProperty("pageTitle").Value().ToString(); } //create the category page item var categoryItemLink = new LinkItemModel { LinkTitle = categoryPageTitle, LinkUrl = categoryPage.Url, LinkPage = categoryPage }; //check if this category page has got child pages which can be displayed in the menu var categoryPageChildren = categoryPage.Children.Where(page => !page.Value <bool>("hideFromMenu")).ToList(); //go through each of the product pages and add them to the item foreach (var productPage in categoryPageChildren) { //set the default product page title var productPageTitle = productPage.Name; //check if we have the page title set on the current page if (productPage.HasProperty("pageTitle") && productPage.HasValue("pageTitle")) { // set the page title to override the default productPageTitle = productPage.GetProperty("pageTitle").Value().ToString(); } //create the child page item var productPageLink = new LinkItemModel { LinkTitle = productPageTitle, LinkUrl = productPage.Url, LinkPage = productPage }; //add the product link to the category categoryItemLink.ChildLinkItems.Add(productPageLink); } //add the category link to the menu menuItem.CategoryProductsLinks.Add(categoryItemLink); } } } //check if we have the site details page for the footer if (_globalDetailsPage.Id > 0) { //get the opening hours if set if (_globalDetailsPage.HasProperty("openingHours") && _globalDetailsPage.HasValue("openingHours")) { //set the list of opening hours menuItem.OpeningHours = _globalDetailsPage.Value <string[]>("openingHours"); } //get the footer links if (_globalDetailsPage.HasProperty("footerLinks") && _globalDetailsPage.HasValue("footerLinks")) { //set the list of pages to use for the footer links var footerPages = _globalDetailsPage.Value <List <IPublishedContent> >("footerLinks"); if (footerPages.Any()) { foreach (var footerPage in footerPages) { //set the default landing page title var footerPageTitle = footerPage.Name; //check if we have the page title set on the current page if (footerPage.HasProperty("pageTitle") && footerPage.HasValue("pageTitle")) { // set the page title to override the default footerPageTitle = footerPage.GetProperty("pageTitle").Value().ToString(); } //create the landing page item var footerLink = new LinkItemModel { LinkTitle = footerPageTitle, LinkUrl = footerPage.Url, LinkPage = footerPage }; //add the link to the footer links menuItem.FooterLinks.Add(footerLink); } } } //get the opening hours if set if (_globalDetailsPage.HasProperty("subscribeText") && _globalDetailsPage.HasValue("subscribeText")) { //set the list of opening hours menuItem.SubscribeText = _globalDetailsPage.Value <string>("subscribeText"); } } //return the view model with the menu items added return(model); }