public virtual CategoryNavigationViewModel CreateViewModel() { var categoryNavigationViewModel = new CategoryNavigationViewModel(); var rootCategories = CatalogLibrary.GetRootCategories().Where(x => x.DisplayOnSite).ToList(); var currentPriceGroup = SiteContext.Current.CatalogContext.CurrentPriceGroup; categoryNavigationViewModel.Categories = this.MapCategories(rootCategories, SiteContext.Current.CatalogContext.CurrentCategory); categoryNavigationViewModel.Currencies = this.MapCurrencies(SiteContext.Current.CatalogContext.CurrentCatalog.AllowedPriceGroups, currentPriceGroup); categoryNavigationViewModel.CurrentCurrency = new CategoryNavigationCurrencyViewModel() { DisplayName = currentPriceGroup.Name, PriceGroupId = currentPriceGroup.PriceGroupId, }; categoryNavigationViewModel.ProductDetailsPageId = this.productDetailsPageId; this.MapConfigurationFields(categoryNavigationViewModel); categoryNavigationViewModel.Routes.Add(RouteConstants.SEARCH_ROUTE_NAME, RouteConstants.SEARCH_ROUTE_VALUE); categoryNavigationViewModel.Routes.Add(RouteConstants.SEARCH_SUGGESTIONS_ROUTE_NAME, RouteConstants.SEARCH_SUGGESTIONS_ROUTE_VALUE); categoryNavigationViewModel.Routes.Add(RouteConstants.PRICE_GROUP_ROUTE_NAME, RouteConstants.PRICE_GROUP_ROUTE_VALUE); categoryNavigationViewModel.Routes.Add(RouteConstants.GET_BASKET_ROUTE_NAME, RouteConstants.GET_BASKET_ROUTE_VALUE); return(categoryNavigationViewModel); }
public IHttpActionResult Add(AddToBasketDTO model) { string variantSku = null; var product = CatalogLibrary.GetProduct(model.Sku); if (model.Variants == null || !model.Variants.Any()) { var variant = product.Variants.FirstOrDefault(); if (variant != null) { variantSku = variant.VariantSku; } } else { var variants = product.Variants.AsEnumerable(); foreach (var v in model.Variants) { variants = variants.Where(pv => pv.ProductProperties.Any(pp => pp.Value == v.Value)); } var variant = variants.FirstOrDefault(); if (variant != null) { variantSku = variant.VariantSku; } } TransactionLibrary.AddToBasket(model.Quantity, model.Sku, variantSku); return(Json(this.GetBasketModel())); }
public ActionResult HomePageTabWithProducts(List <string> productIds) { ProductsViewModel productsViewModel = new ProductsViewModel(); //loop productIds foreach (var productId in productIds) { var product = CatalogLibrary.GetProduct(Convert.ToInt32(productId)); productsViewModel.Products.Add(new ProductViewModel() { Name = product.Name, PriceCalculation = CatalogLibrary.CalculatePrice(product), Url = CatalogLibrary.GetNiceUrlForProduct(product), Sku = product.Sku, IsVariant = product.IsVariant, VariantSku = product.VariantSku, ThumbnailImageUrl = ObjectFactory.Instance.Resolve <IImageService>().GetImage(product.ThumbnailImageMediaId).Url }); //Get image and other details } // add to model return(View("/views/PartialView/_HomePageTabProducts.cshtml", productsViewModel)); }
private UcommerceProductDto ConvertProductToUcommerceProductDto(Product product) { var imageService = ObjectFactory.Instance.Resolve <IImageService>(); var url = CatalogLibrary.GetNiceUrlForProduct(product); var price = CatalogLibrary.CalculatePrice(product); var ucommerceProduct = new UcommerceProductDto { ProductName = product.Name, ProductSku = product.Sku, ProductUrl = url, Price = "-", Tax = "-" }; if (price.YourPrice != null) { ucommerceProduct.Price = price.YourPrice.Amount.ToString(); ucommerceProduct.Tax = price.YourTax.ToString(); } if (string.IsNullOrWhiteSpace(product.PrimaryImageMediaId) == false) { ucommerceProduct.ImageUrl = imageService.GetImage(product.PrimaryImageMediaId).Url; } return(ucommerceProduct); }
public override ActionResult Index(RenderModel model) { PurchaseOrder basket = TransactionLibrary.GetBasket().PurchaseOrder; var basketModel = new PurchaseOrderViewModel(); foreach (var orderLine in basket.OrderLines) { var orderLineViewModel = new OrderlineViewModel { Quantity = orderLine.Quantity, ProductName = orderLine.ProductName, Sku = orderLine.Sku, VariantSku = orderLine.VariantSku, Total = new Money(orderLine.Total.GetValueOrDefault(), basket.BillingCurrency).ToString(), Discount = orderLine.Discount, Tax = new Money(orderLine.VAT, basket.BillingCurrency).ToString(), Price = new Money(orderLine.Price, basket.BillingCurrency).ToString(), ProductUrl = CatalogLibrary.GetNiceUrlForProduct(CatalogLibrary.GetProduct(orderLine.Sku)), PriceWithDiscount = new Money(orderLine.Price - orderLine.UnitDiscount.GetValueOrDefault(), basket.BillingCurrency).ToString(), OrderLineId = orderLine.OrderLineId }; basketModel.OrderLines.Add(orderLineViewModel); } basketModel.OrderTotal = new Money(basket.OrderTotal.GetValueOrDefault(), basket.BillingCurrency).ToString(); basketModel.DiscountTotal = new Money(basket.DiscountTotal.GetValueOrDefault(), basket.BillingCurrency).ToString(); basketModel.TaxTotal = new Money(basket.TaxTotal.GetValueOrDefault(), basket.BillingCurrency).ToString(); basketModel.SubTotal = new Money(basket.SubTotal.GetValueOrDefault(), basket.BillingCurrency).ToString(); return(View("/Views/Basket.cshtml", basketModel)); }
private void SetupProduct(Product product) { litHeadline.Text = product.DisplayName(); productSku.Text = product.Sku; litDescription.Text = product.GetDescription(CultureInfo.CurrentCulture.ToString()).LongDescription; var price = CatalogLibrary.CalculatePrice(product); if (price.YourPrice != null) { litPrice.Text = price.YourPrice.Amount.ToString(); litTax.Text = price.YourTax.ToString(); } else { btnAddToBasket.Enabled = false; btnAddToBasket.Text = "This product has not been assigned a price."; litPrice.Text = "-"; litTax.Text = "-"; } if (string.IsNullOrWhiteSpace(product.PrimaryImageMediaId)) { return; } var imageService = ObjectFactory.Instance.Resolve <IImageService>(); imgTop.ImageUrl = imageService.GetImage(product.PrimaryImageMediaId).Url; }
protected void Page_Load(object sender, EventArgs e) { var catalogContext = ObjectFactory.Instance.Resolve <ICatalogContext>(); var imageService = ObjectFactory.Instance.Resolve <IImageService>(); if (CurrentProduct == null) { Visible = false; return; } string url = CatalogLibrary.GetNiceUrlForProduct(CurrentProduct, catalogContext.CurrentCategory); PriceCalculation price = CatalogLibrary.CalculatePrice(CurrentProduct); if (!string.IsNullOrWhiteSpace(CurrentProduct.ThumbnailImageMediaId)) { productImage.ImageUrl = imageService.GetImage(CurrentProduct.ThumbnailImageMediaId).Url; hlImage.Visible = true; } hlProduct.Text = CurrentProduct.DisplayName(); hlProduct.NavigateUrl = url; hlViewMore.NavigateUrl = url; hlImage.NavigateUrl = url; litPrice.Text = price?.YourPrice?.Amount.ToString() ?? "-"; if (price?.YourTax != null) { litTax.Text = price.YourTax.ToString(); } }
public IHttpActionResult ChangePriceGroup(ChangePriceGroupDTO model) { var priceGroupRepository = ObjectFactory.Instance.Resolve <IRepository <PriceGroup> >(); CatalogLibrary.ChangePriceGroup(priceGroupRepository.Get(model.PriceGroupId)); return(Ok()); }
public ActionResult Index(ProductReviewViewModel formReview) { var product = SiteContext.Current.CatalogContext.CurrentProduct; var category = SiteContext.Current.CatalogContext.CurrentCategory; var request = System.Web.HttpContext.Current.Request; var basket = SiteContext.Current.OrderContext.GetBasket(); if (request.Form.AllKeys.All(x => x != "review-product")) { return(RedirectToAction("Index")); } var name = formReview.Name; var email = formReview.Email; var rating = Convert.ToInt32(formReview.Rating) * 20; var reviewHeadline = formReview.Title; var reviewText = formReview.Comments; if (basket.PurchaseOrder.Customer == null) { basket.PurchaseOrder.Customer = new Customer() { FirstName = name, LastName = String.Empty, EmailAddress = email }; } else { basket.PurchaseOrder.Customer.FirstName = name; if (basket.PurchaseOrder.Customer.LastName == null) { basket.PurchaseOrder.Customer.LastName = String.Empty; } basket.PurchaseOrder.Customer.EmailAddress = email; } basket.PurchaseOrder.Customer.Save(); var review = new ProductReview() { ProductCatalogGroup = SiteContext.Current.CatalogContext.CurrentCatalogGroup, ProductReviewStatus = ProductReviewStatus.SingleOrDefault(s => s.Name == "New"), CreatedOn = DateTime.Now, CreatedBy = "System", Product = product, Customer = basket.PurchaseOrder.Customer, Rating = rating, ReviewHeadline = reviewHeadline, ReviewText = reviewText, Ip = request.UserHostName }; product.AddProductReview(review); PipelineFactory.Create <ProductReview>("ProductReview").Execute(review); return(Redirect(CatalogLibrary.GetNiceUrlForProduct(product, category))); }
public IHttpActionResult ProductPrices(ProductDTO productPricesModel) { var currentPriceGroupCurrency = SiteContext.Current.CatalogContext.CurrentPriceGroup.Currency; var productGuidsToGetPricesFor = ProductGuidsToGetPricesFor(productPricesModel); var productsPrices = CatalogLibrary.CalculatePrice(productGuidsToGetPricesFor); return(Json(MapToProductPricesViewModels(productsPrices, currentPriceGroupCurrency))); }
public void GetAllProductsRecursive(Category currentCategory) { _products.AddRange(CatalogLibrary.GetProducts(currentCategory)); foreach (var childCategory in currentCategory.Categories) { GetAllProductsRecursive(childCategory); } }
// GET: PartialView public ActionResult CategoryNavigation() { var cn = new CategoryNavigationViewModel(); ICollection <Category> rootCategories = CatalogLibrary.GetRootCategories(); cn.Categories = MapCategories(rootCategories); return(View("/views/PartialView/CategoryNavigation.cshtml", cn)); }
public ActionResult CategoryNavigation() { var categoryNavigationModel = new CategoryNavigationViewModel(); ICollection <Category> rootCategories = CatalogLibrary.GetRootCategories(); categoryNavigationModel.Categories = MapCategories(rootCategories); return(View("/views/PartialView/_HeaderMainMenuCategoryNav.cshtml", categoryNavigationModel)); }
public ActionResult CategoryNavigation() { var categoryNavigationModel = new CategoryNavigationViewModel(); ICollection <Category> rootCategories = CatalogLibrary.GetRootCategories().Where(x => x.DisplayOnSite).ToList(); categoryNavigationModel.Categories = MapCategories(rootCategories); return(View("/views/PartialView/CategoryNavigation.cshtml", categoryNavigationModel)); }
public IHttpActionResult GetBasket() { var currency = SiteContext.Current.CatalogContext.CurrentCatalog.PriceGroup.Currency; var purchaseOrder = TransactionLibrary.GetBasket(false).PurchaseOrder; var subTotal = new Money(purchaseOrder.SubTotal.Value, currency); var taxTotal = new Money(purchaseOrder.TaxTotal.Value, currency); var discountTotal = new Money(purchaseOrder.DiscountTotal.Value, currency); var orderTotal = new Money(purchaseOrder.OrderTotal.Value, currency); var basket = new Basket { SubTotal = purchaseOrder.SubTotal, TaxTotal = purchaseOrder.TaxTotal, DiscountTotal = purchaseOrder.DiscountTotal, OrderTotal = purchaseOrder.OrderTotal, TotalItems = purchaseOrder.OrderLines.Sum(l => l.Quantity), FormattedSubTotal = subTotal.ToString(), FormattedTaxTotal = taxTotal.ToString(), FormattedDiscountTotal = discountTotal.ToString(), FormattedOrderTotal = orderTotal.ToString(), FormattedTotalItems = purchaseOrder.OrderLines.Sum(l => l.Quantity).ToString("#,##"), LineItems = new List <LineItem>() }; foreach (var line in purchaseOrder.OrderLines) { var product = CatalogLibrary.GetProduct(line.Sku); var url = CatalogLibrary.GetNiceUrlForProduct(product); var imageUrl = GetImageUrlForProduct(product); var lineTotal = new Money(line.Total.Value, currency); var lineItem = new LineItem { OrderLineId = line.OrderLineId, Quantity = line.Quantity, Sku = line.Sku, VariantSku = line.VariantSku, Url = url, ImageUrl = imageUrl, Price = line.Price, ProductName = line.ProductName, Total = line.Total, FormattedTotal = lineTotal.ToString(), UnitDiscount = line.UnitDiscount, VAT = line.VAT, VATRate = line.VATRate }; basket.LineItems.Add(lineItem); } return(Json(new { Basket = basket })); }
public GetBasketResponse(UCommerce.EntitiesV2.Basket basket) { var currency = SiteContext.Current.CatalogContext.CurrentCatalog.PriceGroup.Currency; var po = basket.PurchaseOrder; var subTotal = new Money(po.SubTotal.Value, currency); var taxTotal = new Money(po.TaxTotal.Value, currency); var discountTotal = new Money(po.DiscountTotal.Value, currency); var orderTotal = new Money(po.OrderTotal.Value, currency); Basket = new Basket { SubTotal = po.SubTotal, TaxTotal = po.TaxTotal, DiscountTotal = po.DiscountTotal, OrderTotal = po.OrderTotal, TotalItems = po.OrderLines.Sum(l => l.Quantity), FormattedSubTotal = subTotal.ToString(), FormattedTaxTotal = taxTotal.ToString(), FormattedDiscountTotal = discountTotal.ToString(), FormattedOrderTotal = orderTotal.ToString(), FormattedTotalItems = po.OrderLines.Sum(l => l.Quantity).ToString("#,##"), LineItems = new List <LineItem>() }; foreach (var line in po.OrderLines) { var product = CatalogLibrary.GetProduct(line.Sku); var url = CatalogLibrary.GetNiceUrlForProduct(product); var imageUrl = getImageUrlForProduct(product); var lineTotal = new Money(line.Total.Value, currency); var lineItem = new LineItem { OrderLineId = line.OrderLineId, Quantity = line.Quantity, Sku = line.Sku, VariantSku = line.VariantSku, Url = url, ImageUrl = imageUrl, Price = line.Price, ProductName = line.ProductName, Total = line.Total, FormattedTotal = lineTotal.ToString(), UnitDiscount = line.UnitDiscount, VAT = line.VAT, VATRate = line.VATRate }; Basket.LineItems.Add(lineItem); } }
public ActionResult Rendering() { BreadcrumbWrapper breadcrumbs = new BreadcrumbWrapper(); IList <Item> items = GetBreadcrumbItems(); foreach (Item item in items) { if (!IsTemplateBlacklisted(item.TemplateName)) { BreadcrumbViewModel crumb = new BreadcrumbViewModel(item); crumb.BreadcrumbName = item["Name"]; crumb.IsActive = Sitecore.Context.Item.ID == item.ID; crumb.BreadcrumbUrl = LinkManager.GetItemUrl(item); breadcrumbs.SitecoreBreadcrumbs.Add(crumb); } } Product product = SiteContext.Current.CatalogContext.CurrentProduct; Category lastCategory = SiteContext.Current.CatalogContext.CurrentCategory; foreach (var category in SiteContext.Current.CatalogContext.CurrentCategories) { BreadcrumbViewModelUcommerce crumb = new BreadcrumbViewModelUcommerce() { BreadcrumbNameUcommerce = category.DisplayName(), BreadcrumbUrlUcommerce = CatalogLibrary.GetNiceUrlForCategory(category) }; lastCategory = category; breadcrumbs.UcommerceBreadcrumbs.Add(crumb); } if (product != null) { var breadcrumb = new BreadcrumbViewModelUcommerce() { BreadcrumbNameUcommerce = product.DisplayName(), BreadcrumbUrlUcommerce = CatalogLibrary.GetNiceUrlForProduct(product, lastCategory) }; breadcrumbs.UcommerceBreadcrumbs.Add(breadcrumb); } if (IsTemplateWhitelisted(Sitecore.Context.Item.TemplateName)) { BreadcrumbViewModelUcommerce currentCrumb = new BreadcrumbViewModelUcommerce(); currentCrumb.BreadcrumbNameUcommerce = Sitecore.Context.Item.DisplayName; currentCrumb.BreadcrumbUrlUcommerce = LinkManager.GetItemUrl(Sitecore.Context.Item); breadcrumbs.UcommerceBreadcrumbs.Add(currentCrumb); } return(View(breadcrumbs)); }
public List <Folder> GetFolders() { var folders = new List <Folder>(); foreach (var category in CatalogLibrary.GetRootCategories()) { var folder = GenerateFolderTree(category); folders.Add(folder); } return(folders); }
public ActionResult Index() { IList <BreadcrumbsViewModel> breadcrumbs = new List <BreadcrumbsViewModel>(); Category lastCategory = null; Product product = SiteContext.Current.CatalogContext.CurrentProduct; foreach (var category in SiteContext.Current.CatalogContext.CurrentCategories) { var breadcrumb = new BreadcrumbsViewModel { BreadcrumbName = category.DisplayName(), BreadcrumbUrl = CatalogLibrary.GetNiceUrlForCategory(category) }; lastCategory = category; breadcrumbs.Add(breadcrumb); } if (product != null) { var breadcrumb = new BreadcrumbsViewModel { BreadcrumbName = product.DisplayName(), BreadcrumbUrl = CatalogLibrary.GetNiceUrlForProduct(product, lastCategory) }; breadcrumbs.Add(breadcrumb); } if (product == null && lastCategory == null) { var currentNode = CurrentPage; foreach (var level in currentNode.Ancestors().Where(IsVisible)) { var breadcrumb = new BreadcrumbsViewModel() { BreadcrumbName = level.Name, BreadcrumbUrl = level.Url }; breadcrumbs.Add(breadcrumb); } var currentBreadcrumb = new BreadcrumbsViewModel() { BreadcrumbName = currentNode.Name, BreadcrumbUrl = currentNode.Url }; breadcrumbs.Add(currentBreadcrumb); } return(View("/Views/PartialView/Breadcrumbs.cshtml", breadcrumbs)); }
/// <summary> /// Initializes the control properties. /// </summary> protected void SetupControl() { if (this.StopProcessing) { // Do not process } else { CategoryNavigationList.InnerHtml = ""; foreach (Category currentCategory in CatalogLibrary.GetRootCategories()) { RecursiveMenu(currentCategory); } } }
public ActionResult Rendering() { var product = _catalogContext.CurrentProduct; var viewModel = new AddToBasketButtonRenderingViewModel { AddToBasketUrl = Url.Action("AddToBasket"), BasketUrl = "/cart", ConfirmationMessageTimeoutInMillisecs = (int)TimeSpan.FromSeconds(5).TotalMilliseconds, ConfirmationMessageClientId = "js-add-to-basket-button-confirmation-message-" + Guid.NewGuid(), ProductSku = product.Sku, IsProductFamily = product.ProductDefinition.IsProductFamily(), Price = CatalogLibrary.CalculatePrice(product).YourPrice.Amount.ToString() }; return(View("/Views/AddToBasketButton/Rendering.cshtml", viewModel)); }
private IList <CategoryViewModel> MapCategories(ICollection <Category> categoriesToMap) { var categoriesToReturn = new List <CategoryViewModel>(); foreach (var category in categoriesToMap) { var categoryViewModel = new CategoryViewModel(); categoryViewModel.Name = category.DisplayName(); categoryViewModel.Url = CatalogLibrary.GetNiceUrlForCategory(category); categoryViewModel.Categories = MapCategories(CatalogLibrary.GetCategories(category)); categoriesToReturn.Add(categoryViewModel); } return(categoriesToReturn); }
public ActionResult Rendering() { var cart = GetCart(); var basketModel = new BasketRenderingViewModel(); var currency = new Currency() { ISOCode = cart.CurrencyCode }; foreach (var cartLine in cart.Lines) { var orderLineViewModel = new BasketRenderingViewModel.OrderlineViewModel(); orderLineViewModel.Quantity = (int)cartLine.Quantity; orderLineViewModel.ProductName = cartLine.Product.ProductName; orderLineViewModel.Sku = cartLine.Product.ProductId; if (cartLine.GetPropertyValue("VariantSku") != null) { orderLineViewModel.VariantSku = cartLine.GetPropertyValue("VariantSku").ToString(); } orderLineViewModel.Total = new Money(cartLine.Total.Amount, currency).ToString(); orderLineViewModel.Discount = new Money(cartLine.Adjustments.Sum(x => x.Amount), currency).Value; if (cartLine.Total.TaxTotal != null) { orderLineViewModel.Tax = new Money(cartLine.Total.TaxTotal.Amount, currency).ToString(); } orderLineViewModel.Price = new Money(cartLine.Product.Price.Amount, currency).ToString(); orderLineViewModel.ProductUrl = CatalogLibrary.GetNiceUrlForProduct(CatalogLibrary.GetProduct(cartLine.Product.ProductId)); orderLineViewModel.PriceWithDiscount = new Money((cartLine.Product.Price.Amount - cartLine.Adjustments.Sum(x => x.Amount)), currency).ToString(); orderLineViewModel.OrderLineId = Convert.ToInt32(cartLine.ExternalCartLineId); basketModel.OrderLines.Add(orderLineViewModel); } basketModel.OrderTotal = new Money(cart.Total.Amount, currency).ToString(); basketModel.DiscountTotal = new Money(cart.Adjustments.Sum(x => x.Amount), currency).ToString(); if (cart.Total.TaxTotal != null) { basketModel.TaxTotal = new Money(cart.Total.TaxTotal.Amount, currency).ToString(); } basketModel.SubTotal = new Money((cart.Total.Amount - cart.Total.TaxTotal.Amount), currency).ToString(); return(View(basketModel)); }
public IHttpActionResult GetProductVariations([FromBody] GetProductVariationsRequest request) { var product = CatalogLibrary.GetProduct(request.ProductSku); var variations = product.Variants.Select(variant => new ProductVariation { Sku = variant.Sku, VariantSku = variant.VariantSku, ProductName = variant.Name, Properties = variant.ProductProperties.Select(prop => new ProductProperty() { Id = prop.Id, Name = prop.ProductDefinitionField.Name, Value = prop.Value }) }).ToList(); return(Json(new { Variations = variations })); }
private IList <ProductDTO> MapProducts(IList <Product> products, Category category, bool openInSamePage, Guid detailPageId) { var result = new List <ProductDTO>(); var imageService = UCommerce.Infrastructure.ObjectFactory.Instance.Resolve <IImageService>(); var currentCatalog = SiteContext.Current.CatalogContext.CurrentCatalog; var productsPrices = CatalogLibrary.CalculatePrice(products.Select(x => x.Guid).ToList()); foreach (var product in products) { var singleProductPrice = productsPrices.Items.Where(x => x.ProductGuid == product.Guid).FirstOrDefault(); decimal price = 0; decimal discount = 0; if (singleProductPrice != null) { price = singleProductPrice.PriceExclTax; discount = singleProductPrice.DiscountExclTax; if (currentCatalog.ShowPricesIncludingVAT) { price = singleProductPrice.PriceInclTax; discount = singleProductPrice.DiscountInclTax; } } var productViewModel = new ProductDTO() { Sku = product.Sku, VariantSku = product.VariantSku, Price = new Money(price, SiteContext.Current.CatalogContext.CurrentPriceGroup.Currency).ToString(), Discount = new Money(discount, SiteContext.Current.CatalogContext.CurrentPriceGroup.Currency).ToString(), DisplayName = product.DisplayName(), ThumbnailImageMediaUrl = imageService.GetImage(product.ThumbnailImageMediaId).Url, ProductUrl = this.GetProductUrl(category, product, openInSamePage, detailPageId), IsSellableProduct = (product.ProductDefinition.IsProductFamily() && product.IsVariant) || (!product.ProductDefinition.IsProductFamily() && !product.IsVariant), }; result.Add(productViewModel); } return(result); }
private List <CategoryNavigationRenderingViewModel.Category> MapCategories(ICollection <UCommerce.EntitiesV2.Category> categoriesToMap) { var categoriesToReturn = new List <CategoryNavigationRenderingViewModel.Category>(); foreach (UCommerce.EntitiesV2.Category category in categoriesToMap) { var categoryToAdd = new CategoryNavigationRenderingViewModel.Category(); categoryToAdd.Name = category.DisplayName(); categoryToAdd.Url = CatalogLibrary.GetNiceUrlForCategory(category); categoryToAdd.Url = _catalogLibraryInternal.GetNiceUrlForCategory(null, category); categoriesToReturn.Add(categoryToAdd); categoryToAdd.Categories = MapCategories(_catalogLibraryInternal.GetCategories(category)); } return(categoriesToReturn); }
// GET: MiniBasket public ActionResult Index() { var miniBasket = new MiniBasketViewModel(); miniBasket.IsEmpty = true; if (TransactionLibrary.HasBasket()) { PurchaseOrder basket = TransactionLibrary.GetBasket(false).PurchaseOrder; var numberOfItems = basket.OrderLines.Sum(x => x.Quantity); if (numberOfItems != 0) { foreach (var orderLine in basket.OrderLines) { var miniOrderLineViewModel = new MiniOrderlineViewModel { Quantity = orderLine.Quantity, ProductName = orderLine.ProductName, Sku = orderLine.Sku, VariantSku = orderLine.VariantSku, Total = new Money(orderLine.Total.GetValueOrDefault(), basket.BillingCurrency).ToString(), Discount = orderLine.Discount, Tax = new Money(orderLine.VAT, basket.BillingCurrency).ToString(), Price = new Money(orderLine.Price, basket.BillingCurrency).ToString(), ProductUrl = CatalogLibrary.GetNiceUrlForProduct(CatalogLibrary.GetProduct(orderLine.Sku)), PriceWithDiscount = new Money(orderLine.Price - orderLine.UnitDiscount.GetValueOrDefault(), basket.BillingCurrency).ToString(), OrderLineId = orderLine.OrderLineId }; miniBasket.MiniOrderlineViewModelCollection.Add(miniOrderLineViewModel); } miniBasket.Total = new Money(basket.OrderTotal.GetValueOrDefault(), basket.BillingCurrency); miniBasket.NumberOfItems = basket.OrderLines.Sum(x => x.Quantity); miniBasket.IsEmpty = false; } } return(View("/Views/PartialView/MiniBasket.cshtml", miniBasket)); }
public virtual CartRenderingViewModel GetViewModel(string refreshUrl, string removeOrderLineUrl) { var basketVM = new CartRenderingViewModel(); if (!_transactionLibraryInternal.HasBasket()) { return(basketVM); } PurchaseOrder basket = _transactionLibraryInternal.GetBasket(false).PurchaseOrder; foreach (var orderLine in basket.OrderLines) { var orderLineViewModel = new OrderlineViewModel { Quantity = orderLine.Quantity, ProductName = orderLine.ProductName, Sku = orderLine.Sku, VariantSku = orderLine.VariantSku, Total = new Money(orderLine.Total.GetValueOrDefault(), basket.BillingCurrency).ToString(), Discount = orderLine.Discount, Tax = new Money(orderLine.VAT, basket.BillingCurrency).ToString(), Price = new Money(orderLine.Price, basket.BillingCurrency).ToString(), ProductUrl = GetProductUrl(CatalogLibrary.GetProduct(orderLine.Sku), this.productDetailsPageId), PriceWithDiscount = new Money(orderLine.Price - orderLine.UnitDiscount.GetValueOrDefault(), basket.BillingCurrency).ToString(), OrderLineId = orderLine.OrderLineId }; basketVM.OrderLines.Add(orderLineViewModel); } basketVM.OrderTotal = new Money(basket.OrderTotal.GetValueOrDefault(), basket.BillingCurrency).ToString(); basketVM.DiscountTotal = new Money(basket.DiscountTotal.GetValueOrDefault(), basket.BillingCurrency).ToString(); basketVM.TaxTotal = new Money(basket.TaxTotal.GetValueOrDefault(), basket.BillingCurrency).ToString(); basketVM.SubTotal = new Money(basket.SubTotal.GetValueOrDefault(), basket.BillingCurrency).ToString(); basketVM.NextStepUrl = GetNextStepUrl(nextStepId); basketVM.RefreshUrl = refreshUrl; basketVM.RemoveOrderlineUrl = removeOrderLineUrl; return(basketVM); }
// GET: HomepageCatalog public ActionResult Index() { var products = SiteContext.Current.CatalogContext.CurrentCatalog.Categories.SelectMany(c => c.Products.Where(p => p.ProductProperties.Any(pp => pp.ProductDefinitionField.Name == "ShowOnHomepage" && Convert.ToBoolean(pp.Value)))); ProductsViewModel productsViewModel = new ProductsViewModel(); foreach (var p in products) { productsViewModel.Products.Add(new ProductViewModel() { Name = p.Name, PriceCalculation = CatalogLibrary.CalculatePrice(p), Url = CatalogLibrary.GetNiceUrlForProduct(p), Sku = p.Sku, IsVariant = p.IsVariant, VariantSku = p.VariantSku, ThumbnailImageUrl = ObjectFactory.Instance.Resolve <IImageService>().GetImage(p.ThumbnailImageMediaId).Url }); } return(View("/Views/PartialView/HomepageCatalog.cshtml", productsViewModel)); }
public SearchResponse(IEnumerable <UCommerce.EntitiesV2.Product> products) { Variations = new List <ProductVariation>(); foreach (var product in products) { Variations.Add(new ProductVariation { Sku = product.Sku, VariantSku = product.VariantSku, ProductName = product.ProductDescriptions.First().DisplayName, Url = CatalogLibrary.GetNiceUrlForProduct(product), Properties = product.ProductProperties.Select(prop => new ProductProperty() { Id = prop.Id, Name = prop.ProductDefinitionField.Name, Value = prop.Value }) }); } }