public static coreModel.ShoppingCart ToCoreModel(this webModel.ShoppingCart cart)
		{
			var retVal = new coreModel.ShoppingCart();
			retVal.InjectFrom(cart);

			retVal.Currency = cart.Currency;
					
			if(cart.Addresses != null)
				retVal.Addresses = cart.Addresses.Select(x => x.ToCoreModel()).ToList();
			if(cart.Items != null)
				retVal.Items = cart.Items.Select(x => x.ToCoreModel()).ToList();
			if(cart.Payments != null)
				retVal.Payments = cart.Payments.Select(x => x.ToCoreModel()).ToList();
			if(cart.Shipments != null)
				retVal.Shipments = cart.Shipments.Select(x => x.ToCoreModel()).ToList();
			if(cart.Discounts != null)
				retVal.Discounts = cart.Discounts.Select(x => x.ToCoreModel()).ToList();
			if(cart.Coupon != null)
			{
				retVal.Coupon = new coreModel.Coupon() { CouponCode = cart.Coupon.CouponCode, InvalidDescription = cart.Coupon.InvalidDescription };
			}

			retVal.TaxDetails = cart.TaxDetails;
			return retVal;
		}
Ejemplo n.º 2
0
        public static webModel.ShoppingCart ToWebModel(this coreModel.ShoppingCart cart)
        {
            var retVal = new webModel.ShoppingCart();

            retVal.InjectFrom(cart);

            retVal.Currency = cart.Currency;
            if (cart.Addresses != null)
            {
                retVal.Addresses = cart.Addresses.Select(x => x.ToWebModel()).ToList();
            }
            if (cart.Items != null)
            {
                retVal.Items = cart.Items.Select(x => x.ToWebModel()).ToList();
            }
            if (cart.Payments != null)
            {
                retVal.Payments = cart.Payments.Select(x => x.ToWebModel()).ToList();
            }
            if (cart.Shipments != null)
            {
                retVal.Shipments = cart.Shipments.Select(x => x.ToWebModel()).ToList();
            }
            if (cart.Discounts != null)
            {
                retVal.Discounts = cart.Discounts.Select(x => x.ToWebModel()).ToList();
            }

            retVal.TaxDetails = cart.TaxDetails;

            return(retVal);
        }
		public static ShoppingCart ToCoreModel(this ShoppingCartEntity entity)
		{
			if (entity == null)
				throw new ArgumentNullException("entity");

			var retVal = new ShoppingCart();
			retVal.InjectFrom(entity);
			retVal.Currency = (CurrencyCodes)Enum.Parse(typeof(CurrencyCodes), entity.Currency);

			if (entity.Items != null)
			{
				retVal.Items = entity.Items.Select(x => x.ToCoreModel()).ToList();
			}
			if (entity.Addresses != null)
			{
				retVal.Addresses = entity.Addresses.Select(x => x.ToCoreModel()).ToList();
			}
			if (entity.Shipments != null)
			{
				retVal.Shipments = entity.Shipments.Select(x => x.ToCoreModel()).ToList();
			}
			if (entity.Payments != null)
			{
				retVal.Payments = entity.Payments.Select(x => x.ToCoreModel()).ToList();
			}
			retVal.TaxDetails = entity.TaxDetails.Select(x => x.ToCoreModel()).ToList();
			return retVal;
		}
Ejemplo n.º 4
0
        public virtual orderModel.CustomerOrder PlaceCustomerOrderFromCart(cartModel.ShoppingCart cart)
        {
            var customerOrder = ConvertCartToOrder(cart);

            _customerOrderService.SaveChanges(new[] { customerOrder });
            return(customerOrder);
        }
        protected override orderModel.CustomerOrder ConvertCartToOrder(cartModel.ShoppingCart cart)
        {
            var retVal = base.ConvertCartToOrder(cart);

            //TODO: Invoices
            return(retVal);
        }
Ejemplo n.º 6
0
        public virtual orderModel.CustomerOrder PlaceCustomerOrderFromCart(cartModel.ShoppingCart cart)
        {
            var customerOrder = ConvertCartToOrder(cart);

            _customerOrderService.SaveChanges(new[] { customerOrder });

            customerOrder = _customerOrderService.GetByIds(new[] { customerOrder.Id }).FirstOrDefault();

            return(customerOrder);
        }
		public void Update(ShoppingCart[] carts)
		{
			var changedCarts = new List<ShoppingCart>();
			//Thats need to correct handle partial cart update
			foreach (var cart in carts)
			{
				//Apply changes to temporary  object
				var targetCart = GetById(cart.Id);
				if (targetCart == null)
				{
					throw new NullReferenceException("targetCart");
				}
				var sourceCartEntity = cart.ToDataModel();
				var targetCartEntity = targetCart.ToDataModel();
				sourceCartEntity.Patch(targetCartEntity);
				var changedCart = targetCartEntity.ToCoreModel();
				changedCarts.Add(changedCart);
			}


			//Need a call business logic for changes and persist changes
			using (var repository = _repositoryFactory())
			using (var changeTracker = base.GetChangeTracker(repository))
			{
				foreach (var changedCart in changedCarts)
				{
					var origCart = GetById(changedCart.Id);

                    var productIds = changedCart.Items.Select(x => x.ProductId).ToArray();
                    var products = _productService.GetByIds(productIds, Domain.Catalog.Model.ItemResponseGroup.ItemInfo);
                    foreach (var lineItem in changedCart.Items)
                    {
                        var product = products.FirstOrDefault(x => x.Id == lineItem.ProductId);
                        if (product != null)
                        {
                            lineItem.Product = product;
                        }
                    }

					_eventPublisher.Publish(new CartChangeEvent(Platform.Core.Common.EntryState.Modified, origCart, changedCart));

					var sourceCartEntity = changedCart.ToDataModel();
					var targetCartEntity = repository.GetShoppingCartById(changedCart.Id);
					if (targetCartEntity == null)
					{
						throw new NullReferenceException("targetCartEntity");
					}

					changeTracker.Attach(targetCartEntity);
					sourceCartEntity.Patch(targetCartEntity);
				}
				CommitChanges(repository);
			}

		}
Ejemplo n.º 8
0
        public static CustomerOrder ToCustomerOrder(this cart.ShoppingCart cart)
        {
            if (cart == null)
            {
                throw new ArgumentNullException("cart");
            }

            var retVal = new CustomerOrder()
            {
                Id             = Guid.NewGuid().ToString(),
                Currency       = cart.Currency,
                CustomerId     = cart.CustomerId,
                CustomerName   = cart.CustomerName,
                StoreId        = cart.StoreId,
                OrganizationId = cart.OrganizationId,
                Status         = "New"
            };

            if (cart.Items != null)
            {
                retVal.Items = cart.Items.Select(x => x.ToOrderCoreModel()).ToList();
            }
            if (cart.Discounts != null)
            {
                retVal.Discount = cart.Discounts.Select(x => x.ToOrderCoreModel()).FirstOrDefault();
            }
            if (cart.Addresses != null)
            {
                retVal.Addresses = cart.Addresses.Select(x => x.ToCoreModel()).ToList();
            }
            if (cart.Shipments != null)
            {
                retVal.Shipments = cart.Shipments.Select(x => x.ToOrderCoreModel()).ToList();
                //Redistribute order line items to shipment if cart shipment items empty
                var shipment = retVal.Shipments.FirstOrDefault();
                if (shipment != null && (shipment.Items == null || !shipment.Items.Any()))
                {
                    shipment.Items = retVal.Items.Select(x => new ShipmentItem {
                        LineItem = x, Quantity = x.Quantity
                    }).ToList();
                }
            }
            if (cart.Payments != null)
            {
                retVal.InPayments = new List <PaymentIn>();
                foreach (var payment in cart.Payments)
                {
                    var paymentIn = payment.ToOrderCoreModel();
                    paymentIn.CustomerId = cart.CustomerId;
                    retVal.InPayments.Add(paymentIn);
                }
            }
            retVal.TaxDetails = cart.TaxDetails;
            return(retVal);
        }
		public ShoppingCart Create(ShoppingCart cart)
		{

			//Do business logic on temporary  order object
			_eventPublisher.Publish(new CartChangeEvent(Platform.Core.Common.EntryState.Added, null, cart));

			var entity = cart.ToDataModel();
			ShoppingCart retVal = null;
			using (var repository = _repositoryFactory())
			{
				repository.Add(entity);
				CommitChanges(repository);
			}
			retVal = GetById(entity.Id);
			return retVal;
		}
Ejemplo n.º 10
0
        public static CustomerOrder ToCustomerOrder(this cart.ShoppingCart cart)
        {
            if (cart == null)
            {
                throw new ArgumentNullException("cart");
            }

            var retVal = new CustomerOrder()
            {
                Id             = Guid.NewGuid().ToString(),
                Currency       = cart.Currency,
                CustomerId     = cart.CustomerId,
                StoreId        = cart.StoreId,
                OrganizationId = cart.OrganizationId
            };

            if (cart.Items != null)
            {
                retVal.Items = cart.Items.Select(x => x.ToCoreModel()).ToList();
            }
            if (cart.Discounts != null)
            {
                retVal.Discount = cart.Discounts.First().ToCoreModel();
            }
            if (cart.Addresses != null)
            {
                retVal.Addresses = cart.Addresses.Select(x => x.ToCoreModel()).ToList();
            }
            if (cart.Shipments != null)
            {
                retVal.Shipments = cart.Shipments.Select(x => x.ToCoreModel()).ToList();
            }
            if (cart.Payments != null)
            {
                retVal.InPayments = new List <PaymentIn>();
                foreach (var payment in cart.Payments)
                {
                    var paymentIn = payment.ToCoreModel();
                    paymentIn.CustomerId = cart.CustomerId;
                    retVal.InPayments.Add(paymentIn);
                }
            }
            retVal.TaxDetails = cart.TaxDetails;
            return(retVal);
        }
		public static ShoppingCart ToCoreModel(this ShoppingCartEntity entity)
		{
			if (entity == null)
				throw new ArgumentNullException("entity");

			var retVal = new ShoppingCart();
			retVal.InjectFrom(entity);
            retVal.Currency = entity.Currency;

            retVal.Items = entity.Items.Select(x => x.ToCoreModel()).ToList();
			retVal.Addresses = entity.Addresses.Select(x => x.ToCoreModel()).ToList();
			retVal.Shipments = entity.Shipments.Select(x => x.ToCoreModel()).ToList();
			retVal.Payments = entity.Payments.Select(x => x.ToCoreModel()).ToList();
			retVal.TaxDetails = entity.TaxDetails.Select(x => x.ToCoreModel()).ToList();
            retVal.Discounts = entity.Discounts.Select(x => x.ToCoreModel()).ToList();

            return retVal;
		}
Ejemplo n.º 12
0
        public static coreModel.ShoppingCart ToCoreModel(this webModel.ShoppingCart cart)
        {
            var retVal = new coreModel.ShoppingCart();

            retVal.InjectFrom(cart);

            retVal.Currency = cart.Currency;

            if (cart.Addresses != null)
            {
                retVal.Addresses = cart.Addresses.Select(x => x.ToCoreModel()).ToList();
            }
            if (cart.Items != null)
            {
                retVal.Items = cart.Items.Select(x => x.ToCoreModel()).ToList();
            }
            if (cart.Payments != null)
            {
                retVal.Payments = cart.Payments.Select(x => x.ToCoreModel()).ToList();
            }
            if (cart.Shipments != null)
            {
                retVal.Shipments = cart.Shipments.Select(x => x.ToCoreModel()).ToList();
            }
            if (cart.Discounts != null)
            {
                retVal.Discounts = cart.Discounts.Select(x => x.ToCoreModel()).ToList();
            }
            if (cart.Coupon != null)
            {
                retVal.Coupon = new coreModel.Coupon()
                {
                    CouponCode = cart.Coupon.CouponCode, InvalidDescription = cart.Coupon.InvalidDescription
                };
            }

            retVal.TaxDetails = cart.TaxDetails;
            return(retVal);
        }
Ejemplo n.º 13
0
        public static cartCoreModel.ShoppingCart ToCartModel(this coreModel.QuoteRequest quoteRequest)
        {
            var retVal = new cartCoreModel.ShoppingCart();
            retVal.InjectFrom(quoteRequest);
            retVal.Currency = quoteRequest.Currency;
            if (quoteRequest.Items != null)
            {
                retVal.Items = quoteRequest.Items.Select(x => x.ToCartModel()).ToList();
            }

            if(quoteRequest.ShipmentMethod != null)
            {
                var shipment = new cartCoreModel.Shipment
                {
                    Currency = quoteRequest.Currency,
                    ShipmentMethodCode = quoteRequest.ShipmentMethod.ShipmentMethodCode,
                    ShipmentMethodOption = quoteRequest.ShipmentMethod.OptionName                     
                };
                retVal.Shipments = new List<cartCoreModel.Shipment>(new[] { shipment });
            }

            return retVal;
        }
Ejemplo n.º 14
0
        public static cartCoreModel.ShoppingCart ToCartModel(this coreModel.QuoteRequest quoteRequest)
        {
            var retVal = new cartCoreModel.ShoppingCart();

            retVal.InjectFrom(quoteRequest);
            retVal.Currency = quoteRequest.Currency;
            if (quoteRequest.Items != null)
            {
                retVal.Items = quoteRequest.Items.Select(x => x.ToCartModel()).ToList();
            }

            if (quoteRequest.ShipmentMethod != null)
            {
                var shipment = new cartCoreModel.Shipment
                {
                    Currency             = quoteRequest.Currency,
                    ShipmentMethodCode   = quoteRequest.ShipmentMethod.ShipmentMethodCode,
                    ShipmentMethodOption = quoteRequest.ShipmentMethod.OptionName
                };
                retVal.Shipments = new List <cartCoreModel.Shipment>(new[] { shipment });
            }

            return(retVal);
        }
Ejemplo n.º 15
0
		public static coreModel.ShoppingCart ToCoreModel(this webModel.ShoppingCart cart)
		{
			var retVal = new coreModel.ShoppingCart();
			retVal.InjectFrom(cart);

			retVal.Currency = cart.Currency;
					
			if(cart.Addresses != null)
				retVal.Addresses = cart.Addresses.Select(x => x.ToCoreModel()).ToList();
			if(cart.Items != null)
				retVal.Items = cart.Items.Select(x => x.ToCoreModel()).ToList();
			if(cart.Payments != null)
				retVal.Payments = cart.Payments.Select(x => x.ToCoreModel()).ToList();
			if(cart.Shipments != null)
				retVal.Shipments = cart.Shipments.Select(x => x.ToCoreModel()).ToList();
			if(cart.Discounts != null)
				retVal.Discounts = cart.Discounts.Select(x => x.ToCoreModel()).ToList();
            if (cart.DynamicProperties != null)
                retVal.DynamicProperties = cart.DynamicProperties;


            retVal.TaxDetails = cart.TaxDetails;
			return retVal;
		}
Ejemplo n.º 16
0
        private void UpdateCartTaxes(IEnumerable<AvaTaxCalcREST.TaxLine> taxLines, ShoppingCart cart)
        {
            //reset all cart items taxes
            if (cart.Items.Any())
            {
                cart.Items.ForEach(x =>
                {
                    x.TaxTotal = 0;
                    x.TaxDetails = null;
                });
            }

            //reset all cart shipments taxes
            if (cart.Shipments.Any())
            {
                cart.Shipments.ForEach(x =>
                {
                    x.TaxTotal = 0;
                    x.TaxDetails = null;
                });
            }

            foreach (var taxLine in taxLines ?? Enumerable.Empty<AvaTaxCalcREST.TaxLine>())
            {
                var lineItem = cart.Items.FirstOrDefault(x => x.Id == taxLine.LineNo);
                if (lineItem != null)
                {
                    lineItem.TaxTotal = taxLine.Tax;
                    if (taxLine.TaxDetails != null && taxLine.TaxDetails.Any(td => !string.IsNullOrEmpty(td.TaxName)))
                    {
                        lineItem.TaxDetails =
                            taxLine.TaxDetails.Where(td => !string.IsNullOrEmpty(td.TaxName)).Select(taxDetail => taxDetail.ToDomainTaxDetail()).ToList();
                    }
                }
                else
                {
                    var shipment = cart.Shipments.FirstOrDefault(s => s.Id != null ? s.Id.Equals(taxLine.LineNo) : s.ShipmentMethodCode.Equals(taxLine.LineNo));
                    if (shipment != null)
                    {
                        shipment.TaxTotal = taxLine.Tax;
                        if (taxLine.TaxDetails != null && taxLine.TaxDetails.Any(td => !string.IsNullOrEmpty(td.TaxName)))
                        {
                            shipment.TaxDetails =
                                taxLine.TaxDetails.Where(td => !string.IsNullOrEmpty(td.TaxName)).Select(taxDetail => taxDetail.ToDomainTaxDetail()).ToList();
                        }
                    }
                }
            }
        }
Ejemplo n.º 17
0
 public IHttpActionResult CartTotal(ShoppingCart cart)
 {
     if (!string.IsNullOrEmpty(_taxSettings.Username) && !string.IsNullOrEmpty(_taxSettings.Password)
         && !string.IsNullOrEmpty(_taxSettings.ServiceUrl)
         && !string.IsNullOrEmpty(_taxSettings.CompanyCode) && _taxSettings.IsEnabled)
     {
         var taxSvc = new JsonTaxSvc(_taxSettings.Username, _taxSettings.Password, _taxSettings.ServiceUrl);
         var request = cart.ToAvaTaxRequest(_taxSettings.CompanyCode);
         var getTaxResult = taxSvc.GetTax(request);
         if (!getTaxResult.ResultCode.Equals(SeverityLevel.Success))
         {
             var error = string.Join(Environment.NewLine, getTaxResult.Messages.Select(m => m.Details));
             return BadRequest(error);
         }
         else
         {
             foreach (TaxLine taxLine in getTaxResult.TaxLines ?? Enumerable.Empty<TaxLine>())
             {
                 cart.Items.ToArray()[Int32.Parse(taxLine.LineNo)].TaxTotal = taxLine.Tax;
                 //foreach (TaxDetail taxDetail in taxLine.TaxDetails ?? Enumerable.Empty<TaxDetail>())
                 //{
                 //}
             }
             cart.TaxTotal = getTaxResult.TotalTax;
         }
     }
     else
     {
         return BadRequest();
     }
     return Ok(cart);
 }
Ejemplo n.º 18
0
        public static CustomerOrder ToCustomerOrder(this cart.ShoppingCart cart)
        {
            if (cart == null)
            {
                throw new ArgumentNullException("cart");
            }

            var retVal = new CustomerOrder()
            {
                Id             = Guid.NewGuid().ToString(),
                Currency       = cart.Currency,
                CustomerId     = cart.CustomerId,
                CustomerName   = cart.CustomerName,
                StoreId        = cart.StoreId,
                OrganizationId = cart.OrganizationId,
                Status         = "New"
            };

            retVal.Addresses = new List <Address>();

            if (cart.Items != null)
            {
                retVal.Items = cart.Items.Select(x => x.ToOrderCoreModel()).ToList();
            }
            if (cart.Discounts != null)
            {
                retVal.Discount = cart.Discounts.Select(x => x.ToOrderCoreModel()).FirstOrDefault();
            }
            if (cart.Addresses != null)
            {
                retVal.Addresses = cart.Addresses.Select(x => x.ToCoreModel()).ToList();
            }
            if (cart.Shipments != null)
            {
                retVal.Shipments = cart.Shipments.Select(x => x.ToOrderCoreModel()).ToList();
                //Add shipping address to order
                retVal.Addresses.AddRange(retVal.Shipments.Where(x => x.DeliveryAddress != null).Select(x => x.DeliveryAddress));
                //Redistribute order line items to shipment if cart shipment items empty
                var shipment = retVal.Shipments.FirstOrDefault();
                if (shipment != null && shipment.Items.IsNullOrEmpty())
                {
                    shipment.Items = retVal.Items.Select(x => new ShipmentItem {
                        LineItem = x, Quantity = x.Quantity
                    }).ToList();
                }
            }
            if (cart.Payments != null)
            {
                retVal.InPayments = new List <PaymentIn>();
                foreach (var payment in cart.Payments)
                {
                    var paymentIn = payment.ToOrderCoreModel();
                    if (paymentIn.BillingAddress != null)
                    {
                        //Add billing address to order
                        retVal.Addresses.Add(paymentIn.BillingAddress);
                    }
                    paymentIn.CustomerId = cart.CustomerId;
                    retVal.InPayments.Add(paymentIn);
                }
            }

            //Save only disctinct addresses for order
            retVal.Addresses   = retVal.Addresses.Distinct().ToList();
            retVal.TaxDetails  = cart.TaxDetails;
            retVal.Tax         = cart.TaxTotal;
            retVal.TaxIncluded = cart.TaxIncluded ?? false;
            return(retVal);
        }
Ejemplo n.º 19
0
        public virtual void CalculateCartTax(ShoppingCart cart)
        {
            LogInvoker<AvalaraLogger.TaxRequestContext>.Execute(log =>
            {
                if (IsEnabled && !string.IsNullOrEmpty(AccountNumber) && !string.IsNullOrEmpty(LicenseKey)
                    && !string.IsNullOrEmpty(ServiceUrl)
                    && !string.IsNullOrEmpty(CompanyCode))
                {
                    Contact contact = null;
                    if (cart.CustomerId != null)
                        contact = _customerSearchService.GetById(cart.CustomerId);

                    var request = cart.ToAvaTaxRequest(CompanyCode, contact);
                    if (request != null)
                    {
                        log.docCode = request.DocCode;
                        log.customerCode = request.CustomerCode;
                        log.docType = request.DocType.ToString();
                        log.amount = (double)cart.Total;

                        var taxSvc = new JsonTaxSvc(AccountNumber, LicenseKey, ServiceUrl);
                        var getTaxResult = taxSvc.GetTax(request);

                        if (!getTaxResult.ResultCode.Equals(SeverityLevel.Success))
                        {
                            //if tax calculation failed create exception with provided error info
                            var error = string.Join(Environment.NewLine,
                                getTaxResult.Messages.Select(m => m.Summary));
                            throw new Exception(error);
                        }

                        UpdateCartTaxes(getTaxResult.TaxLines, cart);
                    }
                    else
                    {
                        throw new Exception("Failed to create get tax request");
                    }
                }
                else
                {
                    throw new Exception("Tax calculation disabled or credentials not provided");
                }
            })
            .OnError(_logger, AvalaraLogger.EventCodes.TaxCalculationError)
            .OnSuccess(_logger, AvalaraLogger.EventCodes.GetTaxRequestTime);
        }
Ejemplo n.º 20
0
        protected virtual orderModel.CustomerOrder ConvertCartToOrder(cartModel.ShoppingCart cart)
        {
            var retVal = AbstractTypeFactory <orderModel.CustomerOrder> .TryCreateInstance();

            retVal.ShoppingCartId = cart.Id;
            retVal.Comment        = cart.Comment;
            retVal.Currency       = cart.Currency;
            retVal.ChannelId      = cart.ChannelId;
            retVal.CustomerId     = cart.CustomerId;
            retVal.CustomerName   = cart.CustomerName;
            retVal.DiscountAmount = cart.DiscountAmount;
            retVal.OrganizationId = cart.OrganizationId;
            retVal.StoreId        = cart.StoreId;
            retVal.TaxPercentRate = cart.TaxPercentRate;
            retVal.TaxType        = cart.TaxType;
            retVal.LanguageCode   = cart.LanguageCode;

            retVal.Status = "New";

            var cartLineItemsMap = new Dictionary <string, orderModel.LineItem>();

            if (cart.Items != null)
            {
                retVal.Items = new List <orderModel.LineItem>();
                foreach (var cartLineItem in cart.Items)
                {
                    var orderLineItem = ToOrderModel(cartLineItem);
                    retVal.Items.Add(orderLineItem);
                    cartLineItemsMap.Add(cartLineItem.Id, orderLineItem);
                }
            }
            if (cart.Discounts != null)
            {
                retVal.Discounts = cart.Discounts.Select(ToOrderModel).ToList();
            }

            if (cart.Addresses != null)
            {
                retVal.Addresses = cart.Addresses.ToList();
            }

            if (cart.Shipments != null)
            {
                retVal.Shipments = new List <orderModel.Shipment>();
                foreach (var cartShipment in cart.Shipments)
                {
                    var shipment = ToOrderModel(cartShipment);
                    if (!cartShipment.Items.IsNullOrEmpty())
                    {
                        shipment.Items = new List <orderModel.ShipmentItem>();
                        foreach (var cartShipmentItem in cartShipment.Items)
                        {
                            var shipmentItem = ToOrderModel(cartShipmentItem);
                            if (cartLineItemsMap.ContainsKey(cartShipmentItem.LineItemId))
                            {
                                shipmentItem.LineItem = cartLineItemsMap[cartShipmentItem.LineItemId];
                                shipment.Items.Add(shipmentItem);
                            }
                        }
                    }
                    retVal.Shipments.Add(shipment);
                }
                //Add shipping address to order
                retVal.Addresses.AddRange(retVal.Shipments.Where(x => x.DeliveryAddress != null).Select(x => x.DeliveryAddress));
            }
            if (cart.Payments != null)
            {
                retVal.InPayments = new List <orderModel.PaymentIn>();
                foreach (var payment in cart.Payments)
                {
                    var paymentIn = ToOrderModel(payment);
                    paymentIn.CustomerId = cart.CustomerId;
                    retVal.InPayments.Add(paymentIn);
                    if (payment.BillingAddress != null)
                    {
                        retVal.Addresses.Add(payment.BillingAddress);
                    }
                }
            }

            //Save only disctinct addresses for order
            retVal.Addresses = retVal.Addresses.Distinct().ToList();
            foreach (var address in retVal.Addresses)
            {
                //Reset primary key for addresses
                address.Key = null;
            }
            retVal.TaxDetails = cart.TaxDetails;
            return(retVal);
        }
Ejemplo n.º 21
0
        private static ShoppingCart GetTestCart(string id)
        {
            var cart = new ShoppingCart
            {
                Id = id,
                Currency = CurrencyCodes.USD,
                CustomerId = "Test Customer",
                StoreId = "test store",
                CreatedDate = DateTime.Now,
                Addresses = new[]
				{
					new CartAddress {	
					AddressType = CartAddressType.Shipping, 
					Phone = "+68787687",
					PostalCode = "60602",
					CountryCode = "US",
					CountryName = "United states",
					Email = "*****@*****.**",
					FirstName = "first name",
					LastName = "last name",
					Line1 = "45 Fremont Street",
                    City = "Los Angeles",
                    RegionId = "CA",
					Organization = "org1"
					}
				}.ToList(),
                Discounts = new[] { new CartDiscount
                    {
                        PromotionId = "testPromotion",
                        Currency = CurrencyCodes.USD,
                        DiscountAmount = 12,
                        
                    }
                },
                Coupon = new CartCoupon
                {
                    CouponCode = "ssss"
                }
                
            };
            var item1 = new CartLineItem
            {
                ListPrice = 10,
                ExtendedPrice = 20,
                ProductId = "shoes",
                CatalogId = "catalog",
                Currency = CurrencyCodes.USD,
                CategoryId = "category",
                Name = "shoes",
                Quantity = 2,
                ShipmentMethodCode = "EMS",
                Discounts = new[] { 
                    new CartDiscount
                    {
                        PromotionId = "itemPromotion",
                        Currency = CurrencyCodes.USD,
                        DiscountAmount = 12
                        
                    }
                }
            };
            var item2 = new CartLineItem
            {
                ListPrice = 100,
                ExtendedPrice = 200,
                ProductId = "t-shirt",
                CatalogId = "catalog",
                CategoryId = "category",
                Currency = CurrencyCodes.USD,
                Name = "t-shirt",
                Quantity = 2,
                ShipmentMethodCode = "EMS",
                Discounts = new[]{ 
                    new CartDiscount
                    {
                        PromotionId = "testPromotion",
                        Currency = CurrencyCodes.USD,
                        DiscountAmount = 12
                    }
                }
            };
            cart.Items = new List<CartLineItem> { item1, item2 };

            var shipment = new CartShipment
            {
                Currency = CurrencyCodes.USD,
                DeliveryAddress = new CartAddress
                {
                    City = "london",
                    CountryName = "England",
                    Phone = "+68787687",
                    PostalCode = "2222",
                    CountryCode = "ENG",
                    Email = "*****@*****.**",
                    FirstName = "first name",
                    LastName = "last name",
                    Line1 = "line 1",
                    Organization = "org1"
                },
                Discounts = new[] {
                    new CartDiscount
                    {
                        PromotionId = "testPromotion",
                        Currency = CurrencyCodes.USD,
                        DiscountAmount = 12,
                        
                    }
                }
            };
            cart.Shipments = new List<CartShipment> { shipment };

            var payment = new CartPayment
            {
                PaymentGatewayCode = "PayPal",
                Currency = CurrencyCodes.USD,
                Amount = 10,
                OuterId = "et"
            };
            cart.Payments = new List<CartPayment> { payment };

            return cart;
        }
		public ShippingEvaluationContext(ShoppingCart shoppingCart)
		{
			ShoppingCart = shoppingCart;
		}
		public void Update(ShoppingCart[] carts)
		{
			var changedCarts = new List<ShoppingCart>();
            var pkMap = new PrimaryKeyResolvingMap();

            using (var repository = _repositoryFactory())
			using (var changeTracker = base.GetChangeTracker(repository))
			{
				foreach (var changedCart in carts)
				{
					var origCart = GetById(changedCart.Id);

                    var productIds = changedCart.Items.Select(x => x.ProductId).ToArray();
                    var products = _productService.GetByIds(productIds, Domain.Catalog.Model.ItemResponseGroup.ItemInfo);
                    foreach (var lineItem in changedCart.Items)
                    {
                        var product = products.FirstOrDefault(x => x.Id == lineItem.ProductId);
                        if (product != null)
                        {
                            lineItem.Product = product;
                        }
                    }

					_eventPublisher.Publish(new CartChangeEvent(Platform.Core.Common.EntryState.Modified, origCart, changedCart));

					var sourceCartEntity = changedCart.ToDataModel(pkMap);
					var targetCartEntity = repository.GetShoppingCartById(changedCart.Id);
					if (targetCartEntity == null)
					{
						throw new NullReferenceException("targetCartEntity");
					}

					changeTracker.Attach(targetCartEntity);
					sourceCartEntity.Patch(targetCartEntity);
                }
                CommitChanges(repository);
                pkMap.ResolvePrimaryKeys();
            }

            //Save dynamic properties for carts and all nested objects
            foreach(var cart in carts)
            {
                _dynamicPropertyService.SaveDynamicPropertyValues(cart);
            }
        }
Ejemplo n.º 24
0
		public CartChangeEvent(EntryState state, ShoppingCart origCart, ShoppingCart modifiedCart)
		{
			ChangeState = state;
			OrigCart = origCart;
			ModifiedCart = modifiedCart;
		}