public static void CollectProductTemplateInput(OrderItem item, Control container)
        {
            // COLLECT ANY ADDITIONAL INPUTS
            Product product = item.Product;

            if (product != null)
            {
                foreach (ProductTemplate template in product.ProductTemplates)
                {
                    foreach (InputField input in template.InputFields)
                    {
                        //ONLY LOOK FOR CUSTOMER INPUT FIELDS
                        if (!input.IsMerchantField)
                        {
                            //SEE IF WE CAN LOCATE THE CONTROL
                            WebControl inputControl = (WebControl)AbleCommerce.Code.PageHelper.RecursiveFindControl(container, input.UniqueId);
                            if (inputControl != null)
                            {
                                OrderItemInput itemInput = new OrderItemInput();
                                itemInput.OrderItem  = item;
                                itemInput.Name       = input.Name;
                                itemInput.InputValue = input.GetControlValue(inputControl);
                                item.Inputs.Add(itemInput);
                            }
                        }
                    }
                }
            }
        }
        public static OrderItemInput Load(Int32 orderItemInputId, bool useCache)
        {
            if (orderItemInputId == 0)
            {
                return(null);
            }
            OrderItemInput orderItemInput = null;
            string         key            = "OrderItemInput_" + orderItemInputId.ToString();

            if (useCache)
            {
                orderItemInput = ContextCache.GetObject(key) as OrderItemInput;
                if (orderItemInput != null)
                {
                    return(orderItemInput);
                }
            }
            orderItemInput = new OrderItemInput();
            if (orderItemInput.Load(orderItemInputId))
            {
                if (useCache)
                {
                    ContextCache.SetObject(key, orderItemInput);
                }
                return(orderItemInput);
            }
            return(null);
        }
        public static bool Delete(Int32 orderItemInputId)
        {
            OrderItemInput orderItemInput = new OrderItemInput();

            if (orderItemInput.Load(orderItemInputId))
            {
                return(orderItemInput.Delete());
            }
            return(false);
        }
        public static OrderItemInputCollection LoadForOrderItem(Int32 orderItemId, int maximumRows, int startRowIndex, string sortExpression)
        {
            //CREATE THE DYNAMIC SQL TO LOAD OBJECT
            StringBuilder selectQuery = new StringBuilder();

            selectQuery.Append("SELECT");
            if (maximumRows > 0)
            {
                selectQuery.Append(" TOP " + (startRowIndex + maximumRows).ToString());
            }
            selectQuery.Append(" " + OrderItemInput.GetColumnNames(string.Empty));
            selectQuery.Append(" FROM ac_OrderItemInputs");
            selectQuery.Append(" WHERE OrderItemId = @orderItemId");
            if (!string.IsNullOrEmpty(sortExpression))
            {
                selectQuery.Append(" ORDER BY " + sortExpression);
            }
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());

            database.AddInParameter(selectCommand, "@orderItemId", System.Data.DbType.Int32, orderItemId);
            //EXECUTE THE COMMAND
            OrderItemInputCollection results = new OrderItemInputCollection();
            int thisIndex = 0;
            int rowCount  = 0;

            using (IDataReader dr = database.ExecuteReader(selectCommand))
            {
                while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows)))
                {
                    if (thisIndex >= startRowIndex)
                    {
                        OrderItemInput orderItemInput = new OrderItemInput();
                        OrderItemInput.LoadDataReader(orderItemInput, dr);
                        results.Add(orderItemInput);
                        rowCount++;
                    }
                    thisIndex++;
                }
                dr.Close();
            }
            return(results);
        }
 public static SaveResult Insert(OrderItemInput orderItemInput)
 {
     return(orderItemInput.Save());
 }
 public static SaveResult Update(OrderItemInput orderItemInput)
 {
     return(orderItemInput.Save());
 }
 public static bool Delete(OrderItemInput orderItemInput)
 {
     return(orderItemInput.Delete());
 }
示例#8
0
        /// <summary>
        /// Generates order items from the basket data
        /// </summary>
        /// <param name="basket">The basket checking out</param>
        /// <param name="order">The order being created</param>
        /// <param name="idLookup">A translation table to map basket ids to order ids</param>
        /// <remarks>This method does not modify the basket object</remarks>
        internal static void GenerateOrderItemObjects(Basket basket, Order order, Dictionary <string, int> idLookup)
        {
            //MAKE SURE ITEMS ARE SORTED SO THAT THE IDLOOKUP IS VALID
            //(WE NEED TO PROCESS PARENT ITEMS BEFORE CHILD ITEMS)
            basket.Items.Sort(new BasketItemComparer());
            foreach (BasketItem bi in basket.Items)
            {
                OrderItem oi = new OrderItem();
                if (idLookup.ContainsKey("I" + bi.ParentItemId))
                {
                    oi.ParentItemId = idLookup["I" + bi.ParentItemId];
                }
                oi.OrderId = order.OrderId;
                if (idLookup.ContainsKey("S" + bi.BasketShipmentId))
                {
                    oi.OrderShipmentId = idLookup["S" + bi.BasketShipmentId];
                }
                oi.ProductId  = bi.ProductId;
                oi.OptionList = bi.OptionList;
                if (bi.ProductVariant != null)
                {
                    oi.VariantName = bi.ProductVariant.VariantName;
                    if (bi.ProductVariant.CostOfGoods > 0)
                    {
                        oi.CostOfGoods = bi.ProductVariant.CostOfGoods;
                    }
                }
                oi.TaxCodeId   = bi.TaxCodeId;
                oi.ShippableId = bi.ShippableId;
                oi.Name        = bi.Name;
                oi.Sku         = bi.Sku;
                oi.Price       = bi.Price;
                oi.Weight      = bi.Weight;
                if (bi.Product != null && oi.CostOfGoods == 0)
                {
                    oi.CostOfGoods = bi.Product.CostOfGoods;
                }
                oi.Quantity        = bi.Quantity;
                oi.LineMessage     = bi.LineMessage;
                oi.OrderItemTypeId = bi.OrderItemTypeId;
                oi.OrderBy         = bi.OrderBy;
                oi.WrapStyleId     = bi.WrapStyleId;
                oi.GiftMessage     = bi.GiftMessage;
                oi.WishlistItemId  = bi.WishlistItemId;
                oi.InventoryStatus = InventoryStatus.None;
                oi.TaxRate         = bi.TaxRate;
                oi.TaxAmount       = bi.TaxAmount;
                oi.KitList         = bi.KitList;
                if (oi.Product != null && oi.Product.Kit.ItemizeDisplay)
                {
                    oi.ItemizeChildProducts = true;
                }
                order.Items.Add(oi);

                // COPY THE CUSTOM FIELDS
                foreach (KeyValuePair <string, string> customField in bi.CustomFields)
                {
                    oi.CustomFields.Add(customField.Key, customField.Value);
                }

                oi.Save();
                idLookup.Add("I" + bi.BasketItemId, oi.OrderItemId);
                //COPY ANY ITEM INPUTS
                foreach (BasketItemInput bii in bi.Inputs)
                {
                    InputField inputField = bii.InputField;
                    if (inputField != null)
                    {
                        OrderItemInput oii = new OrderItemInput();
                        oii.OrderItemId     = oi.OrderItemId;
                        oii.IsMerchantField = inputField.IsMerchantField;
                        oii.Name            = inputField.Name;
                        oii.InputValue      = bii.InputValue;
                        oi.Inputs.Add(oii);
                        oii.Save();
                        // SAVE THE ASSOCIATION AS WELL
                        oi.Inputs.Save();
                    }
                }
            }
        }