Exemplo n.º 1
0
        protected void BindData()
        {
            Product product = ProductManager.GetProductByID(ProductID);

            if (product != null)
            {
                int totalRecords = 0;
                RelatedProductCollection relatedProducts = ProductManager.GetRelatedProductsByProductID1Paged(ProductID,
                                                                                                              CurrentPageIndex, pageSize, ref totalRecords);

                if (relatedProducts.Count > 0)
                {
                    this.Visible = true;
                    dlRelatedProducts.DataSource = relatedProducts;
                    dlRelatedProducts.DataBind();
                    this.relatedProductPager.PageSize     = pageSize;
                    this.relatedProductPager.TotalRecords = totalRecords;
                    this.relatedProductPager.PageIndex    = CurrentPageIndex;
                }
                else
                {
                    this.Visible = false;
                }
            }
            else
            {
                this.Visible = false;
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Product product = ProductManager.GetProductById(this.ProductId);

            if (product != null)
            {
                RelatedProductCollection existingRelatedProducts = product.RelatedProducts;

                foreach (GridViewRow row in gvProducts.Rows)
                {
                    try
                    {
                        CheckBox       cbProductInfo      = row.FindControl("cbProductInfo") as CheckBox;
                        HiddenField    hfProductId        = row.FindControl("hfProductId") as HiddenField;
                        NumericTextBox txtRowDisplayOrder = row.FindControl("txtDisplayOrder") as NumericTextBox;
                        int            productId          = int.Parse(hfProductId.Value);
                        int            displayOrder       = txtRowDisplayOrder.Value;
                        if (cbProductInfo.Checked)
                        {
                            if (existingRelatedProducts.FindRelatedProduct(this.ProductId, productId) == null)
                            {
                                ProductManager.InsertRelatedProduct(this.ProductId, productId, displayOrder);
                            }
                        }
                    }
                    catch (Exception exc)
                    {
                        ProcessException(exc);
                    }
                }
            }

            this.Page.ClientScript.RegisterStartupScript(typeof(RelatedProductAddControl), "closerefresh", "<script language=javascript>try {window.opener.document.forms[0]." + this.BtnId + ".click();}catch (e){} window.close();</script>");
        }
Exemplo n.º 3
0
        private static void DeletePreviousRelatedProducts(Product product)
        {
            RelatedProductCollection relatedProducts = new RelatedProductCollection();
            RelatedProductQuery      q = new RelatedProductQuery();

            q.Where(q.ProductId == product.Id);
            relatedProducts.Load(q);
            relatedProducts.MarkAllAsDeleted();
            relatedProducts.Save();
        }
        private void BindData()
        {
            Product product = ProductManager.GetProductByID(this.ProductID);

            if (product != null)
            {
                RelatedProductCollection         existingRelatedProductCollection = product.RelatedProducts;
                List <RelatedProductHelperClass> relatedProducts = GetRelatedProducts(existingRelatedProductCollection);
                gvRelatedProducts.DataSource = relatedProducts;
                gvRelatedProducts.DataBind();
            }
        }
        private List <RelatedProductHelperClass> GetRelatedProducts(RelatedProductCollection ExistingRelatedProductCollection)
        {
            List <RelatedProductHelperClass> result = new List <RelatedProductHelperClass>();

            foreach (RelatedProduct relatedProduct in ExistingRelatedProductCollection)
            {
                Product product = relatedProduct.Product2;
                if (product != null)
                {
                    RelatedProductHelperClass rphc = new RelatedProductHelperClass();
                    rphc.RelatedProductID = relatedProduct.RelatedProductID;
                    rphc.ProductID2       = product.ProductID;
                    rphc.ProductInfo2     = product.Name;
                    rphc.IsMapped         = true;
                    rphc.DisplayOrder     = relatedProduct.DisplayOrder;
                    result.Add(rphc);
                }
            }

            return(result);
        }
        private void BindData()
        {
            Product product = ProductManager.GetProductById(this.ProductId);

            if (product != null)
            {
                pnlData.Visible    = true;
                pnlMessage.Visible = false;

                RelatedProductCollection         existingRelatedProductCollection = product.RelatedProducts;
                List <RelatedProductHelperClass> relatedProducts = GetRelatedProducts(existingRelatedProductCollection);
                gvRelatedProducts.Columns[1].Visible = SettingManager.GetSettingValueBoolean("Display.ShowAdminProductImages");
                gvRelatedProducts.DataSource         = relatedProducts;
                gvRelatedProducts.DataBind();
            }
            else
            {
                pnlData.Visible    = false;
                pnlMessage.Visible = true;
            }
        }
Exemplo n.º 7
0
        private static RelatedProductCollection DBMapping(DBRelatedProductCollection dbCollection)
        {
            if (dbCollection == null)
                return null;

            RelatedProductCollection collection = new RelatedProductCollection();
            foreach (DBRelatedProduct dbItem in dbCollection)
            {
                RelatedProduct item = DBMapping(dbItem);
                collection.Add(item);
            }

            return collection;
        }
Exemplo n.º 8
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            bool isNew = false;

            Product toSave = new Product();

            if (!toSave.LoadByPrimaryKey(ParamId.GetValueOrDefault(-1)))
            {
                isNew          = true;
                toSave.Name    = txtName.Text;
                toSave.StoreId = StoreContext.CurrentStore.Id;
            }

            string slug = txtSlug.Text.CreateSlug();

            if (toSave.Slug != slug)
            {
                if (!SlugFactory.IsSlugAvailable(StoreContext.CurrentStore.Id.Value, slug))
                {
                    ShowFlash(string.Format(@"The URL name ""{0}"" is already in use for this store, please choose another.", slug));
                    return;
                }
            }

            if (toSave.Name.Trim() != txtName.Text.Trim())
            {
                var existingProductByName = Product.GetByName(StoreContext.CurrentStore.Id.Value, txtName.Text.Trim());
                if (existingProductByName != null)
                {
                    ShowFlash(string.Format(@"The product name ""{0}"" already exists in this store, please chose another product name", existingProductByName.Name));
                    return;
                }
            }

            string sku = txtSku.Text;

            if (!string.IsNullOrEmpty(sku))
            {
                if (!RegexPatterns.IsValidSku.IsMatch(sku))
                {
                    ShowFlash(string.Format(@"The Sku '{0}' is invalid, it must match the pattern '{1}'", sku, RegexPatterns.IsValidSku));
                    return;
                }
                sku = sku.Trim();
            }

            toSave.Name                   = txtName.Text.Trim();
            toSave.Slug                   = slug;
            toSave.IsActive               = chkIsActive.Checked;
            toSave.Price                  = Convert.ToDecimal(txtPrice.Text, CultureInfo.CreateSpecificCulture("en-US"));
            toSave.Sku                    = sku;
            toSave.SpecialNotes           = txtSpecialNotes.Text.NewlineToBr();
            toSave.IsTaxable              = chkIsTaxable.Checked;
            toSave.IsPriceDisplayed       = chkIsPriceDisplayed.Checked;
            toSave.IsAvailableForPurchase = chkIsAvailableForPurchase.Checked;
            toSave.DeliveryMethodId       = WA.Parser.ToShort(rdoDeliveryMethod.SelectedValue);
            if (toSave.DeliveryMethodId.Value == (short)ProductDeliveryMethod.Shipped)
            {
                toSave.ShippingAdditionalFeePerItem = string.IsNullOrEmpty(txtAdditionalShippingFeePerItem.Text) ? 0 : Convert.ToDecimal(txtAdditionalShippingFeePerItem.Text, CultureInfo.CreateSpecificCulture("en-US"));

                toSave.Weight = String.IsNullOrEmpty(txtWeight.Text) ? 0 : Convert.ToDecimal(txtWeight.Text, CultureInfo.CreateSpecificCulture("en-US"));
                toSave.Length = String.IsNullOrEmpty(txtLength.Text) ? 0 : Convert.ToDecimal(txtLength.Text, CultureInfo.CreateSpecificCulture("en-US"));
                toSave.Width  = String.IsNullOrEmpty(txtWidth.Text) ? 0 : Convert.ToDecimal(txtWidth.Text, CultureInfo.CreateSpecificCulture("en-US"));
                toSave.Height = String.IsNullOrEmpty(txtHeight.Text) ? 0 : Convert.ToDecimal(txtHeight.Text, CultureInfo.CreateSpecificCulture("en-US"));
            }
            else if (toSave.DeliveryMethodId.Value == (short)ProductDeliveryMethod.Downloaded)
            {
                toSave.Weight = 0;
                toSave.Length = null;
                toSave.Width  = null;
                toSave.Height = null;
                toSave.ShippingAdditionalFeePerItem = 0;
            }

            toSave.QuantityWidget  = rdoQuantityWidget.SelectedValue;
            toSave.QuantityOptions = txtQuantityOptions.Text;

            toSave.InventoryIsEnabled = chkInventoryIsEnabled.Checked;
            toSave.InventoryAllowNegativeStockLevel = chkInventoryAllowNegativeStockLevel.Checked;
            toSave.InventoryQtyInStock      = WA.Parser.ToInt(txtInventoryQtyInStock.Text);
            toSave.InventoryQtyLowThreshold = WA.Parser.ToInt(txtInventoryQtyLowThreshold.Text);

            toSave.SeoTitle       = txtSeoTitle.Text;
            toSave.SeoDescription = txtSeoDescription.Text;
            toSave.SeoKeywords    = txtSeoKeywords.Text;

            toSave.CheckoutAssignRoleInfoJson = ParseCheckoutRoleInfoFromPost();
            toSave.ViewPermissions            = ParseViewPermissionInfoFromPost();
            toSave.CheckoutPermissions        = ParseCheckoutPermissionInfoFromPost();


            toSave.Save();

            //---- Product Categories
            List <string> productCategoryIdStrings = new List <string>(Request.Form.GetValues("productCategory") ?? new string[] { });
            List <int?>   productCategoryIds       = productCategoryIdStrings.ConvertAll(s => WA.Parser.ToInt(s));

            productCategoryIds.RemoveAll(i => !i.HasValue);
            Product.SetCategories(toSave.Id.Value, productCategoryIds.ConvertAll(i => i.Value));

            //---- Related Products
            DeletePreviousRelatedProducts(toSave);

            var relatedlatedProducts = new RelatedProductCollection();

            foreach (ListItem p in cblRelatedProducts.Items)
            {
                if (!p.Selected)
                {
                    continue;
                }
                RelatedProduct relatedProduct = relatedlatedProducts.AddNew();
                relatedProduct.ProductId        = toSave.Id;
                relatedProduct.RelatedProductId = Convert.ToInt32(p.Value);
            }

            relatedlatedProducts.Save();


            //---- Digital File upload);
            if (fupDigitalFile.HasFile)
            {
                string fileUploadDirectory = StoreUrls.ProductFileFolderFileRoot;
                string fileExt             = Path.GetExtension(fupDigitalFile.PostedFile.FileName);
                string filenameWithExt     = string.Format("{0}_{1}{2}", toSave.Id.Value, Guid.NewGuid(), fileExt);
                string filePath            = fileUploadDirectory + filenameWithExt;
                //Debug.WriteFormat(@"fileUploadDirectory = ""{0}""", fileUploadDirectory);
                if (!Directory.Exists(fileUploadDirectory))
                {
                    //Debug.WriteFormat(@"creating fileUploadDirectory = ""{0}""", fileUploadDirectory);
                    Directory.CreateDirectory(fileUploadDirectory);
                }
                fupDigitalFile.PostedFile.SaveAs(filePath);

                toSave.DigitalFilename        = filenameWithExt;
                toSave.DigitalFileDisplayName = Path.GetFileNameWithoutExtension(fupDigitalFile.PostedFile.FileName).Left(250);

                toSave.Save();
            }

            //---- Photos are saved via ajax (uploaded via ajax, separately, no need to save here)

            //---- Descriptor Fields
            using (esTransactionScope transaction = new esTransactionScope())
            {
                toSave.ProductDescriptorCollectionByProductId.MarkAllAsDeleted();
                toSave.Save();

                AddDescriptor(txtDescriptorName1.Text, (txtDescriptorText1 as DotNetNuke.UI.UserControls.TextEditor).Text, 1, toSave);
                AddDescriptor(txtDescriptorName2.Text, (txtDescriptorText2 as DotNetNuke.UI.UserControls.TextEditor).Text, 2, toSave);
                AddDescriptor(txtDescriptorName3.Text, (txtDescriptorText3 as DotNetNuke.UI.UserControls.TextEditor).Text, 3, toSave);
                AddDescriptor(txtDescriptorName4.Text, (txtDescriptorText4 as DotNetNuke.UI.UserControls.TextEditor).Text, 4, toSave);
                AddDescriptor(txtDescriptorName5.Text, (txtDescriptorText5 as DotNetNuke.UI.UserControls.TextEditor).Text, 5, toSave);

                toSave.Save();

                transaction.Complete();
            }

            Response.Redirect(StoreUrls.AdminEditProduct(toSave.Id.Value, "Product Saved" + (isNew ? ", you can now add Photos, Descriptions, and Custom Attributes" : "")));
        }