public ProductViewModel GetWildCardProductViewModel(Item datasource, Rendering currentRendering) { ProductViewModel productViewModel; var productId = CatalogUrlManager.ExtractItemIdFromCurrentUrl().Replace(" ", "-"); var virtualProductCacheKey = string.Format(CultureInfo.InvariantCulture, "VirtualProduct_{0}", productId); if (this.CurrentSiteContext.Items.Contains(virtualProductCacheKey)) { productViewModel = this.CurrentSiteContext.Items[virtualProductCacheKey] as ProductViewModel; } else { if (string.IsNullOrEmpty(productId)) { //No ProductId passed in on the URL //Use to Storefront DefaultProductId productId = StorefrontManager.CurrentStorefront.DefaultProductId; } var productItem = SearchNavigation.GetProduct(productId, this.CurrentCatalog.Name); if (productItem == null) { var message = string.Format(CultureInfo.InvariantCulture, "The requested product '{0}' does not exist in the catalog '{1}' or cannot be displayed in the language '{2}'", productId, this.CurrentCatalog.Name, Context.Language); Log.Error(message, this); throw new InvalidOperationException(message); } datasource = productItem; productViewModel = this.GetProductViewModel(datasource, currentRendering); this.CurrentSiteContext.Items.Add(virtualProductCacheKey, productViewModel); } return(productViewModel); }
/// <summary> /// Visiteds the product details page. /// </summary> /// <param name="storefront">The storefront.</param> /// <returns> /// The manager response /// </returns> public virtual ManagerResponse <CatalogResult, bool> VisitedProductDetailsPage([NotNull] CommerceStorefront storefront) { Assert.ArgumentNotNull(storefront, "storefront"); string productId = CatalogUrlManager.ExtractItemIdFromCurrentUrl(); string parentCategoryName = CatalogUrlManager.ExtractCategoryNameFromCurrentUrl(); var request = new VisitedProductDetailsPageRequest(storefront.ShopName, productId, productId, parentCategoryName, parentCategoryName); var result = this.CatalogServiceProvider.VisitedProductDetailsPage(request); if (!result.Success) { Helpers.LogSystemMessages(result.SystemMessages, result); } return(new ManagerResponse <CatalogResult, bool>(result, result.Success)); }
/// <summary> /// This method returns the current category by URL /// </summary> /// <returns>The category.</returns> public Category GetCurrentCategoryByUrl() { Category currentCategory; var categoryId = CatalogUrlManager.ExtractItemIdFromCurrentUrl(); string virtualCategoryCacheKey = string.Format(CultureInfo.InvariantCulture, "VirtualCategory_{0}", categoryId); if (CurrentSiteContext.Items.Contains(virtualCategoryCacheKey)) { currentCategory = CurrentSiteContext.Items[virtualCategoryCacheKey] as Category; } else { currentCategory = GetCategory(categoryId); CurrentSiteContext.Items.Add(virtualCategoryCacheKey, currentCategory); } return(currentCategory); }