Пример #1
0
        /// <summary>
        /// Maps the specified source.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="destination">The destination.</param>
        protected virtual void Map([NotNull] ShoppingCartLine source, [NotNull] DomainModel.Orders.OrderLine destination)
        {
            Assert.ArgumentNotNull(source, "source");
            Assert.ArgumentNotNull(destination, "destination");

            destination.Product     = source.Product;
            destination.Totals      = source.Totals;
            destination.Quantity    = source.Quantity;
            destination.FriendlyUrl = source.FriendlyUrl;
            destination.ImageUrl    = source.ImageUrl;
        }
Пример #2
0
        /// <summary>
        /// Maps the specified source.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="destination">The destination.</param>
        protected virtual void Map([NotNull] ShoppingCart source, [NotNull] OldOrder destination)
        {
            Assert.ArgumentNotNull(source, "source");
            Assert.ArgumentNotNull(destination, "destination");

            Assert.IsNotNull(this.entityHelper, "EntityHelper must be set.");

            this.entityHelper.CopyPropertiesValues(source, ref destination);
            foreach (ShoppingCartLine line in source.ShoppingCartLines)
            {
                DomainModel.Orders.OrderLine orderLine = Context.Entity.Resolve <DomainModel.Orders.OrderLine>();
                this.Map(line, orderLine);
                destination.OrderLines.Add(orderLine);
            }
        }
Пример #3
0
        /// <summary>
        /// Gets the order from item.
        /// </summary>
        /// <param name="orderItem">The order item.</param>
        /// <returns>The order from item.</returns>
        protected virtual T GetOrderFromItem(Item orderItem)
        {
            if (orderItem == null)
            {
                return(Context.Entity.Resolve <T>());
            }

            IDataMapper dataMapper = Context.Entity.Resolve <IDataMapper>();
            T           order      = dataMapper.GetEntity <T>(orderItem, "OrderMappingRule");

            order.OrderLines = new List <DomainModel.Orders.OrderLine>();

            foreach (Item orderLineItem in orderItem.Children)
            {
                DomainModel.Orders.OrderLine orderLine = dataMapper.GetEntity <DomainModel.Orders.OrderLine>(orderLineItem, "OrderLineMappingRule");
                orderLine.Id = orderLineItem.ID.ToString();

                Assert.IsNotNull(orderLine.Product, "There is no products in the orderline");

                order.OrderLines.Add(orderLine);
            }

            return(order);
        }
Пример #4
0
        /// <summary>
        /// Creates the order.
        /// </summary>
        /// <typeparam name="TShoppingCart">The type of the shopping cart.</typeparam>
        /// <param name="shoppingCart">The shopping cart.</param>
        /// <returns>The order.</returns>
        /// <exception cref="ConfigurationException">The Order/Default Status For Order Registration setting did't contain a valid Status item.</exception>
        /// <exception cref="Exception"><c>Exception</c>.</exception>
        public virtual T CreateOrder <TShoppingCart>(TShoppingCart shoppingCart) where TShoppingCart : ShoppingCart
        {
            Assert.IsNotNull(shoppingCart, "Shopping Cart is null");

            Events.Event.RaiseEvent("order:creating", this);

            TemplateItem orderTemplateItem = this.Database.GetTemplate(this.orderItemTempalteId);

            Assert.IsNotNull(orderTemplateItem, "Order item template is null");

            T order = Context.Entity.Resolve <T>();

            this.entityHelper.CopyPropertiesValues(shoppingCart, ref order);
            foreach (ShoppingCartLine line in shoppingCart.ShoppingCartLines)
            {
                DomainModel.Orders.OrderLine orderLine = Context.Entity.Resolve <DomainModel.Orders.OrderLine>();

                orderLine.Product     = line.Product;
                orderLine.Totals      = line.Totals;
                orderLine.Quantity    = line.Quantity;
                orderLine.FriendlyUrl = line.FriendlyUrl;

                order.OrderLines.Add(orderLine);
            }

            // NOTE: Save transaction number.
            ITransactionData transactionData   = Context.Entity.Resolve <ITransactionData>();
            string           transactionNumber = TypeUtil.TryParse(transactionData.GetPersistentValue(shoppingCart.OrderNumber, TransactionConstants.TransactionNumber), string.Empty);

            if (!string.IsNullOrEmpty(transactionNumber))
            {
                order.TransactionNumber = transactionNumber;
            }

            order.OrderDate = DateTime.Now;
            order.Status    = Context.Entity.Resolve <NewOrder>();
            order.ProcessStatus();

            Item orderItem;

            using (new SecurityDisabler())
            {
                orderItem = this.OrdersItem.Add(shoppingCart.OrderNumber, orderTemplateItem);
                Assert.IsNotNull(orderItem, "Failed to create to order item");

                if (order is IEntity)
                {
                    ((IEntity)order).Alias = orderItem.ID.ToString();
                }
            }

            try
            {
                this.SaveOrder(orderItem, order);
            }
            catch
            {
                using (new SecurityDisabler())
                {
                    orderItem.Delete();
                }

                throw;
            }

            Events.Event.RaiseEvent("order:created", this, order);

            return(order);
        }