protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { return; } PurchaseOrder basket = TransactionLibrary.GetBasket(false).PurchaseOrder; Country shippingCountry = TransactionLibrary.GetShippingInformation().Country; var availablePaymentMethods = TransactionLibrary.GetPaymentMethods(shippingCountry); var existingPayment = basket.Payments.FirstOrDefault(); var selectedPaymentMethodId = existingPayment != null ? existingPayment.PaymentMethod.PaymentMethodId : -1; foreach (var availablePaymentMethod in availablePaymentMethods) { var option = new ListItem(); option.Text = availablePaymentMethod.Name; option.Value = availablePaymentMethod.PaymentMethodId.ToString(); option.Selected = availablePaymentMethod.PaymentMethodId == selectedPaymentMethodId; AvailablePaymentMethods.Items.Add(option); } }
public ActionResult Index(AddressDetailsViewModel addressDetails) { var billingDetails = addressDetails.BillingAddress; if (!string.IsNullOrEmpty(billingDetails.FirstName) || !string.IsNullOrEmpty(billingDetails.LastName) || !string.IsNullOrEmpty(billingDetails.EmailAddress) || !string.IsNullOrEmpty(billingDetails.MobilePhoneNumber) || !string.IsNullOrEmpty(billingDetails.Line1)) { if (addressDetails.IsShippingAddressDifferent) { EditBillingInformation(billingDetails); EditShippingInformation(addressDetails.ShippingAddress); } else { EditBillingInformation(billingDetails); EditShippingInformation(billingDetails); } TransactionLibrary.ExecuteBasketPipeline(); var root = UmbracoContext.PublishedContentRequest.PublishedContent.AncestorsOrSelf("homePage").FirstOrDefault(); var shipping = root.Descendants("shipping").FirstOrDefault(); return(Redirect(shipping.Url)); } return(base.View("/Views/BillingShippingAddress.cshtml", addressDetails)); }
protected void RemoveOrderLineButton_OnClick(object sender, EventArgs e) { var orderlineId = Convert.ToInt32((sender as Button).Attributes["Value"]); TransactionLibrary.UpdateLineItem(orderlineId, 0); UCommerce.Api.TransactionLibrary.ExecuteBasketPipeline(); }
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())); }
private void PopulateBillingAddress(IList <Country> countries) { var existingBillingAddress = TransactionLibrary.GetBillingInformation(); billingFirstName.Text = existingBillingAddress.FirstName; billingLastName.Text = existingBillingAddress.LastName; billingEmail.Text = existingBillingAddress.EmailAddress; billingCompany.Text = existingBillingAddress.CompanyName; billingAttention.Text = existingBillingAddress.Attention; billingStreet.Text = existingBillingAddress.Line1; billingStreetTwo.Text = existingBillingAddress.Line2; billingCity.Text = existingBillingAddress.City; billingPostalCode.Text = existingBillingAddress.PostalCode; billingPhone.Text = existingBillingAddress.PhoneNumber; billingMobile.Text = existingBillingAddress.MobilePhoneNumber; billingCountry.DataSource = countries; billingCountry.DataBind(); if (existingBillingAddress.Country != null) { billingCountry.SelectedValue = existingBillingAddress.Country.Id.ToString(); } BillingAddress = existingBillingAddress; }
public IHttpActionResult UpdateLineItem([FromBody] UpdateLineItemRequest request) { TransactionLibrary.UpdateLineItem(request.OrderLineId, request.NewQuantity); TransactionLibrary.ExecuteBasketPipeline(); var orderLine = TransactionLibrary.GetBasket().PurchaseOrder.OrderLines.First(l => l.OrderLineId == request.OrderLineId); var currency = SiteContext.Current.CatalogContext.CurrentCatalog.PriceGroup.Currency; var lineTotal = new Money(orderLine.Total.GetValueOrDefault(), currency); var updatedLine = new LineItem() { OrderLineId = orderLine.OrderLineId, Quantity = orderLine.Quantity, Sku = orderLine.Sku, VariantSku = orderLine.VariantSku, Price = orderLine.Price, ProductName = orderLine.ProductName, Total = orderLine.Total, FormattedTotal = lineTotal.ToString(), UnitDiscount = orderLine.UnitDiscount, VAT = orderLine.VAT, VATRate = orderLine.VATRate }; return(Json(updatedLine)); }
public IHttpActionResult UpdateLineItem(UpdateLineItemDTO model) { TransactionLibrary.UpdateLineItem(model.OrderlineId, model.NewQuantity); TransactionLibrary.ExecuteBasketPipeline(); return(Json(this.GetBasketModel())); }
public ActionResult Index(ShippingViewModel shipping) { TransactionLibrary.CreateShipment(shipping.SelectedShippingMethodId, overwriteExisting: true); TransactionLibrary.ExecuteBasketPipeline(); return(Redirect("/store/payment")); }
public ActionResult Index() { var shippingModel = new ShippingViewModel(); shippingModel.AvailableShippingMethods = new List <SelectListItem>(); var shippingCountry = TransactionLibrary.GetShippingInformation().Country; var availableShippingMethods = TransactionLibrary.GetShippingMethods(shippingCountry); var selectedShipping = TransactionLibrary.GetBasket(false).PurchaseOrder.Shipments.FirstOrDefault(); foreach (var availableShippingMethod in availableShippingMethods) { shippingModel.AvailableShippingMethods.Add(new SelectListItem() { Selected = selectedShipping != null && selectedShipping.ShippingMethod.ShippingMethodId == availableShippingMethod.ShippingMethodId, Text = availableShippingMethod.Name, Value = availableShippingMethod.ShippingMethodId.ToString() }); } return(View("/Views/Shipping.cshtml", shippingModel)); }
private PurchaseOrderViewModel MapOrder() { var basket = TransactionLibrary.GetBasket(false).PurchaseOrder; var basketModel = new PurchaseOrderViewModel(); basketModel.OrderTotal = new Money(basket.OrderTotal.GetValueOrDefault(), basket.BillingCurrency).ToString(); basketModel.SubTotal = new Money(basket.SubTotal.GetValueOrDefault(), basket.BillingCurrency).ToString(); basketModel.ShippingTotal = new Money(basket.ShippingTotal.GetValueOrDefault(), basket.BillingCurrency).ToString(); basketModel.PaymentTotal = new Money(basket.PaymentTotal.GetValueOrDefault(), basket.BillingCurrency).ToString(); basketModel.DiscountTotal = new Money(basket.DiscountTotal.GetValueOrDefault(), basket.BillingCurrency).ToString(); basketModel.TaxTotal = new Money(basket.TaxTotal.GetValueOrDefault(), basket.BillingCurrency).ToString(); foreach (var orderLine in basket.OrderLines) { basketModel.OrderLines.Add(new OrderlineViewModel() { OrderLineId = orderLine.OrderLineId, ProductName = orderLine.ProductName, Sku = orderLine.Sku, VariantSku = orderLine.VariantSku, Quantity = orderLine.Quantity, Total = new Money(orderLine.Total.GetValueOrDefault(), basket.BillingCurrency).ToString() }); } return(basketModel); }
private void SetupPaymentMethods(List <PaymentMethod> billingMethods) { var basket = TransactionLibrary.GetBasket().PurchaseOrder; var existingPayment = basket.Payments.FirstOrDefault(); var selectedPaymentMethodId = existingPayment != null ? existingPayment.PaymentMethod.PaymentMethodId : -1; foreach (PaymentMethod paymentMethod in billingMethods) { var feePercent = paymentMethod.FeePercent; var fee = paymentMethod.GetFeeForCurrency(basket.BillingCurrency); var formattedFee = new Money(fee == null ? 0 : fee.Fee, basket.BillingCurrency); string paymentMethodText = $"{paymentMethod.Name} ({formattedFee} + {feePercent:0.00}%)"; ListItem currentListItem = new ListItem(paymentMethodText, paymentMethod.Id.ToString()) { Selected = paymentMethod.PaymentMethodId == selectedPaymentMethodId }; rblPaymentMethods.Items.Add(currentListItem); } if (rblPaymentMethods.SelectedIndex == -1) { rblPaymentMethods.SelectedIndex = 0; } }
public override ActionResult Index(RenderModel model) { var shipping = new ShippingViewModel(); shipping.AvailableShippingMethods = new List <SelectListItem>(); var shippingInformation = TransactionLibrary.GetShippingInformation(); var availableShippingMethods = TransactionLibrary.GetShippingMethods(shippingInformation.Country); var basket = TransactionLibrary.GetBasket().PurchaseOrder; shipping.SelectedShippingMethodId = basket.Shipments.FirstOrDefault() != null ? basket.Shipments.FirstOrDefault().ShippingMethod.ShippingMethodId : -1; foreach (var availableShippingMethod in availableShippingMethods) { var price = availableShippingMethod.GetPriceForCurrency(basket.BillingCurrency); var formattedprice = new Money((price == null ? 0 : price.Price), basket.BillingCurrency); shipping.AvailableShippingMethods.Add(new SelectListItem() { Selected = shipping.SelectedShippingMethodId == availableShippingMethod.ShippingMethodId, Text = String.Format(" {0} ({1})", availableShippingMethod.Name, formattedprice), Value = availableShippingMethod.ShippingMethodId.ToString() }); } shipping.ShippingCountry = shippingInformation.Country.Name; return(base.View("/Views/Shipping.cshtml", shipping)); }
protected void Page_Load(object sender, EventArgs e) { PurchaseOrderModel model = MapOrder(); model.BillingAddress = MapOrderAddress(TransactionLibrary.GetBillingInformation()); model.ShippingAddress = MapOrderAddress(TransactionLibrary.GetShippingInformation()); var basket = UCommerce.Api.TransactionLibrary.GetBasket(false).PurchaseOrder; var billingCurrency = basket.BillingCurrency; foreach (var basketOrderLine in basket.OrderLines) { var orderLineModel = new OrderlineModel(); orderLineModel.Sku = basketOrderLine.Sku; orderLineModel.VariantSku = basketOrderLine.VariantSku; orderLineModel.ProductName = basketOrderLine.ProductName; orderLineModel.Quantity = basketOrderLine.Quantity; orderLineModel.Total = new UCommerce.Money(basketOrderLine.Total.GetValueOrDefault(), billingCurrency).ToString(); model.OrderLines.Add(orderLineModel); } model.SubTotal = GetMoneyFormat(basket.SubTotal.GetValueOrDefault(), billingCurrency); model.TaxTotal = GetMoneyFormat(basket.TaxTotal.GetValueOrDefault(), billingCurrency); model.DiscountTotal = GetMoneyFormat(basket.DiscountTotal.GetValueOrDefault(), billingCurrency); model.ShippingTotal = GetMoneyFormat(basket.ShippingTotal.GetValueOrDefault(), billingCurrency); model.PaymentTotal = GetMoneyFormat(basket.PaymentTotal.GetValueOrDefault(), billingCurrency); model.OrderTotal = GetMoneyFormat(basket.OrderTotal.GetValueOrDefault(), billingCurrency); BuildPage(model); }
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 Index() { var paymentViewModel = new PaymentViewModel(); PurchaseOrder basket = TransactionLibrary.GetBasket(false).PurchaseOrder; Country shippingCountry = TransactionLibrary.GetShippingInformation().Country; var availablePaymentMethods = TransactionLibrary.GetPaymentMethods(shippingCountry); var existingPayment = basket.Payments.FirstOrDefault(); paymentViewModel.SelectedPaymentMethodId = existingPayment != null ? existingPayment.PaymentMethod.PaymentMethodId : -1; foreach (var availablePaymentMethod in availablePaymentMethods) { var option = new SelectListItem(); option.Text = availablePaymentMethod.Name; option.Value = availablePaymentMethod.PaymentMethodId.ToString(); option.Selected = availablePaymentMethod.PaymentMethodId == paymentViewModel.SelectedPaymentMethodId; paymentViewModel.AvailablePaymentMethods.Add(option); } return(View("/Views/mc/Payment.cshtml", paymentViewModel)); }
public IHttpActionResult AddVoucher(AddVoucherDTO model) { var voucherAdded = MarketingLibrary.AddVoucher(model.VoucherCode); TransactionLibrary.ExecuteBasketPipeline(); return(Json(this.GetBasketModel())); }
protected void UseVoucher(object sender, EventArgs e) { MarketingLibrary.AddVoucher(txtVoucherCode.Value); TransactionLibrary.ExecuteBasketPipeline(); Response.Redirect(Request.RawUrl); }
protected override object Run(UpdateLineItem request) { TransactionLibrary.UpdateLineItem(request.OrderLineId, request.NewQuantity); TransactionLibrary.ExecuteBasketPipeline(); var newLine = TransactionLibrary.GetBasket().PurchaseOrder.OrderLines.FirstOrDefault(l => l.OrderLineId == request.OrderLineId); return(new UpdateLineItemResponse(newLine)); }
public ActionResult Index(AddToBasketViewModel model) { string variant = GetVariantFromPostData(model.Sku, "variation-"); TransactionLibrary.AddToBasket(1, model.Sku, variant); return(RenderView(true)); }
protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { return; } var addressDetails = new AddressDetailsModel(); var shippingInformation = TransactionLibrary.GetShippingInformation(); var billingInformation = TransactionLibrary.GetBillingInformation(); BillingAddressFirstName.Text = billingInformation.FirstName; BillingAddressLastName.Text = billingInformation.LastName; BillingAddressEmailAddress.Text = billingInformation.EmailAddress; BillingAddressPhoneNumber.Text = billingInformation.PhoneNumber; BillingAddressMobilePhoneNumber.Text = billingInformation.MobilePhoneNumber; BillingAddressLine1.Text = billingInformation.Line1; BillingAddressLine2.Text = billingInformation.Line2; BillingAddressPostalCode.Text = billingInformation.PostalCode; BillingAddressCity.Text = billingInformation.City; BillingAddressAttention.Text = billingInformation.Attention; BillingAddressCompanyName.Text = billingInformation.CompanyName; var billingAddressCountryId = billingInformation.Country != null ? billingInformation.Country.CountryId : -1; ShippingAddressFirstName.Text = shippingInformation.FirstName; ShippingAddressLastName.Text = shippingInformation.LastName; ShippingAddressEmailAddress.Text = shippingInformation.EmailAddress; ShippingAddressPhoneNumber.Text = shippingInformation.PhoneNumber; ShippingAddressMobilePhoneNumber.Text = shippingInformation.MobilePhoneNumber; ShippingAddressLine1.Text = shippingInformation.Line1; ShippingAddressLine2.Text = shippingInformation.Line2; ShippingAddressPostalCode.Text = shippingInformation.PostalCode; ShippingAddressCity.Text = shippingInformation.City; ShippingAddressAttention.Text = shippingInformation.Attention; ShippingAddressCompanyName.Text = shippingInformation.CompanyName; var shippingAddressCountryId = shippingInformation.Country != null ? shippingInformation.Country.CountryId : -1; addressDetails.AvailableCountries = UCommerce.EntitiesV2.Country.All().ToList().Select(x => new ListItem() { Text = x.Name, Value = x.CountryId.ToString() }).ToList(); BillingAddressCountryDropDown.ClearSelection(); ShippingAddressCountryDropDown.ClearSelection(); foreach (var country in addressDetails.AvailableCountries) { var shippingCountryIsSelected = shippingAddressCountryId.ToString() == country.Value; var billingCountryIsSelected = billingAddressCountryId.ToString() == country.Value; ShippingAddressCountryDropDown.Items.Add(new ListItem { Text = country.Text, Value = country.Value, Selected = shippingCountryIsSelected }); BillingAddressCountryDropDown.Items.Add(new ListItem { Text = country.Text, Value = country.Value, Selected = billingCountryIsSelected }); } }
public void GetAllProducts_EmptyProductList_ReturnsEmptyList() { TransactionLibrary library = new TransactionLibrary(); List <Transaction> transactions = new List <Transaction>(); IEnumerable <Transaction> result = library.GetAllTransactions(new EnumerableQuery <Transaction>(transactions)); Assert.IsTrue(!result.Any()); }
public ActionResult Index() { PurchaseOrderViewModel model = MapOrder(); model.BillingAddress = MapOrderAddress(TransactionLibrary.GetBillingInformation()); model.ShippingAddress = MapOrderAddress(TransactionLibrary.GetShippingInformation()); return(View("/Views/mc/preview.cshtml", model)); }
public ActionResult Index() { TransactionLibrary.RequestPayments(); var root = UmbracoContext.PublishedContentRequest.PublishedContent.AncestorsOrSelf("home").FirstOrDefault(); var confirmation = root.Descendants("confirmation").FirstOrDefault(); return(Redirect(confirmation.Url)); }
public ActionResult Index() { BasketViewModel model = MapOrder(); model.BillingAddress = MapOrderAddress(TransactionLibrary.GetBillingInformation()); model.ShippingAddress = MapOrderAddress(TransactionLibrary.GetShippingInformation()); return(View(model)); }
public IHttpActionResult GetBasket() { if (!TransactionLibrary.HasBasket()) { return(Json(new BasketDTO())); } return(Json(this.GetBasketModel())); }
public ActionResult Index() { TransactionLibrary.RequestPayments(); var parent = PublishedRequest.PublishedContent.AncestorOrSelf("basket"); var confirmation = parent.Children(x => x.Name == "Confirmation").FirstOrDefault(); return(Redirect(confirmation.Url)); }
public ActionResult Index(ShippingViewModel shipping) { TransactionLibrary.CreateShipment(shipping.SelectedShippingMethodId, overwriteExisting: true); TransactionLibrary.ExecuteBasketPipeline(); var root = UmbracoContext.PublishedContentRequest.PublishedContent.AncestorsOrSelf("home").FirstOrDefault(); var payment = root.Descendants("payment").FirstOrDefault(); return(Redirect(payment.Url)); }
private ReadOnlyCollection <global::Sitecore.Commerce.Entities.Shipping.ShippingMethod> GetCommerceConnectShippingMethods(Country country) { var mapper = ObjectFactory.Instance.Resolve <IMapping <ShippingMethod, global::Sitecore.Commerce.Entities.Shipping.ShippingMethod> >("ShippingMethodToShippingMethod"); var shippingMethods = country == null?TransactionLibrary.GetShippingMethods() : TransactionLibrary.GetShippingMethods(country); IList <global::Sitecore.Commerce.Entities.Shipping.ShippingMethod> cCshippingMethods = shippingMethods.Select(shippingMethod => mapper.Map(shippingMethod)).ToList(); return(new ReadOnlyCollection <global::Sitecore.Commerce.Entities.Shipping.ShippingMethod>(cCshippingMethods)); }
public ActionResult Index(ShippingViewModel shipping) { TransactionLibrary.CreateShipment(shipping.SelectedShippingMethodId, overwriteExisting: true); TransactionLibrary.ExecuteBasketPipeline(); var parent = PublishedRequest.PublishedContent.AncestorOrSelf("basket"); var payment = parent.Children(x => x.Name == "Payment").FirstOrDefault(); return(Redirect(payment.Url)); }
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 })); }