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); }
public ActionResult GiftCardRating() { this.Item = SearchNavigation.GetProduct(StorefrontManager.CurrentStorefront.GiftCardProductId, CurrentCatalog.Name); var productViewModel = _giftCardRepository.GetGiftCardViewModel(this.Item, this.CurrentRendering); return(View("GiftCardRating", productViewModel)); }
public JsonResult GetCurrentProductStockInfo(ProductStockInfoInputModel model) { try { Assert.ArgumentNotNull(model, "model"); var validationResult = new BaseJsonResult(); this.ValidateModel(validationResult); if (validationResult.HasErrors) { return(Json(validationResult, JsonRequestBehavior.AllowGet)); } var currentProductItem = SearchNavigation.GetProduct(model.ProductId, CurrentCatalog.Name); var productId = currentProductItem.Name; var catalogName = currentProductItem["CatalogName"]; var products = new List <CommerceInventoryProduct>(); if (currentProductItem.HasChildren) { foreach (Item item in currentProductItem.Children) { products.Add(new CommerceInventoryProduct { ProductId = productId, CatalogName = catalogName, VariantId = item["VariantId"] }); } } else { products.Add(new CommerceInventoryProduct { ProductId = productId, CatalogName = catalogName }); } var response = this.InventoryManager.GetStockInformation(this.CurrentStorefront, products, StockDetailsLevel.All); var result = new StockInfoListBaseJsonResult(response.ServiceProviderResult); if (response.Result == null) { return(Json(result, JsonRequestBehavior.AllowGet)); } result.Initialize(response.Result); var stockInfo = response.Result.FirstOrDefault(); if (stockInfo != null) { this.InventoryManager.VisitedProductStockStatus(this.CurrentStorefront, stockInfo, string.Empty); } return(Json(result, JsonRequestBehavior.AllowGet)); } catch (Exception e) { CommerceLog.Current.Error("GetCurrentProductStockInfo", this, e); return(Json(new BaseJsonResult("GetCurrentProductStockInfo", e), JsonRequestBehavior.AllowGet)); } }
public StockInfoListBaseJsonResult GetCurrentProductStockInfo(string productId) { var currentProductItem = SearchNavigation.GetProduct(productId, CurrentCatalog.Name); productId = currentProductItem.Name; var catalogName = currentProductItem[CommerceTemplates.CommerceGenerated.GeneralCategory.Fields.CatalogName]; var products = new List <CommerceInventoryProduct>(); if (currentProductItem.HasChildren) { foreach (Item item in currentProductItem.Children) { products.Add(new CommerceInventoryProduct { ProductId = productId, CatalogName = catalogName, VariantId = item.Name }); } } else { products.Add(new CommerceInventoryProduct { ProductId = productId, CatalogName = catalogName }); } var response = _inventoryManager.GetStockInformation(this.CurrentStorefront, products, StockDetailsLevel.All); var result = new StockInfoListBaseJsonResult(response.ServiceProviderResult); if (response.Result == null) { return(result); } result.Initialize(response.Result); var stockInfo = response.Result.FirstOrDefault(); if (stockInfo != null) { _inventoryManager.VisitedProductStockStatus(this.CurrentStorefront, stockInfo, string.Empty); } return(result); }
/// <summary> /// The action for rendering the product view /// </summary> /// <returns>The product view</returns> public ActionResult Product() { //Wild card pages are named "*" if (this.Item.Name == "*") { // This is a Wild Card var productViewModel = this.GetWildCardProductViewModel(); return(this.View(CurrentRenderingView, productViewModel)); } //Special handling for gift card if (this.Item.Name.ToLower(CultureInfo.InvariantCulture) == ProductItemResolver.BuyGiftCardUrlRoute) { this.Item = SearchNavigation.GetProduct(StorefrontManager.CurrentStorefront.GiftCardProductId, CurrentCatalog.Name); } return(this.View(CurrentRenderingView, GetProductViewModel(this.Item, CurrentRendering))); }
/// <summary> /// Checks to see if there is a catalog item that maps to the current id /// </summary> /// <param name="itemId">The ID of the catalog item.</param> /// <param name="catalogName">The name of the catalog that contains the catalog item.</param> /// <param name="isProduct">Specifies whether the item is a product.</param> /// <returns>An item if found, otherwise null</returns> public static Sitecore.Data.Items.Item ResolveCatalogItem(string itemId, string catalogName, bool isProduct) { Sitecore.Data.Items.Item foundItem = null; // If we make it here, the right route was used, but might have an empty value if (!string.IsNullOrEmpty(itemId)) { var cachekey = "FriendlyUrl-" + itemId + "-" + catalogName; ICacheProvider cacheProvider = CommerceTypeLoader.GetCacheProvider(CommerceConstants.KnownCacheNames.FriendlyUrlsCache); var id = cacheProvider.GetData <ID>(CommerceConstants.KnownCachePrefixes.Sitecore, CommerceConstants.KnownCacheNames.FriendlyUrlsCache, cachekey); if (ID.IsNullOrEmpty(id) || id == ID.Undefined) { if (isProduct) { foundItem = SearchNavigation.GetProduct(itemId, catalogName); } else { foundItem = SearchNavigation.GetCategory(itemId, catalogName); } if (foundItem != null) { cacheProvider.AddData <ID>(CommerceConstants.KnownCachePrefixes.Sitecore, CommerceConstants.KnownCacheNames.FriendlyUrlsCache, cachekey, foundItem.ID); } else { cacheProvider.AddData <ID>(CommerceConstants.KnownCachePrefixes.Sitecore, CommerceConstants.KnownCacheNames.FriendlyUrlsCache, cachekey, ID.Undefined); } } else if (id != ID.Undefined && id != ID.Null) { foundItem = Context.Database.GetItem(id); } } return(foundItem); }