Example #1
0
        /// <summary>
        /// Gets a collection of Upsell Products associated with this
        /// </summary>
        /// <param name="excludeHidden">if true hidden and private associated Upsell Products will be excluded</param>
        /// <returns></returns>
        public UpsellProductCollection GetUpsellProducts(bool excludeHidden)
        {
            if (!excludeHidden)
            {
                return(UpsellProducts);
            }
            UpsellProductCollection upsellProds = new UpsellProductCollection();

            foreach (UpsellProduct upsell in UpsellProducts)
            {
                if (upsell.ChildProduct.Visibility == CatalogVisibility.Public)
                {
                    upsellProds.Add(upsell);
                }
            }
            return(upsellProds);
        }
        public static UpsellProductCollection LoadForProduct(Int32 productId, int maximumRows, int startRowIndex, string sortExpression)
        {
            //DEFAULT SORT EXPRESSION
            if (string.IsNullOrEmpty(sortExpression))
            {
                sortExpression = "OrderBy";
            }
            //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(" " + UpsellProduct.GetColumnNames(string.Empty));
            selectQuery.Append(" FROM ac_UpsellProducts");
            selectQuery.Append(" WHERE ProductId = @productId");
            selectQuery.Append(" ORDER BY " + sortExpression);
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());

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

            using (IDataReader dr = database.ExecuteReader(selectCommand))
            {
                while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows)))
                {
                    if (thisIndex >= startRowIndex)
                    {
                        UpsellProduct upsellProduct = new UpsellProduct();
                        UpsellProduct.LoadDataReader(upsellProduct, dr);
                        results.Add(upsellProduct);
                        rowCount++;
                    }
                    thisIndex++;
                }
                dr.Close();
            }
            return(results);
        }
Example #3
0
        /// <summary>
        /// Gets a collection of Upsell Products associated with this
        /// </summary>
        /// <param name="basketToExclude"></param>
        /// <returns></returns>
        public UpsellProductCollection GetUpsellProducts(Basket basketToExclude)
        {
            if (basketToExclude == null)
            {
                return(UpsellProducts);
            }
            UpsellProductCollection upsellProds = new UpsellProductCollection();

            foreach (UpsellProduct upsell in UpsellProducts)
            {
                // ONLY CONSIDER PRODUTS WITH PUBLIC VISIBILITY
                if (!basketToExclude.ContainsProduct(upsell.ChildProductId) && upsell.ChildProduct.Visibility == CatalogVisibility.Public)
                {
                    upsellProds.Add(upsell);
                }
            }
            return(upsellProds);
        }