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 IHttpActionResult GetVariantSkuFromSelectionRequest([FromBody] GetVariantSkuFromSelectionRequest request) { var product = CatalogLibrary.GetProduct(request.ProductSku); UCommerce.EntitiesV2.Product variant = null; if (product.Variants.Any() && request.VariantProperties.Any()) // If there are variant values we'll need to find the selected variant { variant = product.Variants.FirstOrDefault(v => v.ProductProperties.Where(pp => pp.ProductDefinitionField.DisplayOnSite && pp.ProductDefinitionField.IsVariantProperty && !pp.ProductDefinitionField.Deleted && pp.Value != null && pp.Value != String.Empty).All(p => request.VariantProperties.Any(kv => kv.Key.Equals(p.ProductDefinitionField.Name, StringComparison.InvariantCultureIgnoreCase) && kv.Value.ToString().Equals(p.Value, StringComparison.InvariantCultureIgnoreCase)))); } else if (!product.Variants.Any()) // Only use the current product where there are no variants { variant = product; } var variantModel = 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 }) }; return(Json(new { Variant = variantModel })); }
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.Discount, 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)); }
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)); }
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 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 })); }
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: 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)); }
protected override object Run(GetProductVariations request) { var product = CatalogLibrary.GetProduct(request.ProductSku); return(new GetProductVariationsResponse(product)); }
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 GetVariantSkuFromSelectionResponse Post(GetVariantSkuFromSelection request) { var product = CatalogLibrary.GetProduct(request.ProductSku); return(new GetVariantSkuFromSelectionResponse(product, request.VariantProperties)); }
public void CartRepeaterItemDataBound(object sender, RepeaterItemEventArgs e) { bool orderlinePrice = ValidationHelper.GetBoolean(GetValue("OrderlinePrice"), true); bool orderlineVat = ValidationHelper.GetBoolean(GetValue("OrderlineVAT"), true); bool orderlineQuantity = ValidationHelper.GetBoolean(GetValue("OrderlineQuantity"), true); bool orderlineItemNo = ValidationHelper.GetBoolean(GetValue("OrderlineItemNo"), true); bool editable = ValidationHelper.GetBoolean(GetValue("Editable"), true); if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem) { return; } Currency currency = TransactionLibrary.GetBasket(true).PurchaseOrder.BillingCurrency; OrderLine currentItem = (OrderLine)e.Item.DataItem; var product = CatalogLibrary.GetProduct(currentItem.Sku); var itemPrice = new Money(currentItem.Price, currency); var itemTax = new Money(currentItem.VAT, currency); var lineTotal = new Money(currentItem.Total.Value, currency); var lnkItemLink = (HyperLink)e.Item.FindControl("lnkItemLink"); var litPrice = (Literal)e.Item.FindControl("litPrice"); var litVat = (Literal)e.Item.FindControl("litVat"); var litTotal = (Literal)e.Item.FindControl("litTotal"); var txtQuantity = (TextBox)e.Item.FindControl("txtQuantity"); var btnUpdateQuantities = (Button)e.Item.FindControl("btnUpdateQuantities"); var btnRemoveLine = (Button)e.Item.FindControl("btnRemoveLine"); var lblQuantity = (Label)e.Item.FindControl("lblQuantity"); var litItemNo = (Literal)e.Item.FindControl("litItemNo"); string url = CatalogLibrary.GetNiceUrlForProduct(product, product.GetCategories().FirstOrDefault()); lnkItemLink.Text = currentItem.ProductName; lnkItemLink.NavigateUrl = url; if (currentItem.UnitDiscount.HasValue && currentItem.UnitDiscount > 0) { var nowPrice = new Money((currentItem.Price - currentItem.UnitDiscount.Value), currency); litPrice.Text = "<span style=\"text-decoration: line-through\">" + itemPrice + "</span>" + nowPrice; } else { litPrice.Text = itemPrice.ToString(); } litVat.Text = itemTax.ToString(); litTotal.Text = lineTotal.ToString(); txtQuantity.Text = currentItem.Quantity.ToString(); txtQuantity.Attributes.Add("orderlinenumber", _currentIteration.ToString()); btnUpdateQuantities.Attributes.Add("orderlinenumber", _currentIteration.ToString()); btnRemoveLine.Attributes.Add("orderlinenumber", _currentIteration.ToString()); btnUpdateQuantities.ID = "btnUpdateQuantities" + _currentIteration; txtQuantity.ID = "txtQuantity" + _currentIteration; txtQuantity.Attributes.Add("data-orderlineid", currentItem.OrderLineId.ToString()); litPrice.Visible = orderlinePrice; litVat.Visible = orderlineVat; txtQuantity.Visible = orderlineQuantity; btnUpdateQuantities.Visible = orderlineQuantity; litItemNo.Text = currentItem.Sku; litItemNo.Visible = orderlineItemNo; if (!editable) { btnRemoveLine.Visible = false; btnUpdateQuantities.Visible = false; txtQuantity.Attributes.Add("readonly", "true"); txtQuantity.CssClass += " textbox-to-label"; } _currentIteration++; }
public IHttpActionResult GetProductInformation([FromBody] GetProductInformationRequest request) { ProductCatalog catalog = CatalogLibrary.GetCatalog(request.CatalogId); Product product = CatalogLibrary.GetProduct(request.Sku); Category category = CatalogLibrary.GetCategory(request.CategoryId.Value); string niceUrl = CatalogLibrary.GetNiceUrlForProduct(product, category, catalog); PriceCalculation priceCalculation = CatalogLibrary.CalculatePrice(product); Currency currency = priceCalculation.YourPrice.Amount.Currency; ProductInformation productInformation = new ProductInformation() { NiceUrl = niceUrl, PriceCalculation = new PriceCalculationViewModel() { Discount = new PriceViewModel() { Amount = new MoneyViewModel() { Value = priceCalculation.Discount.Amount.Value, DisplayValue = new Money(priceCalculation.Discount.Amount.Value, currency).ToString() }, AmountExclTax = new MoneyViewModel() { Value = priceCalculation.Discount.AmountExclTax.Value, DisplayValue = new Money(priceCalculation.Discount.AmountExclTax.Value, currency).ToString() }, AmountInclTax = new MoneyViewModel() { Value = priceCalculation.Discount.AmountInclTax.Value, DisplayValue = new Money(priceCalculation.Discount.AmountInclTax.Value, currency).ToString() } }, IsDiscounted = priceCalculation.IsDiscounted, YourPrice = new PriceViewModel() { Amount = new MoneyViewModel() { Value = priceCalculation.YourPrice.Amount.Value, DisplayValue = new Money(priceCalculation.YourPrice.Amount.Value, currency).ToString() }, AmountInclTax = new MoneyViewModel() { Value = priceCalculation.YourPrice.AmountInclTax.Value, DisplayValue = new Money(priceCalculation.YourPrice.AmountInclTax.Value, currency).ToString() }, AmountExclTax = new MoneyViewModel() { Value = priceCalculation.YourPrice.AmountExclTax.Value, DisplayValue = new Money(priceCalculation.YourPrice.AmountExclTax.Value, currency).ToString() } }, ListPrice = new PriceViewModel() { Amount = new MoneyViewModel() { Value = priceCalculation.ListPrice.Amount.Value, DisplayValue = new Money(priceCalculation.ListPrice.Amount.Value, currency).ToString() }, AmountExclTax = new MoneyViewModel() { Value = priceCalculation.ListPrice.AmountExclTax.Value, DisplayValue = new Money(priceCalculation.ListPrice.AmountExclTax.Value, currency).ToString() }, AmountInclTax = new MoneyViewModel() { Value = priceCalculation.ListPrice.AmountInclTax.Value, DisplayValue = new Money(priceCalculation.ListPrice.AmountInclTax.Value, currency).ToString() } } } }; productInformation.Sku = product.Sku; return(Json(productInformation)); }
protected override object Run(GetVariantSkuFromSelection request) { var product = CatalogLibrary.GetProduct(request.ProductSku); return(new GetVariantSkuFromSelectionResponse(product, request.VariantProperties)); }
public ActionResult Rendering() { var basketModel = new BasketRenderingViewModel(); if (!_transactionLibraryInternal.HasBasket()) { return(View(basketModel)); } PurchaseOrder basket = _transactionLibraryInternal.GetBasket(false).PurchaseOrder; foreach (var orderLine in basket.OrderLines) { var orderLineViewModel = new BasketRenderingViewModel.OrderlineViewModel(); orderLineViewModel.Quantity = orderLine.Quantity; orderLineViewModel.ProductName = orderLine.ProductName; orderLineViewModel.Sku = orderLine.Sku; orderLineViewModel.VariantSku = orderLine.VariantSku; orderLineViewModel.Total = new Money(orderLine.Total.GetValueOrDefault(), basket.BillingCurrency).ToString(); orderLineViewModel.Discount = orderLine.Discount; orderLineViewModel.Tax = new Money(orderLine.VAT, basket.BillingCurrency).ToString(); orderLineViewModel.Price = new Money(orderLine.Price, basket.BillingCurrency).ToString(); orderLineViewModel.ProductUrl = CatalogLibrary.GetNiceUrlForProduct(CatalogLibrary.GetProduct(orderLine.Sku)); orderLineViewModel.PriceWithDiscount = new Money(orderLine.Price - orderLine.UnitDiscount.GetValueOrDefault(), basket.BillingCurrency).ToString(); orderLineViewModel.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(); basketModel.RefreshUrl = Url.Action("UpdateBasket"); basketModel.RemoveOrderlineUrl = Url.Action("RemoveOrderline"); return(View(basketModel)); }
public GetProductVariationsResponse Post(GetProductVariations request) { var product = CatalogLibrary.GetProduct(request.ProductSku); return(new GetProductVariationsResponse(product)); }