예제 #1
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            PageMessageBox = ucMessageBox;

            // TODO: troubleshoot taxonomy to see why it's not saving and loading
            divTaxonomyBlock.Visible = false;

            if (!Page.IsPostBack)
            {
                PopulateTemplates();
                PopulateManufacturers();
                PopulateVendors();
                PopulateProductTypes();
                PopulateColumns();
                PopulateTaxes();
                SkuField.Focus();

                if (!string.IsNullOrEmpty(ReturnUrl) && ReturnUrl == "Y")
                {
                    lnkBacktoAbandonedCartsReport.Visible     = true;
                    lnkBacktoAbandonedCartsReport.NavigateUrl =
                        "~/DesktopModules/Hotcakes/Core/Admin/reports/AbandonedCarts/view.aspx";
                }
                else
                {
                    lnkBacktoAbandonedCartsReport.Visible = false;
                }

                if (!string.IsNullOrEmpty(ProductId))
                {
                    LoadProduct();
                    if (Request.QueryString["u"] == "1")
                    {
                        ucMessageBox.ShowOk("Product Updated");
                    }
                }
                var props = HccApp.CatalogServices.ProductPropertiesFindForType(lstProductType.SelectedValue);
                foreach (var prop in props)
                {
                    var propertyValue = HccApp.CatalogServices.ProductPropertyValues.GetPropertyValue(ProductId, prop,
                                                                                                      true);
                    _productTypeProperties.Add(prop.Id, propertyValue);
                }
                GenerateProductTypePropertyFields();
                UrlsAssociated1.ObjectId = ProductId;
                UrlsAssociated1.LoadUrls();
            }
            else
            {
                //this is a postback
                var props = HccApp.CatalogServices.ProductPropertiesFindForType(lstProductType.SelectedValue);
                foreach (var prop in props)
                {
                    var propertyValue = Request["ProductTypeProperty" + prop.Id];
                    _productTypeProperties.Add(prop.Id, propertyValue);
                }

                CheckIfProductTypePropertyChanged();
                GenerateProductTypePropertyFields();
            }
        }
예제 #2
0
        private bool Save()
        {
            var result = false;

            var c = HccApp.CatalogServices.Categories.Find(CategoryId) ?? new Category {
                ParentId = ParentCategoryId
            };
            var isNewCategory = string.IsNullOrEmpty(CategoryId);

            // ensure that the current category is not a parent of itself
            if (ParentCategoryDropDownList.SelectedValue != c.Bvin || isNewCategory)
            {
                // only update the sort if this is not a new category & the parent is different
                if (!isNewCategory && c.ParentId != ParentCategoryDropDownList.SelectedValue)
                {
                    // update the sort to be at the bottom of the existing child categories
                    c.SortOrder = HccApp.CatalogServices.Categories.FindMaxSort(ParentCategoryDropDownList.SelectedValue);
                }

                // update the category to match the selected parent category
                c.ParentId = ParentCategoryDropDownList.SelectedValue;
            }
            else
            {
                ucMessageBox.ShowWarning("A category cannot be a parent to itself.");
                return(false);
            }

            c.Name            = NameField.Text.Trim();
            c.Description     = DescriptionField.Text.Trim();
            c.MetaDescription = MetaDescriptionField.Text.Trim();
            c.MetaTitle       = MetaTitleField.Text.Trim();
            c.MetaKeywords    = MetaKeywordsField.Text.Trim();
            c.ShowInTopMenu   = false;
            c.Hidden          = chkHidden.Checked;

            c.SourceType          = CategorySourceType.Manual;
            c.TemplateName        = TemplateList.SelectedItem.Value;
            c.PreContentColumnId  = PreContentColumnIdField.SelectedValue;
            c.PostContentColumnId = PostContentColumnIdField.SelectedValue;
            c.DisplaySortOrder    = (CategorySortOrder)int.Parse(SortOrderDropDownList.SelectedValue);

            var oldUrl = c.RewriteUrl;

            // no entry, generate one
            if (string.IsNullOrWhiteSpace(RewriteUrlField.Text))
            {
                c.RewriteUrl = Text.Slugify(c.Name, true);
            }
            else
            {
                c.RewriteUrl = Text.Slugify(RewriteUrlField.Text, true);
            }

            RewriteUrlField.Text = c.RewriteUrl;

            if (UrlRewriter.IsCategorySlugInUse(c.RewriteUrl, c.Bvin, HccApp))
            {
                ucMessageBox.ShowWarning("The requested URL is already in use by another item.");
                return(false);
            }

            c.ShowTitle = chkShowTitle.Checked;
            c.Keywords  = keywords.Text.Trim();

            if (isNewCategory)
            {
                result = HccApp.CatalogServices.Categories.Create(c);
            }

            if (!SaveImages(c))
            {
                return(false);
            }

            result = HccApp.CatalogServices.CategoryUpdate(c);

            var taxonomyTags = txtTaxonomyTags.Text.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);

            HccApp.SocialService.UpdateCategoryTaxonomy(c, taxonomyTags);

            if (result)
            {
                // Update bvin field so that next save will call updated instead of create
                CategoryId = c.Bvin;

                if (oldUrl != string.Empty)
                {
                    if (oldUrl != c.RewriteUrl)
                    {
                        HccApp.ContentServices.CustomUrls.Register301(oldUrl, c.RewriteUrl,
                                                                      c.Bvin, CustomUrlType.Category, HccApp.CurrentRequestContext, HccApp);
                        UrlsAssociated1.LoadUrls();
                    }
                }
            }
            else
            {
                ucMessageBox.ShowError("Unable to save category. Unknown error.");
            }

            return(result);
        }
예제 #3
0
        protected bool Save()
        {
            var culture = Thread.CurrentThread.CurrentUICulture;
            var result  = false;

            if (Page.IsValid)
            {
                var p = HccApp.CatalogServices.Products.Find(ProductId);
                if (p == null)
                {
                    p = new Product();
                }

                p.Status       = chkActive.Checked ? ProductStatus.Active : ProductStatus.Disabled;
                p.IsSearchable = chkSearchable.Checked;

                var isBundle = rbBehaviour.SelectedValue == "B";
                var isGC     = rbBehaviour.SelectedValue == "GC";
                p.IsBundle = isBundle;

                if (isGC && p.IsGiftCard != isGC && !string.IsNullOrEmpty(p.Bvin))
                {
                    HccApp.CatalogServices.BundledProducts.DeleteByBundleProductId(p.Bvin);
                }
                p.IsGiftCard = isGC;

                p.TemplateName = ddlTemplateList.SelectedValue;
                p.Featured     = chkFeatured.Checked;

                if (string.Compare(p.Sku.Trim(), SkuField.Text.Trim(), true) != 0)
                {
                    //sku changed, so do a sku check
                    var prodGuid = DataTypeHelper.BvinToNullableGuid(p.Bvin);
                    if (HccApp.CatalogServices.Products.IsSkuExist(SkuField.Text.Trim(), prodGuid))
                    {
                        ucMessageBox.ShowError("Sku already exists on another product. Please pick another sku.");
                        return(false);
                    }
                }

                p.Sku = SkuField.Text.Trim();

                p.ProductName   = txtProductName.Text.Trim();
                p.ProductTypeId = lstProductType.SelectedValue ?? string.Empty;

                p.IsUserSuppliedPrice    = chkUserPrice.Checked;
                p.HideQty                = chkHideQty.Checked;
                p.UserSuppliedPriceLabel = txtUserPriceLabel.Text;

                if (p.IsUserSuppliedPrice || isGC)
                {
                    p.ListPrice             = 0;
                    p.SiteCost              = 0;
                    p.SitePrice             = 0;
                    p.SitePriceOverrideText = string.Empty;
                }
                else
                {
                    decimal listPrice;
                    if (decimal.TryParse(ListPriceField.Text, NumberStyles.Currency, culture, out listPrice))
                    {
                        p.ListPrice = Money.RoundCurrency(listPrice);
                    }
                    decimal cost;
                    if (decimal.TryParse(CostField.Text, NumberStyles.Currency, Thread.CurrentThread.CurrentUICulture,
                                         out cost))
                    {
                        p.SiteCost = Money.RoundCurrency(cost);
                    }
                    decimal price;
                    if (decimal.TryParse(SitePriceField.Text, NumberStyles.Currency,
                                         Thread.CurrentThread.CurrentUICulture, out price))
                    {
                        p.SitePrice = Money.RoundCurrency(price);
                    }
                    p.SitePriceOverrideText = PriceOverrideTextBox.Text.Trim();
                }
                p.LongDescription = LongDescriptionField.Text.Trim();
                p.ManufacturerId  = lstManufacturers.SelectedValue ?? string.Empty;
                p.VendorId        = lstVendors.SelectedValue ?? string.Empty;


                if (string.IsNullOrEmpty(SmallImageAlternateTextField.Text))
                {
                    p.ImageFileSmallAlternateText = p.ProductName + " " + p.Sku;
                }
                else
                {
                    p.ImageFileSmallAlternateText = SmallImageAlternateTextField.Text;
                }
                if (string.IsNullOrEmpty(MediumImageAlternateTextField.Text))
                {
                    p.ImageFileMediumAlternateText = p.ProductName + " " + p.Sku;
                }
                else
                {
                    p.ImageFileMediumAlternateText = MediumImageAlternateTextField.Text;
                }

                p.PreContentColumnId  = ddlPreContentColumn.SelectedValue;
                p.PostContentColumnId = ddlPostContentColumn.SelectedValue;

                var oldUrl = p.UrlSlug;

                // no entry, generate one
                if (p.UrlSlug.Trim().Length < 1)
                {
                    p.UrlSlug = Text.Slugify(p.ProductName, false);
                }
                else
                {
                    p.UrlSlug = Text.Slugify(txtRewriteUrl.Text, false);
                }

                if (UrlRewriter.IsProductSlugInUse(p.UrlSlug, p.Bvin, HccApp))
                {
                    ucMessageBox.ShowWarning("The requested URL is already in use by another item.");
                    return(false);
                }

                p.Keywords      = txtKeywords.Text.Trim();
                p.ProductTypeId = lstProductType.SelectedValue;
                if (!string.IsNullOrEmpty(lstTaxClasses.SelectedValue))
                {
                    p.TaxSchedule = long.Parse(lstTaxClasses.SelectedValue);
                }
                else
                {
                    p.TaxSchedule = -1;
                }

                p.MetaTitle       = txtMetaTitle.Text.Trim();
                p.MetaDescription = txtMetaDescription.Text.Trim();
                p.MetaKeywords    = txtMetaKeywords.Text.Trim();

                decimal weight = 0;
                decimal.TryParse(txtWeight.Text, NumberStyles.Float, Thread.CurrentThread.CurrentUICulture, out weight);
                p.ShippingDetails.Weight = weight;

                decimal length = 0;
                decimal.TryParse(txtLength.Text, NumberStyles.Float, Thread.CurrentThread.CurrentUICulture, out length);
                p.ShippingDetails.Length = length;

                decimal width = 0;
                decimal.TryParse(txtWidth.Text, NumberStyles.Float, Thread.CurrentThread.CurrentUICulture, out width);
                p.ShippingDetails.Width = width;

                decimal height = 0;
                decimal.TryParse(txtHeight.Text, NumberStyles.Float, Thread.CurrentThread.CurrentUICulture, out height);
                p.ShippingDetails.Height = height;

                p.ShippingDetails.ExtraShipFee =
                    Money.RoundCurrency(decimal.Parse(ExtraShipFeeField.Text, NumberStyles.Currency, culture));
                p.ShippingMode = (ShippingMode)int.Parse(ddlShipType.SelectedValue);
                p.ShippingDetails.IsNonShipping  = chkNonShipping.Checked;
                p.ShippingDetails.ShipSeparately = chkShipSeparately.Checked;

                p.ShippingCharge = (ShippingChargeType)int.Parse(lstShippingCharge.SelectedValue);

                p.MinimumQty = int.Parse(txtMinimumQty.Text, NumberStyles.Integer, Thread.CurrentThread.CurrentUICulture);

                p.TaxExempt = TaxExemptField.Checked;

                p.GiftWrapAllowed = false;

                if (!string.IsNullOrWhiteSpace(rblAllowReviews.SelectedValue))
                {
                    p.AllowReviews = bool.Parse(rblAllowReviews.SelectedValue);
                }
                else
                {
                    p.AllowReviews = null;
                }
                p.SwatchPath = swatchpathfield.Text;

                if (ucImageUploadLarge.HasFile)
                {
                    var fileName = Text.CleanFileName(Path.GetFileName(ucImageUploadLarge.FileName));
                    p.ImageFileMedium = fileName;
                    p.ImageFileSmall  = fileName;
                }

                if (string.IsNullOrEmpty(p.Bvin))
                {
                    result = HccApp.CatalogServices.ProductsCreateWithInventory(p, true);
                }
                else
                {
                    result = HccApp.CatalogServices.ProductsUpdateWithSearchRebuild(p);
                }

                if (result)
                {
                    // Create taxonomy tags
                    var taxonomyTags = txtTaxonomyTags.Text.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    HccApp.SocialService.UpdateProductTaxonomy(p, taxonomyTags);

                    // Save images
                    UploadImage(p);

                    // Store propety values
                    var props = HccApp.CatalogServices.ProductPropertiesFindForType(lstProductType.SelectedValue);
                    foreach (var prop in props)
                    {
                        if (_productTypeProperties.ContainsKey(prop.Id))
                        {
                            HccApp.CatalogServices.ProductPropertyValues.SetPropertyValue(p.Bvin, prop,
                                                                                          _productTypeProperties[prop.Id]);
                        }
                    }

                    // Update bvin field so that next save will call updated instead of create
                    ProductId = p.Bvin;

                    if (!string.IsNullOrEmpty(oldUrl) && oldUrl != p.UrlSlug)
                    {
                        HccApp.ContentServices.CustomUrls.Register301(oldUrl,
                                                                      p.UrlSlug,
                                                                      p.Bvin, CustomUrlType.Product, HccApp.CurrentRequestContext, HccApp);
                        UrlsAssociated1.LoadUrls();
                    }
                }
                else
                {
                    ucMessageBox.ShowError("Unable to save product. Unknown error. Please check event log.");
                }
            }
            return(result);
        }
예제 #4
0
        private void LoadCategory(Category c)
        {
            // load the parent categories DDL
            PopulateCategories(c.Bvin);

            NameField.Text            = c.Name;
            DescriptionField.Text     = c.Description;
            MetaDescriptionField.Text = c.MetaDescription;
            MetaKeywordsField.Text    = c.MetaKeywords;
            MetaTitleField.Text       = c.MetaTitle;
            chkHidden.Checked         = c.Hidden;

            if (ParentCategoryDropDownList.Items.FindByValue(c.ParentId) != null)
            {
                ParentCategoryDropDownList.ClearSelection();
                ParentCategoryDropDownList.Items.FindByValue(c.ParentId).Selected = true;
            }

            if (TemplateList.Items.FindByValue(c.TemplateName) != null)
            {
                TemplateList.ClearSelection();
                TemplateList.Items.FindByValue(c.TemplateName).Selected = true;
            }

            if (!string.IsNullOrWhiteSpace(c.PreContentColumnId))
            {
                if (PreContentColumnIdField.Items.FindByValue(c.PreContentColumnId) != null)
                {
                    PreContentColumnIdField.Items.FindByValue(c.PreContentColumnId).Selected = true;
                }
            }
            if (!string.IsNullOrWhiteSpace(c.PostContentColumnId))
            {
                if (PostContentColumnIdField.Items.FindByValue(c.PostContentColumnId) != null)
                {
                    PostContentColumnIdField.Items.FindByValue(c.PostContentColumnId).Selected = true;
                }
            }

            if (Enum.IsDefined(typeof(CategorySortOrder), c.DisplaySortOrder) &&
                c.DisplaySortOrder != CategorySortOrder.None)
            {
                SortOrderDropDownList.SelectedValue = ((int)c.DisplaySortOrder).ToString();
            }
            else
            {
                SortOrderDropDownList.SelectedValue = ((int)CategorySortOrder.ManualOrder).ToString();
            }

            RewriteUrlField.Text = c.RewriteUrl;
            chkShowTitle.Checked = c.ShowTitle;
            keywords.Text        = c.Keywords;
            txtTaxonomyTags.Text = string.Join(",", HccApp.SocialService.GetTaxonomyTerms(c));

            CategoryBreadCrumbTrail1.LoadTrail(c.Bvin);
            UrlsAssociated1.ObjectId = c.Bvin;
            UrlsAssociated1.LoadUrls();

            lnkViewInStore.NavigateUrl = UrlRewriter.BuildUrlForCategory(new CategorySnapshot(c));
            ucIconImage.ImageUrl       = DiskStorage.CategoryIconUrl(HccApp, c.Bvin, c.ImageUrl,
                                                                     HccApp.IsCurrentRequestSecure());
            ucBannerImage.ImageUrl = DiskStorage.CategoryBannerUrl(HccApp, c.Bvin, c.BannerImageUrl,
                                                                   HccApp.IsCurrentRequestSecure());
        }