Created
March 8, 2020 17:16
-
-
Save sotirisf/afb3c900e49f11c920ac14d28a0eb849 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Collections.Generic; | |
| using System.Web.Mvc; | |
| using Umbraco.Core.Models.PublishedContent; | |
| using Umbraco.Web.Mvc; | |
| using Umbraco.Web.PublishedModels; | |
| using UmbracoMLCultureTest.Models; | |
| namespace UmbracoMLCultureTest.Controllers | |
| { | |
| public class Products2Controller : SurfaceController | |
| { | |
| private readonly IVariationContextAccessor _variationContextAccessor; | |
| public Products2Controller(IVariationContextAccessor variationContextAccessor) | |
| { | |
| _variationContextAccessor = variationContextAccessor; | |
| } | |
| public ActionResult GetProductsNewWay(int productRootId, string defaultCurrency, string culture = "") | |
| { | |
| // This is how the culture is set for the context we are in | |
| _variationContextAccessor.VariationContext = new VariationContext(culture); | |
| return PartialView("ProductList", GetProductVm(productRootId, defaultCurrency)); | |
| } | |
| private IEnumerable<ProductViewModel> GetProductVm(int productRootId, string defaultCurrency) | |
| { | |
| var productsRootPage = Umbraco.Content(productRootId); | |
| foreach (Product product in productsRootPage.Children) | |
| { | |
| var vm = new ProductViewModel(); | |
| vm.Price = product.Price; | |
| vm.Name = product.ProductName; | |
| vm.PhotoUrl = product.Photos.Url; | |
| vm.Url = product.Url; | |
| vm.DefaultCurrency = defaultCurrency; | |
| yield return vm; | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment