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));
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
        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 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));
        }
Exemplo n.º 6
0
    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;
        }
    }
Exemplo n.º 7
0
        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));
        }
        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);
        }
Exemplo n.º 9
0
        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));
        }
Exemplo n.º 10
0
        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 }));
        }
Exemplo n.º 11
0
        public ActionResult Rendering()
        {
            var basketPreviewViewModel = new BasketPreviewViewModel();

            //used to grap addresses
            var purchaseOrder = TransactionLibrary.GetBasket(false).PurchaseOrder;

            var cart = GetCart();

            basketPreviewViewModel = MapPurchaseOrderToViewModel(purchaseOrder, cart, basketPreviewViewModel);

            return(View(basketPreviewViewModel));
        }
Exemplo n.º 12
0
        public void btnContinue_Click(object sender, EventArgs e)
        {
            var payment = TransactionLibrary.GetBasket().PurchaseOrder.Payments.First();

            if (payment.PaymentMethod.PaymentMethodServiceName == null)
            {
                HttpContext.Current.Response.Redirect("~/Basket/Confirmation");
            }

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            string paymentUrl = TransactionLibrary.GetPaymentPageUrl(payment);

            HttpContext.Current.Response.Redirect(paymentUrl);
        }
Exemplo n.º 13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                return;
            }

            var basket        = TransactionLibrary.GetBasket().PurchaseOrder;
            var firstShipment = basket.Shipments.First();

            var shippingMethods = TransactionLibrary.GetShippingMethods(firstShipment.ShipmentAddress.Country);

            AvailableShipmentMethods.DataSource = shippingMethods;
            AvailableShipmentMethods.DataBind();
        }
        public ActionResult Index()
        {
            var payment = TransactionLibrary.GetBasket().PurchaseOrder.Payments.First();

            if (payment.PaymentMethod.PaymentMethodServiceName == null)
            {
                var root         = UmbracoContext.PublishedContentRequest.PublishedContent.AncestorsOrSelf("homePage").FirstOrDefault();
                var confirmation = root.Descendants("confirmation").FirstOrDefault();
                return(Redirect(confirmation.Url));
            }

            string paymentUrl = TransactionLibrary.GetPaymentPageUrl(payment);

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            return(Redirect(paymentUrl));
        }
    private void SetupShippingMethods(List <ShippingMethod> shippingMethods)
    {
        var currentShippingMethod = TransactionLibrary.GetShippingMethod();
        var currentBasket         = TransactionLibrary.GetBasket().PurchaseOrder;

        foreach (ShippingMethod shippingMethod in shippingMethods)
        {
            var price          = shippingMethod.GetPriceForCurrency(currentBasket.BillingCurrency);
            var formattedPrice = new Money((price == null ? 0 : price.Price), currentBasket.BillingCurrency);

            ListItem currentListItem = new ListItem($"{shippingMethod.Name} ({formattedPrice})", shippingMethod.Id.ToString());
            currentListItem.Selected = currentShippingMethod.Id == shippingMethod.Id;

            rblShippingMethods.Items.Add(currentListItem);
        }
    }
Exemplo n.º 16
0
        public int GetBasketCount()
        {
            int count = 0;

            try
            {
                var basket = TransactionLibrary.GetBasket();

                foreach (var purchaseOrderOrderLine in basket.PurchaseOrder.OrderLines)
                {
                    count += purchaseOrderOrderLine.Quantity;
                }
            }
            catch (Exception ex)
            {
            }
            return(count);
        }
Exemplo n.º 17
0
// 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)
                {
                    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 override ActionResult Index(ContentModel model)
        {
            var paymentViewModel = new PaymentViewModel();

            paymentViewModel.AvailablePaymentMethods = new List <SelectListItem>();

            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();
                decimal feePercent   = availablePaymentMethod.FeePercent;
                var     fee          = availablePaymentMethod.GetFeeForCurrency(basket.BillingCurrency);
                var     formattedFee = new Money((fee == null ? 0 : fee.Fee), basket.BillingCurrency);

                option.Text = String.Format(" {0} ({1} + {2}%)", availablePaymentMethod.Name, formattedFee,
                                            feePercent.ToString("0.00"));
                option.Value    = availablePaymentMethod.PaymentMethodId.ToString();
                option.Selected = availablePaymentMethod.PaymentMethodId == paymentViewModel.SelectedPaymentMethodId;

                paymentViewModel.AvailablePaymentMethods.Add(option);
            }

            if (paymentViewModel.AvailablePaymentMethods.Any() && paymentViewModel.AvailablePaymentMethods.All(x => !x.Selected))
            {
                // Always make sure, that one payment method is selected.
                paymentViewModel.AvailablePaymentMethods.First().Selected = true;
            }

            paymentViewModel.ShippingCountry = shippingCountry.Name;

            return(View("/Views/Payment.cshtml", paymentViewModel));
        }
    public static bool?UpdateCartLine(string lineNumberString, string quantityString)
    {
        var basket     = TransactionLibrary.GetBasket().PurchaseOrder;
        int lineNumber = 0;
        int quantity   = 0;

        if (!Int32.TryParse(lineNumberString, out lineNumber) || !Int32.TryParse(quantityString, out quantity))
        {
            //if we cant parse the input to ints, we cant go on
            return(false);
        }

        var listOfOrderLineIds = basket.OrderLines.Select(x => x.OrderLineId).ToList();
        var currentOrderLineId = listOfOrderLineIds[lineNumber];

        TransactionLibrary.UpdateLineItem(currentOrderLineId, quantity);

        TransactionLibrary.ExecuteBasketPipeline();
        return(true);
    }
        public ActionResult Index()
        {
            if (!TransactionLibrary.HasBasket())
            {
                return(View(new MiniBasketModel()
                {
                    HasBasket = false
                }));
            }
            ;

            var basket = TransactionLibrary.GetBasket(false).PurchaseOrder;

            return(View(new MiniBasketModel()
            {
                HasBasket = true,
                NumberOfItemsInBasket = basket.OrderLines.Sum(x => x.Quantity),
                OrderTotal = new Money(basket.OrderTotal.GetValueOrDefault(), basket.BillingCurrency).ToString()
            }));
        }
Exemplo n.º 21
0
// 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));
        }
Exemplo n.º 22
0
        protected void UpdateBasketButton_OnClick(object sender, EventArgs e)
        {
            var basket = TransactionLibrary.GetBasket().PurchaseOrder;

            foreach (RepeaterItem item in OrderLinesRepeater.Items)
            {
                var orderlineIdHidden = item.FindControl("OrderLineId") as HiddenField;
                int orderlineId       = Convert.ToInt32(orderlineIdHidden.Value);

                var quantityTextBox = item.FindControl("OrderLineQuantity") as TextBox;
                int quantity        = Convert.ToInt32(quantityTextBox.Text);

                UCommerce.Api.TransactionLibrary.UpdateLineItem(orderlineId, quantity);
            }
            UCommerce.Api.TransactionLibrary.ExecuteBasketPipeline();
            basket = TransactionLibrary.GetBasket().PurchaseOrder;

            PurchaseOrderModel basketModel = MapBasket(basket);

            BuildPage(basketModel);
        }
        private ActionResult RenderView(bool addedToBasket)
        {
            Product currentProduct = SiteContext.Current.CatalogContext.CurrentProduct;

            var productViewModel = new ProductViewModel();

            productViewModel.Sku = currentProduct.Sku;
            productViewModel.PriceCalculation  = UCommerce.Api.CatalogLibrary.CalculatePrice(currentProduct);
            productViewModel.Name              = currentProduct.DisplayName();
            productViewModel.LongDescription   = currentProduct.LongDescription();
            productViewModel.IsVariant         = false;
            productViewModel.IsOrderingAllowed = currentProduct.AllowOrdering;
            productViewModel.TaxCalculation    = CatalogLibrary.CalculatePrice(currentProduct).YourTax.ToString();
            productViewModel.IsProductFamily   = currentProduct.ProductDefinition.IsProductFamily();
            productViewModel.Reviews           = MapReviews(currentProduct);

            if (!string.IsNullOrEmpty(currentProduct.PrimaryImageMediaId))
            {
                var media = ObjectFactory.Instance.Resolve <IImageService>().GetImage(currentProduct.PrimaryImageMediaId).Url;
                productViewModel.ThumbnailImageUrl = media;
            }

            productViewModel.Properties = MapProductProperties(currentProduct);

            if (currentProduct.ProductDefinition.IsProductFamily())
            {
                productViewModel.Variants = MapVariants(currentProduct.Variants);
            }

            bool isInBasket = TransactionLibrary.GetBasket(true).PurchaseOrder.OrderLines.Any(x => x.Sku == currentProduct.Sku);

            ProductPageViewModel productPageViewModel = new ProductPageViewModel()
            {
                ProductViewModel  = productViewModel,
                AddedToBasket     = addedToBasket,
                ItemAlreadyExists = isInBasket
            };

            return(View("/Views/Product.cshtml", productPageViewModel));
        }
        private BasketDTO GetBasketModel()
        {
            var model        = new BasketDTO();
            var basket       = TransactionLibrary.GetBasket(false).PurchaseOrder;
            var imageService = ObjectFactory.Instance.Resolve <IImageService>();
            var urlService   = ObjectFactory.Instance.Resolve <IUrlService>();

            foreach (var orderLine in basket.OrderLines)
            {
                var orderLineModel = this.MapOrderLine(orderLine);
                var currentCatalog = SiteContext.Current.CatalogContext.CurrentCatalog;
                orderLineModel.ProductUrl = urlService.GetUrl(currentCatalog, Product.FirstOrDefault(x => x.Sku == orderLine.Sku));

                orderLineModel.ThumbnailImageMediaUrl = imageService
                                                        .GetImage(Product.FirstOrDefault(x => x.Sku == orderLine.Sku).ThumbnailImageMediaId).Url;

                model.OrderLines.Add(orderLineModel);
            }

            foreach (var discount in basket.Discounts)
            {
                model.Discounts.Add(new DiscountDTO
                {
                    Name  = discount.CampaignItemName,
                    Value = new Money(discount.AmountOffTotal, basket.BillingCurrency).ToString(),
                });
            }

            model.OrderTotal            = new Money(basket.OrderTotal.GetValueOrDefault(), basket.BillingCurrency).ToString();
            model.TaxTotal              = new Money(basket.TaxTotal.GetValueOrDefault(), basket.BillingCurrency).ToString();
            model.DiscountTotal         = new Money(basket.DiscountTotal.GetValueOrDefault(), basket.BillingCurrency).ToString();
            model.HasDiscount           = basket.Discount.GetValueOrDefault() > 0;
            model.NumberOfItemsInBasket = basket.OrderLines.Sum(x => x.Quantity);
            model.ShippingTotal         =
                new Money(basket.ShippingTotal.GetValueOrDefault(), basket.BillingCurrency).ToString();
            model.PaymentTotal = new Money(basket.PaymentTotal.GetValueOrDefault(), basket.BillingCurrency).ToString();

            return(model);
        }
Exemplo n.º 25
0
        public IHttpActionResult PutProductReview([FromBody] ProductReviewDTO model)
        {
            var product = Product.FirstOrDefault(x => x.Sku == model.Sku && x.VariantSku == null);
            var request = System.Web.HttpContext.Current.Request;
            var basket  = TransactionLibrary.HasBasket() ? TransactionLibrary.GetBasket(false) : null;

            if (basket != null)
            {
                if (basket.PurchaseOrder.Customer == null)
                {
                    basket.PurchaseOrder.Customer = new Customer()
                    {
                        FirstName = model.Name, LastName = string.Empty, EmailAddress = model.Email
                    };
                    basket.Save();
                }
            }

            var review = new ProductReview()
            {
                ProductCatalogGroup = SiteContext.Current.CatalogContext.CurrentCatalogGroup,
                ProductReviewStatus = ProductReviewStatus.SingleOrDefault(s => s.Name == "New"),
                CreatedOn           = DateTime.Now,
                CreatedBy           = model.Name,
                Product             = product,
                Customer            = basket?.PurchaseOrder?.Customer,
                Rating         = model.Rating,
                ReviewHeadline = model.Title,
                ReviewText     = model.Comments,
                Ip             = request.UserHostName,
            };

            product.AddProductReview(review);

            PipelineFactory.Create <ProductReview>("ProductReview").Execute(review);

            return(Ok());
        }
        private PurchaseOrderViewModel MapBasket()
        {
            UCommerce.EntitiesV2.PurchaseOrder uCommerceOrder = TransactionLibrary.GetBasket(false).PurchaseOrder;
            var basketModel = new PurchaseOrderViewModel();

            basketModel.OrderTotal = new UCommerce.Money(uCommerceOrder.OrderTotal.GetValueOrDefault(), uCommerceOrder.BillingCurrency).ToString();

            foreach (var uCOmmerceOrderLine in uCommerceOrder.OrderLines)
            {
                basketModel.OrderLines.Add(new OrderlineViewModel()
                {
                    OrderLineId = uCOmmerceOrderLine.OrderLineId,
                    ProductName = uCOmmerceOrderLine.ProductName,
                    Quantity    = uCOmmerceOrderLine.Quantity,
                    Sku         = uCOmmerceOrderLine.Sku,
                    VariantSku  = uCOmmerceOrderLine.VariantSku,
                    Total       = new UCommerce.Money(uCOmmerceOrderLine.Total.GetValueOrDefault(),
                                                      uCommerceOrder.BillingCurrency).ToString()
                });
            }

            return(basketModel);
        }
Exemplo n.º 27
0
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (this.StopProcessing)
        {
            // Do not process
        }
        else
        {
            string textColor   = ValidationHelper.GetString(GetValue("TextColor"), "black").ToLower();
            bool   valuePrice  = ValidationHelper.GetBoolean(GetValue("ShowPrice"), false);
            bool   valueAmount = ValidationHelper.GetBoolean(GetValue("ShowProductAmount"), false);
            string iconColor   = ValidationHelper.GetString(GetValue("IconColor"), "black").ToLower();

            if (!TransactionLibrary.HasBasket())
            {
                lblMinicartAmount.Text = "Your basket is empty";
                hlMinicart.Attributes.Add("class", "" + textColor);
                return;
            }

            var purchaseOrder         = TransactionLibrary.GetBasket(false).PurchaseOrder;
            var numberOfItemsInBasket = purchaseOrder.OrderLines.Sum(x => x.Quantity);
            var basketTotal           = purchaseOrder.OrderTotal.HasValue ? new Money(purchaseOrder.OrderTotal.Value, purchaseOrder.BillingCurrency) : new Money(0, purchaseOrder.BillingCurrency);

            hlMinicart.Attributes.Add("href", "~/basket");
            hlMinicart.Attributes.Add("class", "" + textColor);
            imgMinicart.Attributes.Add("class", "icon-shopping-cart icon-" + iconColor);
            if (valuePrice)
            {
                lblMinicartPrice.Text = basketTotal.ToString();
            }
            if (valueAmount)
            {
                lblMinicartAmount.Text = $"{numberOfItemsInBasket} item(s)";
            }
        }
    }
        public ActionResult Index()
        {
            var paymentModel = new PaymentViewModel();

            paymentModel.AvailablePaymentMethods = new List <SelectListItem>();

            var shippingCountry = TransactionLibrary.GetShippingInformation().Country;
            var payment         = TransactionLibrary.GetBasket(false).PurchaseOrder.Payments.FirstOrDefault();

            var availablePaymentMethods = TransactionLibrary.GetPaymentMethods(shippingCountry);

            foreach (var availablePaymentMethod in availablePaymentMethods)
            {
                paymentModel.AvailablePaymentMethods.Add(new SelectListItem()
                {
                    Selected = payment != null && payment.PaymentMethod.PaymentMethodId ==
                               availablePaymentMethod.PaymentMethodId,
                    Text  = availablePaymentMethod.Name,
                    Value = availablePaymentMethod.PaymentMethodId.ToString()
                });
            }

            return(View("/Views/Payment.cshtml", paymentModel));
        }
Exemplo n.º 29
0
        public HttpResponseMessage GetBasket()
        {
            var     basket        = TransactionLibrary.GetBasket(true);
            dynamic currentbasket = new ExpandoObject();
            var     lineItems     = new List <ExpandoObject>();
            var     subtotal      = 0.0m;

            foreach (var line in basket.PurchaseOrder.OrderLines)
            {
                dynamic item = new ExpandoObject();
                item.lineid    = line.OrderLineId;
                item.qty       = line.Quantity;
                item.name      = line.ProductName;
                item.price     = line.Price;
                item.linetotal = line.Price * line.Quantity;
                lineItems.Add(item);
                subtotal += item.linetotal;
            }

            currentbasket.basket   = lineItems;
            currentbasket.subtotal = subtotal;

            return(Request.CreateResponse(HttpStatusCode.OK, (object)currentbasket));
        }
Exemplo n.º 30
0
        protected override object Run(GetBasket request)
        {
            var basket = TransactionLibrary.GetBasket(true);

            return(new GetBasketResponse(basket));
        }