/// <summary> /// Displays a product listing page of the class's product page type. /// </summary> public ActionResult Listing() { // Gets products of the product page type (via the generated page type code) List <LearningProductType> products = LearningProductTypeProvider.GetLearningProductTypes() .LatestVersion(false) .Published(true) .OnSite(siteName) .Culture("en-US") .CombineWithDefaultCulture() .WhereTrue("SKUEnabled") .OrderByDescending("SKUInStoreFrom") .ToList(); ShoppingCartInfo cart = shoppingService.GetCurrentShoppingCart(); // Prepares a collection of products of the LearningProductType page type to be sent to a view IEnumerable <ProductListItemViewModel> productListing = products.Select( product => new ProductListItemViewModel( product, GetPrice(product.SKU, cart), product.Product.PublicStatus?.PublicStatusDisplayName)); // Displays the action's view with an initialized view model return(View(productListing)); }
//DocSection:LoadProducts /// <summary> /// Loads pages of the LearningProductType product page type based on the specified where condition. /// </summary> /// <param name="where">Where condition that restricts the returned products.</param> /// <returns>List of view models representing products, its prices and public status display name.</returns> private List <ProductListItemViewModel> LoadProducts(WhereCondition where) { // Gets products of the LearningProductType page type from the current site List <LearningProductType> products = LearningProductTypeProvider.GetLearningProductTypes() .LatestVersion(false) .Published(true) .OnSite(SiteContext.CurrentSiteName) .Culture("en-US") .CombineWithDefaultCulture() .WhereTrue("SKUEnabled") .Where(where) .OrderByDescending("SKUInStoreFrom") .ToList(); // Gets the current shopping cart (necessary to contextualize product price calculations) ShoppingCartInfo cart = shoppingService.GetCurrentShoppingCart(); // Returns a list of products filtered by the where condition return(products.Select( product => new ProductListItemViewModel( product, GetPrice(product.SKU, cart), product.Product.PublicStatus?.PublicStatusDisplayName) ).ToList()); }
/// <summary> /// Displays a product listing page of the class's product page type. /// </summary> public ActionResult Index() { // Gets products of the product page type (via the generated page type code) List <LearningProductType> products = LearningProductTypeProvider.GetLearningProductTypes() .LatestVersion(false) .Published(true) .OnSite(siteName) .Culture("en-US") .CombineWithDefaultCulture() .WhereTrue("SKUEnabled") .OrderByDescending("SKUInStoreFrom") .ToList(); // Displays the action's view with an initialized view model return(View(products.Select( product => new ProductListItemViewModel( product, pricingService.CalculatePrice(product.SKU, shoppingService.GetCurrentShoppingCart()), product.Product.PublicStatus?.PublicStatusDisplayName)) )); }
/// <summary> /// Loads pages from the current site of the LearningProductType product page type based on the specified where condition. /// </summary> /// <param name="where">Where condition that restricts the returned products.</param> /// <returns>List of view models representing a products, its prices and public status display name.</returns> private List <ProductListItemViewModel> LoadProducts(WhereCondition where) { // Gets products of the product page type List <LearningProductType> products = LearningProductTypeProvider.GetLearningProductTypes() .LatestVersion(false) .Published(true) .OnSite(SiteContext.CurrentSiteName) .Culture("en-US") .CombineWithDefaultCulture() .WhereTrue("SKUEnabled") .Where(where) .OrderByDescending("SKUInStoreFrom") .ToList(); // Displays an initialized view model return(products.Select( product => new ProductListItemViewModel( product, pricingService.CalculatePrice(product.SKU, shoppingService.GetCurrentShoppingCart()), product.Product.PublicStatus?.PublicStatusDisplayName) ).ToList()); }
/// <summary> /// Loads all available manufacturers (as unselected) used for products of the LearningProductType product page type. /// </summary> /// <returns>List of manufacturers' models and their unselected state.</returns> private List <ProductFilterCheckboxViewModel> GetManufacturers() { // Gets manufacturers of all the product type's products var manufacturers = LearningProductTypeProvider.GetLearningProductTypes() .ToList() .Where(skuPage => skuPage.Product.Manufacturer != null) .Select(skuPage => new { skuPage.Product.Manufacturer?.ManufacturerID, skuPage.Product.Manufacturer?.ManufacturerDisplayName }) .Distinct(); // Returns a model that contains the manufacturers' display name, ID and false select state return(manufacturers.Select(manufacturer => new ProductFilterCheckboxViewModel { DisplayName = manufacturer.ManufacturerDisplayName, Value = manufacturer.ManufacturerID.ToString(), IsChecked = false }).ToList()); }