Example #1
0
        public virtual CartUpdateBasketViewModel Update(CartUpdateBasket model)
        {
            foreach (var updateOrderline in model.RefreshBasket)
            {
                var newQuantity = updateOrderline.OrderLineQty;
                if (newQuantity <= 0)
                {
                    newQuantity = 0;
                }

                _transactionLibraryInternal.UpdateLineItemByOrderLineId(updateOrderline.OrderLineId, newQuantity);
            }

            _transactionLibraryInternal.ExecuteBasketPipeline();

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

            CartUpdateBasketViewModel updatedBasket = new CartUpdateBasketViewModel();

            foreach (var orderLine in basket.OrderLines)
            {
                var orderLineViewModel = new CartUpdateOrderline();
                orderLineViewModel.OrderlineId       = orderLine.OrderLineId;
                orderLineViewModel.Quantity          = orderLine.Quantity;
                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.PriceWithDiscount = new Money(orderLine.Price - orderLine.Discount, basket.BillingCurrency).ToString();

                updatedBasket.OrderLines.Add(orderLineViewModel);
            }

            string orderTotal    = new Money(basket.OrderTotal.GetValueOrDefault(), basket.BillingCurrency).ToString();
            string discountTotal = new Money(basket.DiscountTotal.GetValueOrDefault(), basket.BillingCurrency).ToString();
            string taxTotal      = new Money(basket.TaxTotal.GetValueOrDefault(), basket.BillingCurrency).ToString();
            string subTotal      = new Money(basket.SubTotal.GetValueOrDefault(), basket.BillingCurrency).ToString();

            updatedBasket.OrderTotal    = orderTotal;
            updatedBasket.DiscountTotal = discountTotal;
            updatedBasket.TaxTotal      = taxTotal;
            updatedBasket.SubTotal      = subTotal;

            return(updatedBasket);
        }
Example #2
0
        private static CartUpdateBasketViewModel MapOrderline(Ucommerce.EntitiesV2.PurchaseOrder basket)
        {
            var updatedBasket = new CartUpdateBasketViewModel();

            foreach (var orderLine in basket.OrderLines)
            {
                var currencyIsoCode    = basket.BillingCurrency.ISOCode;
                var orderLineViewModel = new CartUpdateOrderline();
                orderLineViewModel.OrderlineId       = orderLine.OrderLineId;
                orderLineViewModel.Quantity          = orderLine.Quantity;
                orderLineViewModel.Total             = new Money(orderLine.Total.GetValueOrDefault(), currencyIsoCode).ToString();
                orderLineViewModel.Discount          = orderLine.Discount;
                orderLineViewModel.Tax               = new Money(orderLine.VAT, currencyIsoCode).ToString();
                orderLineViewModel.Price             = new Money(orderLine.Price, currencyIsoCode).ToString();
                orderLineViewModel.PriceWithDiscount = new Money(orderLine.Price - orderLine.Discount, currencyIsoCode).ToString();

                updatedBasket.OrderLines.Add(orderLineViewModel);
            }

            return(updatedBasket);
        }