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

            selectQuery.Append("SELECT ProductTemplateId");
            selectQuery.Append(" FROM ac_ProductProductTemplates");
            selectQuery.Append(" WHERE ProductId = @productId");
            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())
                {
                    ProductProductTemplate productProductTemplate = new ProductProductTemplate();
                    productProductTemplate.ProductId         = productId;
                    productProductTemplate.ProductTemplateId = dr.GetInt32(0);
                    ProductProductTemplates.Add(productProductTemplate);
                }
                dr.Close();
            }
            return(ProductProductTemplates);
        }
Beispiel #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();
            }
        }