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);
        }
Example #4
0
        /// <summary>
        /// Copies the product to the specified category.
        /// </summary>
        /// <param name="categoryId">if ZERO then will copy the product with the categories as the orignal product have </param>
        /// <param name="copyName">Name to use for the copied product</param>
        public void SaveCopy(int categoryId, string copyName)
        {
            if (string.IsNullOrEmpty(copyName))
            {
                this.Name = "Copy of " + this.Name;
            }
            else
            {
                this.Name = copyName;
            }
            CopyChildren();
            //make sure related products and upsell products
            //are loaded before resetting product id to 0
            RelatedProductCollection         relatedProds            = this.RelatedProducts;
            UpsellProductCollection          upsellProds             = this.UpsellProducts;
            SubscriptionPlan                 subplan                 = this.SubscriptionPlan;
            ProductProductTemplateCollection productProductTemplates = this.ProductProductTemplates;

            // KEEP THE ORIGNAL PRODUCTS CATEGORIES IN A NEW LIST
            List <int> pcats = new List <int>();

            pcats.AddRange(this.Categories);

            this.ProductId = 0;
            this.Save();

            // RELOAD THE LIST, SO THAT IT CAN PROPERLY BE SAVED
            // THIS IS FOR PRODUCTS WE ARE COPYING WITH FULL CATEGORY DETAILS
            this.Categories.Load(this.ProductId);

            if (categoryId > 0)
            {
                this.Categories.Add(categoryId);
            }
            else
            {
                this.Categories.AddRange(pcats);
            }
            this.Categories.ProductId = this.ProductId;

            this.Categories.Save();

            foreach (RelatedProduct prod in relatedProds)
            {
                prod.ProductId = this.ProductId;
                prod.Save();
            }

            foreach (UpsellProduct upsell in upsellProds)
            {
                upsell.ProductId = this.ProductId;
                upsell.Save();
            }
            if (subplan != null)
            {
                subplan.ProductId = this.ProductId;
                subplan.Save();
            }
            foreach (ProductProductTemplate productProductTemplate in productProductTemplates)
            {
                productProductTemplate.ProductId = this.ProductId;
                productProductTemplate.Save();
            }
        }