コード例 #1
0
        /// <summary>
        /// Updates a product tag
        /// </summary>
        /// <param name="productTag">Product tag</param>
        public void UpdateProductTag(ProductTag productTag)
        {
            if (productTag == null)
                throw new ArgumentNullException("productTag");

            productTag.Name = CommonHelper.EnsureNotNull(productTag.Name);
            productTag.Name = productTag.Name.Trim();
            productTag.Name = CommonHelper.EnsureMaximumLength(productTag.Name, 100);

            if (!_context.IsAttached(productTag))
                _context.ProductTags.Attach(productTag);

            _context.SaveChanges();
        }
コード例 #2
0
        /// <summary>
        /// Inserts a product tag
        /// </summary>
        /// <param name="productTag">Product tag</param>
        public void InsertProductTag(ProductTag productTag)
        {
            if (productTag == null)
                throw new ArgumentNullException("productTag");

            productTag.Name = CommonHelper.EnsureNotNull(productTag.Name);
            productTag.Name = productTag.Name.Trim();
            productTag.Name = CommonHelper.EnsureMaximumLength(productTag.Name, 100);

            _context.ProductTags.AddObject(productTag);
            _context.SaveChanges();
        }
コード例 #3
0
ファイル: SEOHelper.cs プロジェクト: robbytarigan/ToyHouse
        /// <summary>
        /// Gets product tag URL
        /// </summary>
        /// <param name="productTag">Product tag</param>
        /// <returns>Product tag URL</returns>
        public static string GetProductTagUrl(ProductTag productTag)
        {
            if (productTag == null)
                throw new ArgumentNullException("productTag");
            string seName = GetSEName(productTag.Name);

            string url2 = SEOHelper.EnableUrlRewriting ? IoC.Resolve<ISettingManager>().GetSettingValue("SEO.ProductTags.UrlRewriteFormat") : "{0}ProductTag.aspx?tagid={1}";
            string url = string.Format(url2, CommonHelper.GetStoreLocation(), productTag.ProductTagId, seName);
            return url.ToLowerInvariant();
        }
コード例 #4
0
        public Product SaveInfo()
        {
            DateTime nowDT = DateTime.UtcNow;

            string name = txtName.Text.Trim();
            string shortDescription = txtShortDescription.Text.Trim();
            string fullDescription = txtFullDescription.Value.Trim();
            string adminComment = txtAdminComment.Text.Trim();
            int templateId = int.Parse(this.ddlTemplate.SelectedItem.Value);
            bool showOnHomePage = cbShowOnHomePage.Checked;
            bool allowCustomerReviews = cbAllowCustomerReviews.Checked;
            bool allowCustomerRatings = cbAllowCustomerRatings.Checked;
            bool published = cbPublished.Checked;
            string sku = txtSKU.Text.Trim();
            string manufacturerPartNumber = txtManufacturerPartNumber.Text.Trim();
            bool isGiftCard = cbIsGiftCard.Checked;
            int giftCardType = int.Parse(this.ddlGiftCardType.SelectedItem.Value);
            bool isDownload = cbIsDownload.Checked;
            int productVariantDownloadId = 0;
            if (isDownload)
            {
                bool useDownloadURL = cbUseDownloadURL.Checked;
                string downloadURL = txtDownloadURL.Text.Trim();
                byte[] productVariantDownloadBinary = null;
                string downloadContentType = string.Empty;
                string downloadFilename = string.Empty;
                string downloadExtension = string.Empty;

                HttpPostedFile productVariantDownloadFile = fuProductVariantDownload.PostedFile;
                if ((productVariantDownloadFile != null) && (!String.IsNullOrEmpty(productVariantDownloadFile.FileName)))
                {
                    productVariantDownloadBinary = productVariantDownloadFile.GetDownloadBits();
                    downloadContentType = productVariantDownloadFile.ContentType;
                    downloadFilename = Path.GetFileNameWithoutExtension(productVariantDownloadFile.FileName);
                    downloadExtension = Path.GetExtension(productVariantDownloadFile.FileName);
                }

                var productVariantDownload = new Download()
                {
                    UseDownloadUrl = useDownloadURL,
                    DownloadUrl = downloadURL,
                    DownloadBinary = productVariantDownloadBinary,
                    ContentType = downloadContentType,
                    Filename = downloadFilename,
                    Extension = downloadExtension,
                    IsNew = true
                };
                this.DownloadService.InsertDownload(productVariantDownload);
                productVariantDownloadId = productVariantDownload.DownloadId;
            }

            bool unlimitedDownloads = cbUnlimitedDownloads.Checked;
            int maxNumberOfDownloads = txtMaxNumberOfDownloads.Value;
            int? downloadExpirationDays = null;
            if (!String.IsNullOrEmpty(txtDownloadExpirationDays.Text.Trim()))
                downloadExpirationDays = int.Parse(txtDownloadExpirationDays.Text.Trim());
            DownloadActivationTypeEnum downloadActivationType = (DownloadActivationTypeEnum)Enum.ToObject(typeof(DownloadActivationTypeEnum), int.Parse(this.ddlDownloadActivationType.SelectedItem.Value));
            bool hasUserAgreement = cbHasUserAgreement.Checked;
            string userAgreementText = txtUserAgreementText.Value;

            bool hasSampleDownload = cbHasSampleDownload.Checked;
            int productVariantSampleDownloadId = 0;
            if (hasSampleDownload)
            {
                bool useSampleDownloadURL = cbUseSampleDownloadURL.Checked;
                string sampleDownloadURL = txtSampleDownloadURL.Text.Trim();
                byte[] productVariantSampleDownloadBinary = null;
                string sampleDownloadContentType = string.Empty;
                string sampleDownloadFilename = string.Empty;
                string sampleDownloadExtension = string.Empty;

                HttpPostedFile productVariantSampleDownloadFile = fuProductVariantSampleDownload.PostedFile;
                if ((productVariantSampleDownloadFile != null) && (!String.IsNullOrEmpty(productVariantSampleDownloadFile.FileName)))
                {
                    productVariantSampleDownloadBinary = productVariantSampleDownloadFile.GetDownloadBits();
                    sampleDownloadContentType = productVariantSampleDownloadFile.ContentType;
                    sampleDownloadFilename = Path.GetFileNameWithoutExtension(productVariantSampleDownloadFile.FileName);
                    sampleDownloadExtension = Path.GetExtension(productVariantSampleDownloadFile.FileName);
                }

                var productVariantSampleDownload = new Download()
                {
                    UseDownloadUrl = useSampleDownloadURL,
                    DownloadUrl = sampleDownloadURL,
                    DownloadBinary = productVariantSampleDownloadBinary,
                    ContentType = sampleDownloadContentType,
                    Filename = sampleDownloadFilename,
                    Extension = sampleDownloadExtension,
                    IsNew = true
                };
                this.DownloadService.InsertDownload(productVariantSampleDownload);
                productVariantSampleDownloadId = productVariantSampleDownload.DownloadId;
            }

            bool isRecurring = cbIsRecurring.Checked;
            int cycleLength = txtCycleLength.Value;
            RecurringProductCyclePeriodEnum cyclePeriod = (RecurringProductCyclePeriodEnum)Enum.ToObject(typeof(RecurringProductCyclePeriodEnum), int.Parse(this.ddlCyclePeriod.SelectedItem.Value));
            int totalCycles = txtTotalCycles.Value;

            bool isShipEnabled = cbIsShipEnabled.Checked;
            bool isFreeShipping = cbIsFreeShipping.Checked;
            decimal additionalShippingCharge = txtAdditionalShippingCharge.Value;
            bool isTaxExempt = cbIsTaxExempt.Checked;
            int taxCategoryId = int.Parse(this.ddlTaxCategory.SelectedItem.Value);
            int manageStock = Convert.ToInt32(ddlManageStock.SelectedValue);
            int stockQuantity = txtStockQuantity.Value;
            bool displayStockAvailability = cbDisplayStockAvailability.Checked;
            bool displayStockQuantity = cbDisplayStockQuantity.Checked;
            int minStockQuantity = txtMinStockQuantity.Value;
            LowStockActivityEnum lowStockActivity = (LowStockActivityEnum)Enum.ToObject(typeof(LowStockActivityEnum), int.Parse(this.ddlLowStockActivity.SelectedItem.Value));
            int notifyForQuantityBelow = txtNotifyForQuantityBelow.Value;
            int backorders = int.Parse(this.ddlBackorders.SelectedItem.Value);
            int orderMinimumQuantity = txtOrderMinimumQuantity.Value;
            int orderMaximumQuantity = txtOrderMaximumQuantity.Value;
            int warehouseId = int.Parse(this.ddlWarehouse.SelectedItem.Value);
            bool disableBuyButton = cbDisableBuyButton.Checked;
            bool callForPrice = cbCallForPrice.Checked;
            decimal price = txtPrice.Value;
            decimal oldPrice = txtOldPrice.Value;
            decimal productCost = txtProductCost.Value;
            bool customerEntersPrice = cbCustomerEntersPrice.Checked;
            decimal minimumCustomerEnteredPrice = txtMinimumCustomerEnteredPrice.Value;
            decimal maximumCustomerEnteredPrice = txtMaximumCustomerEnteredPrice.Value;
            decimal weight = txtWeight.Value;
            decimal length = txtLength.Value;
            decimal width = txtWidth.Value;
            decimal height = txtHeight.Value;
            DateTime? availableStartDateTime = ctrlAvailableStartDateTimePicker.SelectedDate;
            DateTime? availableEndDateTime = ctrlAvailableEndDateTimePicker.SelectedDate;
            if (availableStartDateTime.HasValue)
            {
                availableStartDateTime = DateTime.SpecifyKind(availableStartDateTime.Value, DateTimeKind.Utc);
            }
            if (availableEndDateTime.HasValue)
            {
                availableEndDateTime = DateTime.SpecifyKind(availableEndDateTime.Value, DateTimeKind.Utc);
            }

            //product
            var product = new Product()
            {
                Name = name,
                ShortDescription = shortDescription,
                FullDescription = fullDescription,
                AdminComment = adminComment,
                TemplateId = templateId,
                ShowOnHomePage = showOnHomePage,
                AllowCustomerReviews = allowCustomerReviews,
                AllowCustomerRatings = allowCustomerRatings,
                Published = published,
                CreatedOn = nowDT,
                UpdatedOn = nowDT
            };

            this.ProductService.InsertProduct(product);

            //product variant
            var productVariant = new ProductVariant()
            {
                ProductId = product.ProductId,
                SKU = sku,
                ManufacturerPartNumber = manufacturerPartNumber,
                IsGiftCard = isGiftCard,
                GiftCardType = giftCardType,
                IsDownload = isDownload,
                DownloadId = productVariantDownloadId,
                UnlimitedDownloads = unlimitedDownloads,
                MaxNumberOfDownloads = maxNumberOfDownloads,
                DownloadExpirationDays = downloadExpirationDays,
                DownloadActivationType = (int)downloadActivationType,
                HasSampleDownload = hasSampleDownload,
                SampleDownloadId = productVariantSampleDownloadId,
                HasUserAgreement = hasUserAgreement,
                UserAgreementText = userAgreementText,
                IsRecurring = isRecurring,
                CycleLength = cycleLength,
                CyclePeriod = (int)cyclePeriod,
                TotalCycles = totalCycles,
                IsShipEnabled = isShipEnabled,
                IsFreeShipping = isFreeShipping,
                AdditionalShippingCharge = additionalShippingCharge,
                IsTaxExempt = isTaxExempt,
                TaxCategoryId = taxCategoryId,
                ManageInventory = manageStock,
                StockQuantity = stockQuantity,
                DisplayStockAvailability = displayStockAvailability,
                DisplayStockQuantity = displayStockQuantity,
                MinStockQuantity = minStockQuantity,
                LowStockActivityId = (int)lowStockActivity,
                NotifyAdminForQuantityBelow = notifyForQuantityBelow,
                Backorders = backorders,
                OrderMinimumQuantity = orderMinimumQuantity,
                OrderMaximumQuantity = orderMaximumQuantity,
                WarehouseId = warehouseId,
                DisableBuyButton = disableBuyButton,
                CallForPrice = callForPrice,
                Price = price,
                OldPrice = oldPrice,
                ProductCost = productCost,
                CustomerEntersPrice = customerEntersPrice,
                MinimumCustomerEnteredPrice = minimumCustomerEnteredPrice,
                MaximumCustomerEnteredPrice = maximumCustomerEnteredPrice,
                Weight = weight,
                Length = length,
                Width = width,
                Height = height,
                AvailableStartDateTime = availableStartDateTime,
                AvailableEndDateTime = availableEndDateTime,
                Published = published,
                Deleted = false,
                DisplayOrder = 1,
                CreatedOn = nowDT,
                UpdatedOn = nowDT
            };

            this.ProductService.InsertProductVariant(productVariant);

            SaveLocalizableContent(product);

            //product tags
            string[] newProductTags = ParseProductTags(txtProductTags.Text);
            foreach (string productTagName in newProductTags)
            {
                ProductTag productTag = null;
                var productTag2 = this.ProductService.GetProductTagByName(productTagName);
                if (productTag2 == null)
                {
                    //add new product tag
                    productTag = new ProductTag()
                    {
                        Name = productTagName,
                        ProductCount = 0
                    };
                    this.ProductService.InsertProductTag(productTag);
                }
                else
                {
                    productTag = productTag2;
                }
                this.ProductService.AddProductTagMapping(product.ProductId, productTag.ProductTagId);
            }

            return product;
        }
コード例 #5
0
        public Product SaveInfo()
        {
            Product product = this.ProductService.GetProductById(this.ProductId);
            if (Page.IsValid)
            {
                if (product != null)
                {
                    product.Name = txtName.Text;
                    product.ShortDescription = txtShortDescription.Text;
                    product.FullDescription = txtFullDescription.Value;
                    product.AdminComment = String.Empty; // txtAdminComment.Text;
                    product.TemplateId = 5; // int.Parse(this.ddlTemplate.SelectedItem.Value);
                    product.ShowOnHomePage = false; // cbShowOnHomePage.Checked;
                    product.AllowCustomerReviews = true; // cbAllowCustomerReviews.Checked;
                    product.AllowCustomerRatings = true; // cbAllowCustomerRatings.Checked;
                    product.Published = cbPublished.Checked;
                    product.MetaKeywords = txtProductTags.Text;
                    product.MetaDescription = txtShortDescription.Text;
                    product.MetaTitle = txtName.Text;
                    //use this flag to determine whether or not
                    //product is an add or an update.
                    product.Activated = true;
                    product.UpdatedOn = DateTime.UtcNow;
                    this.ProductService.UpdateProduct(product);

                    //NFF - 12.19.2011 - There is only one product variant in Sewbie.
                    //                   we will not use anything else so it can be hard coded
                    //                   as if it is an extension table / object.
                    //NFF - 01/11/2012 - Updated so publish saves as well.
                    //NFF - 01/20/2012 - Updated so the disable buy button is automatically enabled.
                    product.ProductVariants[0].StockQuantity = txtStockQuantity.Value;
                    //product.ProductVariants[0].VendorId = Convert.ToInt32(ddlVendor.SelectedItem.Value);
                    product.ProductVariants[0].VendorId = NopCommerce.BusinessLogic.NopContext.Current.User.CustomerId;
                    product.ProductVariants[0].Price = txtPrice.Value;
                    product.ProductVariants[0].Published = cbPublished.Checked;
                    product.ProductVariants[0].DisableBuyButton = false;

                    product.ProductVariants[0].IsShipEnabled = true;
                    product.ProductVariants[0].IsFreeShipping = false;
                    product.ProductVariants[0].AdditionalShippingCharge = txtAdditionalShippingCharge.Value;
                    product.ProductVariants[0].DisplayStockAvailability = true;
                    product.ProductVariants[0].DisplayStockQuantity = cbDisplayStockQuantity.Checked;
                    product.ProductVariants[0].ManageInventory = 1;

                    this.ProductService.UpdateProductVariant(product.ProductVariants[0]);

                    SaveLocalizableContent(product);

                    //product tags
                    var existingProductTags = this.ProductService.GetProductTagsByProductId(product.ProductId);
                    string[] newProductTags = ParseProductTags(txtProductTags.Text);
                    var productTagsToDelete = new List<ProductTag>();
                    foreach (var existingProductTag in existingProductTags)
                    {
                        bool found = false;
                        foreach (string newProductTag in newProductTags)
                        {
                            if (existingProductTag.Name.Equals(newProductTag, StringComparison.InvariantCultureIgnoreCase))
                            {
                                found = true;
                                break;
                            }
                        }
                        if (!found)
                        {
                            productTagsToDelete.Add(existingProductTag);
                        }
                    }
                    foreach (var productTag in productTagsToDelete)
                    {
                        this.ProductService.RemoveProductTagMapping(product.ProductId, productTag.ProductTagId);
                    }
                    foreach (string productTagName in newProductTags)
                    {
                        ProductTag productTag = null;
                        var productTag2 = this.ProductService.GetProductTagByName(productTagName);
                        if (productTag2 == null)
                        {
                            //add new product tag
                            productTag = new ProductTag()
                            {
                                Name = productTagName,
                                ProductCount = 0
                            };
                            this.ProductService.InsertProductTag(productTag);
                        }
                        else
                        {
                            productTag = productTag2;
                        }
                        if (!this.ProductService.DoesProductTagMappingExist(product.ProductId, productTag.ProductTagId))
                        {
                            this.ProductService.AddProductTagMapping(product.ProductId, productTag.ProductTagId);
                        }
                    }
                }

            }
            else {
                //page is invalid.  no good data on the form.
                base.ShowError("There is an error on the form.  Please check your entries and try again.");
            }
            return product;
        }
コード例 #6
0
        public Product SaveInfo()
        {
            Product product = this.ProductService.GetProductById(this.ProductId);
            if (product != null)
            {
                product.Name = txtName.Text;
                product.ShortDescription = txtShortDescription.Text;
                product.FullDescription = txtFullDescription.Value;
                product.AdminComment = txtAdminComment.Text;
                product.TemplateId = int.Parse(this.ddlTemplate.SelectedItem.Value);
                product.ShowOnHomePage = cbShowOnHomePage.Checked;
                product.AllowCustomerReviews = cbAllowCustomerReviews.Checked;
                product.AllowCustomerRatings = cbAllowCustomerRatings.Checked;
                product.Published = cbPublished.Checked;
                product.UpdatedOn = DateTime.UtcNow;

                product.ProductVariants[0].VendorId = Convert.ToInt32(ddlVendor.SelectedItem.Value);

                this.ProductService.UpdateProduct(product);

                SaveLocalizableContent(product);

                //product tags
                var existingProductTags = this.ProductService.GetProductTagsByProductId(product.ProductId);
                string[] newProductTags = ParseProductTags(txtProductTags.Text);
                var productTagsToDelete = new List<ProductTag>();
                foreach (var existingProductTag in existingProductTags)
                {
                    bool found = false;
                    foreach (string newProductTag in newProductTags)
                    {
                        if (existingProductTag.Name.Equals(newProductTag, StringComparison.InvariantCultureIgnoreCase))
                        {
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        productTagsToDelete.Add(existingProductTag);
                    }
                }
                foreach (var productTag in productTagsToDelete)
                {
                    this.ProductService.RemoveProductTagMapping(product.ProductId, productTag.ProductTagId);
                }
                foreach (string productTagName in newProductTags)
                {
                    ProductTag productTag = null;
                    var productTag2 = this.ProductService.GetProductTagByName(productTagName);
                    if (productTag2 == null)
                    {
                        //add new product tag
                        productTag = new ProductTag()
                        {
                            Name = productTagName,
                            ProductCount = 0
                        };
                        this.ProductService.InsertProductTag(productTag);
                    }
                    else
                    {
                        productTag = productTag2;
                    }
                    if (!this.ProductService.DoesProductTagMappingExist(product.ProductId, productTag.ProductTagId))
                    {
                        this.ProductService.AddProductTagMapping(product.ProductId, productTag.ProductTagId);
                    }
                }
            }

            return product;
        }