示例#1
0
        public static BasketItemInput Load(Int32 basketItemInputId, bool useCache)
        {
            if (basketItemInputId == 0)
            {
                return(null);
            }
            BasketItemInput basketItemInput = null;
            string          key             = "BasketItemInput_" + basketItemInputId.ToString();

            if (useCache)
            {
                basketItemInput = ContextCache.GetObject(key) as BasketItemInput;
                if (basketItemInput != null)
                {
                    return(basketItemInput);
                }
            }
            basketItemInput = new BasketItemInput();
            if (basketItemInput.Load(basketItemInputId))
            {
                if (useCache)
                {
                    ContextCache.SetObject(key, basketItemInput);
                }
                return(basketItemInput);
            }
            return(null);
        }
 /// <summary>
 /// Loads the given BasketItemInput object from the given database data reader.
 /// </summary>
 /// <param name="basketItemInput">The BasketItemInput object to load.</param>
 /// <param name="dr">The database data reader to read data from.</param>
 public static void LoadDataReader(BasketItemInput basketItemInput, IDataReader dr)
 {
     //SET FIELDS FROM ROW DATA
     basketItemInput.BasketItemInputId = dr.GetInt32(0);
     basketItemInput.BasketItemId      = dr.GetInt32(1);
     basketItemInput.InputFieldId      = dr.GetInt32(2);
     basketItemInput.InputValue        = dr.GetString(3);
     basketItemInput.IsDirty           = false;
 }
示例#3
0
        public static bool Delete(Int32 basketItemInputId)
        {
            BasketItemInput basketItemInput = new BasketItemInput();

            if (basketItemInput.Load(basketItemInputId))
            {
                return(basketItemInput.Delete());
            }
            return(false);
        }
示例#4
0
        public static BasketItemInputCollection LoadForInputField(Int32 inputFieldId, 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(" " + BasketItemInput.GetColumnNames(string.Empty));
            selectQuery.Append(" FROM ac_BasketItemInputs");
            selectQuery.Append(" WHERE InputFieldId = @inputFieldId");
            if (!string.IsNullOrEmpty(sortExpression))
            {
                selectQuery.Append(" ORDER BY " + sortExpression);
            }
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());

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

            using (IDataReader dr = database.ExecuteReader(selectCommand))
            {
                while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows)))
                {
                    if (thisIndex >= startRowIndex)
                    {
                        BasketItemInput basketItemInput = new BasketItemInput();
                        BasketItemInput.LoadDataReader(basketItemInput, dr);
                        results.Add(basketItemInput);
                        rowCount++;
                    }
                    thisIndex++;
                }
                dr.Close();
            }
            return(results);
        }
示例#5
0
 /// <summary>
 /// Can this BasketItem combine with the given BasketItem?
 /// </summary>
 /// <param name="other">The BasketItem to check for combine</param>
 /// <returns><b>true</b> if it can combine, <b>false</b> otherwise</returns>
 internal bool CanCombine(BasketItem other, bool combineKitProducts)
 {
     if (other == null)
     {
         throw new ArgumentNullException("other");
     }
     if (this.ProductId != other.ProductId)
     {
         return(false);
     }
     if (this.IsChildItem)
     {
         // IF THE OTHER ITEM IS NOT A CHILD, THIS IS NOT A MATCH
         if (!other.IsChildItem)
         {
             return(false);
         }
         // IS THIS IS A CHILD PRODUCT OF A KIT?
         if (this.OrderItemType == OrderItemType.Product)
         {
             // DO NOT COMBINE CHILD PRODUCTS UNLESS INDICATED
             if (!combineKitProducts)
             {
                 return(false);
             }
             // DO NOT COMBINE IF NAME,PRICE,WEIGHT MISMATCH
             if (this.Name != other.Name ||
                 this.Price != other.Price ||
                 this.Weight != other.Weight)
             {
                 return(false);
             }
         }
         // IF THE OTHER ITEM HAS A DIFFERENT PARENT IT IS NOT A MATCH
         if (this.ParentItemId != other.ParentItemId)
         {
             return(false);
         }
     }
     else
     {
         //THIS ITEM IS NOT A CHILD, SO THE OTHER IS NOT A MATCH IF IT IS A CHILD
         if (other.IsChildItem)
         {
             return(false);
         }
     }
     if (this.OptionList != other.OptionList)
     {
         return(false);
     }
     if (this.LineMessage != other.LineMessage)
     {
         return(false);
     }
     if (this.WishlistItemId != other.WishlistItemId)
     {
         return(false);
     }
     if (this.BasketShipmentId != other.BasketShipmentId)
     {
         return(false);
     }
     if (this.GiftMessage != other.GiftMessage)
     {
         return(false);
     }
     if (this.WrapStyleId != other.WrapStyleId)
     {
         return(false);
     }
     if (this.Inputs.Count > 0)
     {
         //compare all of the input values to see if they match
         if (this.Inputs.Count != other.Inputs.Count)
         {
             return(false);
         }
         foreach (BasketItemInput input in this.Inputs)
         {
             BasketItemInput otherInput = BasketItem.GetInput(other.Inputs, input.InputFieldId);
             if (otherInput == null)
             {
                 return(false);
             }
             if (!input.InputValue.Equals(otherInput.InputValue))
             {
                 return(false);
             }
         }
     }
     if (this.KitList != other.KitList)
     {
         return(false);
     }
     if (this.OrderItemType != OrderItemType.Product)
     {
         if (this.Name != other.Name)
         {
             return(false);
         }
         if (this.Sku != other.Sku)
         {
             return(false);
         }
         if (this.Price != other.Price)
         {
             return(false);
         }
     }
     else
     {
         //NEED TO CHECK WHETHER THIS IS A VARIABLE PRICE PRODUCT
         if (this.Product != null && this.Product.UseVariablePrice)
         {
             //IS MY PRICE DIFFERENT FROM THE OTHER PRICE?
             if (this.Price != other.Price)
             {
                 return(false);
             }
         }
     }
     return(true);
 }
示例#6
0
        /// <summary>
        /// Creates a basket item for a product
        /// </summary>
        /// <param name="productId">Id of the product for which to create the basket item</param>
        /// <param name="quantity">The quantity of basket item</param>
        /// <param name="optionList">List of option ids for the variant</param>
        /// <param name="kitList">List of product Ids of the kit items</param>
        /// <param name="userId">The user Id</param>
        /// <returns>The BasketItem created</returns>
        public static BasketItem CreateForProduct(int productId, short quantity, string optionList, string kitList, int userId)
        {
            // vALIDATE PARAMETERS
            Product product = ProductDataSource.Load(productId);

            if (product == null)
            {
                throw new ArgumentException("invalid product specified", "product");
            }
            if (quantity < 1)
            {
                throw new ArgumentException("quantity must be greater than 0", "quantity");
            }
            if (!string.IsNullOrEmpty(optionList))
            {
                ProductVariant v = ProductVariantDataSource.LoadForOptionList(productId, optionList);
                if (v == null)
                {
                    throw new ArgumentException("specified product options are invalid", "optionList");
                }
            }
            if (product.KitStatus == KitStatus.Master)
            {
                Kit kit = product.Kit;
                if (!kit.ValidateChoices(kitList))
                {
                    throw new ArgumentException("specified kit configuration is invalid", "kitProductIds");
                }
            }

            //GET THE QUANTITY
            short tempQuantity   = quantity;
            short basketQuantity = GetExistingBasketCount(product);

            if ((product.MinQuantity > 0) && ((tempQuantity + basketQuantity) < product.MinQuantity))
            {
                tempQuantity = (short)(product.MinQuantity - basketQuantity);
            }


            if ((product.MaxQuantity > 0) && ((tempQuantity + basketQuantity) > product.MaxQuantity))
            {
                tempQuantity = (short)(product.MaxQuantity - basketQuantity);
            }


            if (tempQuantity < 1)
            {
                return(null);
            }
            quantity = tempQuantity;

            BasketItem item = new BasketItem();
            //CALCULATE THE PRICE OF THE PRODUCT
            ProductCalculator pcalc = ProductCalculator.LoadForProduct(productId, quantity, optionList, kitList, userId);

            item.Sku    = pcalc.Sku;
            item.Price  = pcalc.Price;
            item.Weight = pcalc.Weight;
            //SET VALUES COMMON TO ALL BASKET ITEMS
            item.TaxCodeId     = product.TaxCodeId;
            item.Name          = product.Name;
            item.Quantity      = quantity;
            item.OrderItemType = CommerceBuilder.Orders.OrderItemType.Product;
            item.Shippable     = product.Shippable;
            item.ProductId     = productId;
            item.OptionList    = optionList;
            item.KitList       = kitList;

            // COPY MERCHANT INPUT FIELDS, PRODUCT TEMPLATE FIELDS
            foreach (ProductTemplateField tf in product.TemplateFields)
            {
                if (!string.IsNullOrEmpty(tf.InputValue))
                {
                    InputField field = tf.InputField;
                    if (field.IsMerchantField && field.PersistWithOrder)
                    {
                        BasketItemInput itemInput = new BasketItemInput();
                        itemInput.BasketItemId = item.BasketItemId;
                        itemInput.InputFieldId = tf.InputFieldId;
                        itemInput.InputValue   = tf.InputValue;
                        item.Inputs.Add(itemInput);
                    }
                }
            }


            return(item);
        }
示例#7
0
 public static SaveResult Insert(BasketItemInput basketItemInput)
 {
     return(basketItemInput.Save());
 }
示例#8
0
 public static SaveResult Update(BasketItemInput basketItemInput)
 {
     return(basketItemInput.Save());
 }
示例#9
0
 public static bool Delete(BasketItemInput basketItemInput)
 {
     return(basketItemInput.Delete());
 }