public static RelatedProductCollection LoadForProduct(Int32 productId)
        {
            RelatedProductCollection RelatedProducts = new RelatedProductCollection();
            //CREATE THE DYNAMIC SQL TO LOAD OBJECT!
            StringBuilder selectQuery = new StringBuilder();

            selectQuery.Append("SELECT " + RelatedProduct.GetColumnNames(string.Empty));
            selectQuery.Append(" FROM ac_RelatedProducts");
            selectQuery.Append(" WHERE ProductId = @productId");
            selectQuery.Append(" ORDER BY OrderBy");
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());

            database.AddInParameter(selectCommand, "@productId", System.Data.DbType.Int32, productId);
            //EXECUTE THE COMMAND
            using (IDataReader dr = database.ExecuteReader(selectCommand))
            {
                while (dr.Read())
                {
                    RelatedProduct relatedProduct = new RelatedProduct();
                    RelatedProduct.LoadDataReader(relatedProduct, dr);
                    RelatedProducts.Add(relatedProduct);
                }
                dr.Close();
            }
            return(RelatedProducts);
        }
예제 #2
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();
            }
        }