Пример #1
0
 public static void SetPageInfo(IPageInfo pageInfo, ProductDetailPageViewModel model, string pageName)
 {
     pageInfo.PageName = pageName;
     if (model == null)
     {
         pageInfo.ProductStatus = "unavailable";
     }
     else
     {
         if (!model.Product.HasVariations() || model.Product.Variations == null)
         {
             pageInfo.ProductName = model.Product.DisplayName;
             if (model.Product.Pricing.ListPrice != null)
             {
                 pageInfo.ProductPrice = model.Product.Pricing.ListPrice.Value;
             }
         }
         else
         {
             var productVariation = model.Product.Variations.Product.FirstOrDefault();
             if (productVariation != null)
             {
                 pageInfo.ProductName = model.Product.DisplayName;
                 if (model.Product.Pricing.ListPrice != null)
                 {
                     pageInfo.ProductPrice = productVariation.Pricing.ListPrice.Value;
                 }
             }
         }
     }
 }
Пример #2
0
        public IActionResult ProductDetail()
        {
            var id    = RouteData.Values["id"]?.ToString();
            var idInt = 0;

            int.TryParse(id, out idInt);
            var viewmodel = new ProductDetailPageViewModel();
            var item      = this.InstanceRepository.ProductRepository.GetAll()
                            .Include("ProductLanguages.ImageDetails")
                            .Include("ProductLanguages.ProductLanguageDescriptionDetails")
                            .Include("ProductLanguages.ProductLanguageProductDetails")
                            .Include("ProductLanguages.ProductLanguageReviewDetails")
                            .Include("ProductLanguages.LinkStores")
                            .FirstOrDefault(x => x.Id == idInt);
            var model = Mapper.ToModel(item);

            model.ProductLanguages = item.ProductLanguages.Select(pl =>
            {
                var plm = Mapper.ToModel(pl);
                if (plm != null)
                {
                    plm.ImageDetails = pl?.ImageDetails?.Select(Mapper.ToModel).ToList();
                    plm.ProductLanguageDescriptionDetails = pl?.ProductLanguageDescriptionDetails?.Select(Mapper.ToModel).ToList();
                    plm.ProductLanguageProductDetails     = pl?.ProductLanguageProductDetails?.Select(Mapper.ToModel).ToList();
                    plm.ProductLanguageReviewDetails      = pl?.ProductLanguageReviewDetails?.Select(Mapper.ToModel).ToList();
                    plm.LinkStores = pl?.LinkStores?.Select(Mapper.ToModel).ToList();
                }
                return(plm);
            }).ToList();
            viewmodel.Product = model;
            ViewBag.Tab       = "products";
            return(View(viewmodel));
        }
Пример #3
0
        private static ProductDetailPageViewModel DemoProductDetailPageViewModel()
        {
            SiteInfo si;

            WebSession.Current.TryGetSiteInfo(out si);
            var ret = new ProductDetailPageViewModel(si)
            {
            };

            return(ret);
        }
        protected virtual string GetPageTitle(ProductDetailPageViewModel model)
        {
            var title = GetPageTitleFromCurrentItem();

            if (!string.IsNullOrEmpty(title))
            {
                return(title);
            }
            title = model.Product.DisplayName;
            return(!string.IsNullOrEmpty(title) ? title : GetPageTitleFromResource());
        }
Пример #5
0
        protected string GetPageTitle(ProductDetailPageViewModel model)
        {
            var title = GetPageTitleFromCurrentItem();

            if (!string.IsNullOrEmpty(title))
            {
                return(title);
            }
            title = GetPageTitleFromModel(model);
            return(!string.IsNullOrEmpty(title) ? title : GetPageTitleFromResource());
        }
Пример #6
0
 public ProductDetailPage(Guid furnitureProductId)
 {
     InitializeComponent();
     _furnitureProductId = furnitureProductId;
     BindingContext      = viewModel = new ProductDetailPageViewModel(_furnitureProductId);
     MessagingCenter.Subscribe <AddProductPage, FurnitureProduct>(this, "UpdateProduct", async(sender, product) =>
     {
         viewModel.FurnitureProduct = product;
         Init();
     });
     Init();
 }
        public async Task <ProductDetailPageViewModel> GetProductDetail(Product product, SiteInfo siteInfo, bool skipStockAvailabilitycheck)
        {
            if (product == null)
            {
                return(null);
            }

            var displayProduct = product;

            if (product.ParentProduct != null)
            {
                product = await _catalogApi.GetProductAsync(product.ParentProduct).ConfigureAwait(false);
            }

            displayProduct = displayProduct.ParentProduct != null ? displayProduct : product.GetDisplayProduct(skipStockAvailabilitycheck);

            var formActionUri = new Uri(siteInfo.DrBuyNowFormAction);

            formActionUri = formActionUri.Query.Length > 0
                ? new Uri(formActionUri.AbsoluteUri + "?ThemeId=" + siteInfo.DrThemeId)
                : new Uri(formActionUri.AbsoluteUri + "&ThemeId=" + siteInfo.DrThemeId);

            var result = new ProductDetailPageViewModel(siteInfo)
            {
                Product            = product,
                DisplayProduct     = displayProduct,
                VariationOptions   = GetVariationsByAttributes(product, product.Variations),
                SeoMetaDescription = product.LongDescription,
                BuyViewModel       = new BuyViewModel
                {
                    SiteInfo      = siteInfo,
                    ProductId     = displayProduct.Id,
                    FormActionUri = formActionUri
                }
            };

            if (result.HasVariationOptions)
            {
                result.VariationOptionsJson = JsonConvert.SerializeObject(result.VariationOptions);
                result.VariationLevels      = result.VariationOptions.Levels
                                              .Select(l => result.VariationOptions.FirstOrDefault(l))
                                              .Where(vl => vl != null)
                                              .ToArray();
            }

            result.SetPageTitle(result.Product.DisplayName);

            return(result);
        }
Пример #8
0
        private ProductDetailPageViewModel GetDemoProduct()
        {
            SiteInfo si;

            WebSession.Current.TryGetSiteInfo(out si);
            var prod = new Product
            {
                Pricing          = new Pricing(),
                DisplayName      = "demo display name",
                ShortDescription = "demo",
                InventoryStatus  = new InventoryStatus()
            };
            var ret = new ProductDetailPageViewModel(si)
            {
                Product = prod, DisplayProduct = prod
            };

            return(ret);
        }
Пример #9
0
        public string GetPageTitleFromModel(ProductDetailPageViewModel model)
        {
            if (model != null)
            {
                var title = model.Product.CustomAttributes.ValueByName(SuperDuperTitleTagAttributeName);
                if (!string.IsNullOrEmpty(title))
                {
                    return(title);
                }
                if (model.ParentProductId != 0 && model.ParentProductId != model.Product.Id)
                {
                    var parentProd = _catApi.GetProductAsync(_catApi.GetProductUri(model.ParentProductId)).Result;

                    title = parentProd.CustomAttributes.ValueByName(SuperDuperTitleTagAttributeName);
                    if (!string.IsNullOrEmpty(title))
                    {
                        return(title);
                    }
                }
                var res = Res.PageTitle_Product;
                if (!string.IsNullOrEmpty(res))
                {
                    var idx = res.IndexOf(ProductNameSubstititionToken, StringComparison.InvariantCultureIgnoreCase);
                    if (idx >= 0)
                    {
                        string name;
                        if (!string.IsNullOrEmpty(model.Product.DisplayName))
                        {
                            name = model.Product.DisplayName;
                        }
                        else
                        {
                            name = model.Product.Id.ToString(CultureInfo.InvariantCulture);
                        }
                        return(res.Remove(idx, ProductNameSubstititionToken.Length).Insert(idx, name));
                    }
                    return(res);
                }
            }
            return(string.Empty);
        }
        public override ActionResult Index()
        {
            if (CurrentPage == null)
            {
                throw new Exception();
            }

            var startPage = CmsFinder.FindStartPageOf(CurrentPage) as StartPage;

            if (startPage == null)
            {
                return(NotFound());
            }

            var productId = Arguments.Length > 0 ?
                            Arguments[0] :
                            (CurrentItem == null || string.IsNullOrEmpty(CurrentItem.ProductID) ? null : CurrentItem.ProductID.Split().First());

            if (string.IsNullOrEmpty(productId))
            {
                return(NotFound());
            }

            AssertProductsLoaded(int.Parse(productId));

            ProductDetailPageViewModel product = null;
            SiteInfo si;

            WebSession.Current.TryGetSiteInfo(out si);
            Product p;

            if (Products.TryGetValue(Convert.ToInt32(productId), out p))
            {
                product = _prodViewModelBuilder.GetProductDetail(p, si, false).Result;
            }
            if (IsManaging && product == null)
            {
                product = new ProductDetailPageViewModel(si)
                {
                    DisplayProduct = new Product {
                        Id = 123
                    },
                    Product =
                        new Product
                    {
                        Id = 123,
                        DisplayableProduct = true,
                        Purchasable        = true,
                        InventoryStatus    = new InventoryStatus {
                            ProductIsInStock = true
                        }
                    },
                }
            }
            ;

            var model = new ShoppingCartInterstitialViewModel
            {
                Product = product,
            };

            WebSession.Current.Set(WebSession.CurrentProductSlot, product);
            ProductController.SetPageInfo(_pageInfo, product, "Sales.Interstitial");
            SetPageTitle(GetPageTitle(model.Product));

            return(View(model));
        }
Пример #11
0
        public override ActionResult Index()
        {
            var productId = Arguments.Length > 0
                ? Arguments[0]
                : (CurrentItem == null || string.IsNullOrEmpty(CurrentItem.ProductID)
                    ? null
                    : CurrentItem.ProductID.Split().First());

            long?pid;

            if (string.IsNullOrEmpty(productId))
            {
                pid = null;
            }
            else
            {
                long tempId;
                pid = long.TryParse(productId, out tempId) ? tempId : (long?)null;
            }

            AssertProductsLoaded(pid);

            if (pid != null && BogusProductIds.Contains(pid.Value))
            {
                productId = null;
            }

            // Redirect if there's a specific page created for this product.
            if (CurrentItem != null && string.IsNullOrEmpty(CurrentItem.ProductID) && pid != null)
            {
                var prodSpecificUrl = LinkGenerator.GenerateProductLink(pid);
                var productUrl      = LinkGenerator.GenerateProductLink();
                if (!prodSpecificUrl.StartsWith(productUrl, StringComparison.InvariantCultureIgnoreCase))
                {
                    return(RedirectPermanent(this.AssureHttpUrl(prodSpecificUrl + Request.Url.Query)));
                }
            }


            ProductDetailPageViewModel model = null;

            if (pid != null)
            {
                SiteInfo si;
                WebSession.Current.TryGetSiteInfo(out si);
                Product p;
                if (Products.TryGetValue(pid.Value, out p))
                {
                    model = _prodViewModelBuilder.GetProductDetail(p, si, false).Result;
                }
                else if (IsManaging)
                {
                    model = GetDemoProduct();
                }
            }

            if (model == null && !IsManaging)
            {
                return(NotFound());
            }
            if (model == null)
            {
                model = GetDemoProduct();
            }

#if SAVE_VIEW_MODEL
            SaveViewModel(model, model.Id);
#endif
            SetPageTitle(GetPageTitle(model));
            SetPageMetaData(model);

            WebSession.Current.Set(WebSession.CurrentProductSlot, model);
            WebSession.Current.SetSessionAfterAddToCartOption(CurrentItem.AfterAddToCartOption);

            SetPageInfo(_pageInfo, model, "Sales.Product");
            return(View("PageTemplates/Default", model));
        }
 public ProductDetailPage(Product item)
 {
     InitializeComponent();
     BindingContext = viewmodel = new ProductDetailPageViewModel(Navigation, item);
 }