/// <summary>
        /// Updates the specification attribute
        /// </summary>
        /// <param name="specificationAttributeOptionId">The specification attribute option identifier</param>
        /// <param name="specificationAttributeId">The specification attribute identifier</param>
        /// <param name="name">The name</param>
        /// <param name="displayOrder">Display order</param>
        /// <returns>Specification attribute option</returns>
        public static SpecificationAttributeOption UpdateSpecificationAttributeOptions(int specificationAttributeOptionId,
                                                                                       int specificationAttributeId, string name, int displayOrder)
        {
            name = CommonHelper.EnsureMaximumLength(name, 500);

            var specificationAttributeOption = GetSpecificationAttributeOptionById(specificationAttributeOptionId);

            if (specificationAttributeOption == null)
            {
                return(null);
            }

            var context = ObjectContextHelper.CurrentObjectContext;

            if (!context.IsAttached(specificationAttributeOption))
            {
                context.SpecificationAttributeOptions.Attach(specificationAttributeOption);
            }

            specificationAttributeOption.SpecificationAttributeId = specificationAttributeId;
            specificationAttributeOption.Name         = name;
            specificationAttributeOption.DisplayOrder = displayOrder;
            context.SaveChanges();

            if (SpecificationAttributeManager.CacheEnabled)
            {
                NopRequestCache.RemoveByPattern(SPECIFICATIONATTRIBUTEOPTION_PATTERN_KEY);
                NopRequestCache.RemoveByPattern(SPECIFICATIONATTRIBUTEOPTION_PATTERN_KEY);
                NopRequestCache.RemoveByPattern(PRODUCTSPECIFICATIONATTRIBUTE_PATTERN_KEY);
            }

            return(specificationAttributeOption);
        }
示例#2
0
        /// <summary>
        /// Updates the discount
        /// </summary>
        /// <param name="discountId">Discount identifier</param>
        /// <param name="discountType">The discount type</param>
        /// <param name="discountRequirement">The discount requirement</param>
        /// <param name="requirementSpentAmount">The discount requirement - applies if customer has spent/purchased x.xx amount</param>
        /// <param name="requirementBillingCountryIs">The discount requirement - customer's billing country is... (used when requirement is set to "Billing country is")</param>
        /// <param name="requirementShippingCountryIs">The discount requirement - customer's shipping country is... (used when requirement is set to "Shipping country is")</param>
        /// <param name="discountLimitation">The discount limitation</param>
        /// <param name="limitationTimes">The discount limitation times (used when Limitation is set to "N Times Only" or "N Times Per Customer")</param>
        /// <param name="name">The name</param>
        /// <param name="usePercentage">A value indicating whether to use percentage</param>
        /// <param name="discountPercentage">The discount percentage</param>
        /// <param name="discountAmount">The discount amount</param>
        /// <param name="startDate">The discount start date and time</param>
        /// <param name="endDate">The discount end date and time</param>
        /// <param name="requiresCouponCode">The value indicating whether discount requires coupon code</param>
        /// <param name="couponCode">The coupon code</param>
        /// <param name="deleted">A value indicating whether the entity has been deleted</param>
        /// <returns>Discount</returns>
        public static Discount UpdateDiscount(int discountId, DiscountTypeEnum discountType,
                                              DiscountRequirementEnum discountRequirement, decimal requirementSpentAmount,
                                              int requirementBillingCountryIs, int requirementShippingCountryIs,
                                              DiscountLimitationEnum discountLimitation, int limitationTimes,
                                              string name, bool usePercentage,
                                              decimal discountPercentage, decimal discountAmount,
                                              DateTime startDate, DateTime endDate, bool requiresCouponCode,
                                              string couponCode, bool deleted)
        {
            if (startDate.CompareTo(endDate) >= 0)
            {
                throw new NopException("Start date should be less then expiration date");
            }

            if (requiresCouponCode && String.IsNullOrEmpty(couponCode))
            {
                throw new NopException("Discount requires coupon code. Coupon code could not be empty.");
            }

            name       = CommonHelper.EnsureMaximumLength(name, 100);
            couponCode = CommonHelper.EnsureMaximumLength(couponCode, 100);

            var discount = GetDiscountById(discountId);

            if (discount == null)
            {
                return(null);
            }

            var context = ObjectContextHelper.CurrentObjectContext;

            if (!context.IsAttached(discount))
            {
                context.Discounts.Attach(discount);
            }

            discount.DiscountTypeId               = (int)discountType;
            discount.DiscountRequirementId        = (int)discountRequirement;
            discount.RequirementSpentAmount       = requirementSpentAmount;
            discount.RequirementBillingCountryIs  = requirementBillingCountryIs;
            discount.RequirementShippingCountryIs = requirementShippingCountryIs;
            discount.DiscountLimitationId         = (int)discountLimitation;
            discount.LimitationTimes              = limitationTimes;
            discount.Name               = name;
            discount.UsePercentage      = usePercentage;
            discount.DiscountPercentage = discountPercentage;
            discount.DiscountAmount     = discountAmount;
            discount.StartDate          = startDate;
            discount.EndDate            = endDate;
            discount.RequiresCouponCode = requiresCouponCode;
            discount.CouponCode         = couponCode;
            discount.Deleted            = deleted;
            context.SaveChanges();

            if (DiscountManager.CacheEnabled)
            {
                NopRequestCache.RemoveByPattern(DISCOUNTS_PATTERN_KEY);
            }
            return(discount);
        }
示例#3
0
        /// <summary>
        /// Removes a discount from a category
        /// </summary>
        /// <param name="categoryId">Category identifier</param>
        /// <param name="discountId">Discount identifier</param>
        public static void RemoveDiscountFromCategory(int categoryId, int discountId)
        {
            var category = CategoryManager.GetCategoryById(categoryId);

            if (category == null)
            {
                return;
            }

            var discount = GetDiscountById(discountId);

            if (discount == null)
            {
                return;
            }

            var context = ObjectContextHelper.CurrentObjectContext;

            if (!context.IsAttached(category))
            {
                context.Categories.Attach(category);
            }
            if (!context.IsAttached(discount))
            {
                context.Discounts.Attach(discount);
            }

            category.NpDiscounts.Remove(discount);
            context.SaveChanges();

            if (DiscountManager.CacheEnabled)
            {
                NopRequestCache.RemoveByPattern(DISCOUNTS_PATTERN_KEY);
            }
        }
示例#4
0
        /// <summary>
        /// Inserts a localized checkout attribute
        /// </summary>
        /// <param name="checkoutAttributeId">Checkout attribute identifier</param>
        /// <param name="languageId">Language identifier</param>
        /// <param name="name">Name text</param>
        /// <param name="textPrompt">Text prompt</param>
        /// <returns>Checkout attribute content</returns>
        public static CheckoutAttributeLocalized InsertCheckoutAttributeLocalized(int checkoutAttributeId,
                                                                                  int languageId, string name, string textPrompt)
        {
            name       = CommonHelper.EnsureMaximumLength(name, 100);
            textPrompt = CommonHelper.EnsureMaximumLength(textPrompt, 300);

            var context = ObjectContextHelper.CurrentObjectContext;

            var checkoutAttributeLocalized = context.CheckoutAttributeLocalized.CreateObject();

            checkoutAttributeLocalized.CheckoutAttributeId = checkoutAttributeId;
            checkoutAttributeLocalized.LanguageId          = languageId;
            checkoutAttributeLocalized.Name       = name;
            checkoutAttributeLocalized.TextPrompt = textPrompt;

            context.CheckoutAttributeLocalized.AddObject(checkoutAttributeLocalized);
            context.SaveChanges();

            if (CheckoutAttributeManager.CacheEnabled)
            {
                NopRequestCache.RemoveByPattern(CHECKOUTATTRIBUTES_PATTERN_KEY);
                NopRequestCache.RemoveByPattern(CHECKOUTATTRIBUTEVALUES_PATTERN_KEY);
            }

            return(checkoutAttributeLocalized);
        }
示例#5
0
        /// <summary>
        /// Inserts a product template
        /// </summary>
        /// <param name="name">The name</param>
        /// <param name="templatePath">The template path</param>
        /// <param name="displayOrder">The display order</param>
        /// <param name="createdOn">The date and time of instance creation</param>
        /// <param name="updatedOn">The date and time of instance update</param>
        /// <returns>Product template</returns>
        public static ProductTemplate InsertProductTemplate(string name, string templatePath,
                                                            int displayOrder, DateTime createdOn, DateTime updatedOn)
        {
            name         = CommonHelper.EnsureMaximumLength(name, 100);
            templatePath = CommonHelper.EnsureMaximumLength(templatePath, 200);

            var context = ObjectContextHelper.CurrentObjectContext;

            var productTemplate = context.ProductTemplates.CreateObject();

            productTemplate.Name         = name;
            productTemplate.TemplatePath = templatePath;
            productTemplate.DisplayOrder = displayOrder;
            productTemplate.CreatedOn    = createdOn;
            productTemplate.UpdatedOn    = updatedOn;

            context.ProductTemplates.AddObject(productTemplate);
            context.SaveChanges();

            if (TemplateManager.CacheEnabled)
            {
                NopRequestCache.RemoveByPattern(PRODUCTTEMPLATES_PATTERN_KEY);
            }

            return(productTemplate);
        }
示例#6
0
        /// <summary>
        /// Inserts a localized product variant attribute value
        /// </summary>
        /// <param name="productVariantAttributeValueId">Product variant attribute value identifier</param>
        /// <param name="languageId">Language identifier</param>
        /// <param name="name">Name text</param>
        /// <returns>Localized product variant attribute value</returns>
        public static ProductVariantAttributeValueLocalized InsertProductVariantAttributeValueLocalized(int productVariantAttributeValueId,
                                                                                                        int languageId, string name)
        {
            name = CommonHelper.EnsureMaximumLength(name, 100);

            var context = ObjectContextHelper.CurrentObjectContext;

            var productVariantAttributeValueLocalized = context.ProductVariantAttributeValueLocalized.CreateObject();

            productVariantAttributeValueLocalized.ProductVariantAttributeValueId = productVariantAttributeValueId;
            productVariantAttributeValueLocalized.LanguageId = languageId;
            productVariantAttributeValueLocalized.Name       = name;

            context.ProductVariantAttributeValueLocalized.AddObject(productVariantAttributeValueLocalized);
            context.SaveChanges();

            if (ProductAttributeManager.CacheEnabled)
            {
                NopRequestCache.RemoveByPattern(PRODUCTATTRIBUTES_PATTERN_KEY);
                NopRequestCache.RemoveByPattern(PRODUCTVARIANTATTRIBUTES_PATTERN_KEY);
                NopRequestCache.RemoveByPattern(PRODUCTVARIANTATTRIBUTEVALUES_PATTERN_KEY);
            }

            return(productVariantAttributeValueLocalized);
        }
示例#7
0
        /// <summary>
        /// Inserts a country
        /// </summary>
        /// <param name="name">The name</param>
        /// <param name="allowsRegistration">A value indicating whether registration is allowed to this country</param>
        /// <param name="allowsBilling">A value indicating whether billing is allowed to this country</param>
        /// <param name="allowsShipping">A value indicating whether shipping is allowed to this country</param>
        /// <param name="twoLetterIsoCode">The two letter ISO code</param>
        /// <param name="threeLetterIsoCode">The three letter ISO code</param>
        /// <param name="numericIsoCode">The numeric ISO code</param>
        /// <param name="subjectToVAT">A value indicating whether customers in this country must be charged EU VAT</param>
        /// <param name="published">A value indicating whether the entity is published</param>
        /// <param name="displayOrder">The display order</param>
        /// <returns>Country</returns>
        public static Country InsertCountry(string name,
                                            bool allowsRegistration, bool allowsBilling, bool allowsShipping,
                                            string twoLetterIsoCode, string threeLetterIsoCode, int numericIsoCode,
                                            bool subjectToVAT, bool published, int displayOrder)
        {
            name               = CommonHelper.EnsureMaximumLength(name, 100);
            twoLetterIsoCode   = CommonHelper.EnsureMaximumLength(twoLetterIsoCode, 2);
            threeLetterIsoCode = CommonHelper.EnsureMaximumLength(threeLetterIsoCode, 3);

            var context = ObjectContextHelper.CurrentObjectContext;
            var country = context.Countries.CreateObject();

            country.Name = name;
            country.AllowsRegistration = allowsRegistration;
            country.AllowsBilling      = allowsBilling;
            country.AllowsShipping     = allowsShipping;
            country.TwoLetterIsoCode   = twoLetterIsoCode;
            country.ThreeLetterIsoCode = threeLetterIsoCode;
            country.NumericIsoCode     = numericIsoCode;
            country.SubjectToVAT       = subjectToVAT;
            country.Published          = published;
            country.DisplayOrder       = displayOrder;

            context.Countries.AddObject(country);
            context.SaveChanges();

            if (CountryManager.CacheEnabled)
            {
                NopRequestCache.RemoveByPattern(COUNTRIES_PATTERN_KEY);
            }
            return(country);
        }
示例#8
0
        /// <summary>
        /// Inserts an IP network
        /// </summary>
        /// <param name="startAddress">First IP address in the range</param>
        /// <param name="endAddress">Last IP address in the range </param>
        /// <param name="comment">Reason why the IP network was banned</param>
        /// <param name="ipException">Exception IPs in the range</param>
        /// <param name="createdOn">When the record was inserted</param>
        /// <param name="updatedOn">When the record was last updated</param>
        /// <returns></returns>
        public static BannedIpNetwork InsertBannedIpNetwork(string startAddress,
                                                            string endAddress, string comment, string ipException, DateTime createdOn,
                                                            DateTime updatedOn)
        {
            startAddress = startAddress.Trim();
            endAddress   = endAddress.Trim();

            startAddress = CommonHelper.EnsureMaximumLength(startAddress, 50);
            endAddress   = CommonHelper.EnsureMaximumLength(endAddress, 50);
            comment      = CommonHelper.EnsureMaximumLength(comment, 500);

            var context = ObjectContextHelper.CurrentObjectContext;

            var ipNetwork = context.BannedIpNetworks.CreateObject();

            ipNetwork.StartAddress = startAddress;
            ipNetwork.EndAddress   = endAddress;
            ipNetwork.Comment      = comment;
            ipNetwork.IpException  = ipException;
            ipNetwork.CreatedOn    = createdOn;
            ipNetwork.UpdatedOn    = updatedOn;

            context.BannedIpNetworks.AddObject(ipNetwork);
            context.SaveChanges();

            if (IpBlacklistManager.CacheEnabled)
            {
                NopRequestCache.RemoveByPattern(BLACKLIST_NETWORK_PATTERN_KEY);
            }
            return(ipNetwork);
        }
示例#9
0
        /// <summary>
        /// Inserts a localized category
        /// </summary>
        /// <param name="categoryId">Category identifier</param>
        /// <param name="languageId">Language identifier</param>
        /// <param name="name">Name text</param>
        /// <param name="description">Description text</param>
        /// <param name="metaKeywords">Meta keywords text</param>
        /// <param name="metaDescription">Meta descriptions text</param>
        /// <param name="metaTitle">Metat title text</param>
        /// <param name="seName">Se Name text</param>
        /// <returns>Category content</returns>
        public static CategoryLocalized InsertCategoryLocalized(int categoryId,
                                                                int languageId, string name, string description,
                                                                string metaKeywords, string metaDescription, string metaTitle,
                                                                string seName)
        {
            name            = CommonHelper.EnsureMaximumLength(name, 400);
            metaKeywords    = CommonHelper.EnsureMaximumLength(metaKeywords, 400);
            metaDescription = CommonHelper.EnsureMaximumLength(metaDescription, 4000);
            metaTitle       = CommonHelper.EnsureMaximumLength(metaTitle, 400);
            seName          = CommonHelper.EnsureMaximumLength(seName, 100);

            var context = ObjectContextHelper.CurrentObjectContext;

            var categoryLocalized = context.CategoryLocalized.CreateObject();

            categoryLocalized.CategoryId      = categoryId;
            categoryLocalized.LanguageId      = languageId;
            categoryLocalized.Name            = name;
            categoryLocalized.Description     = description;
            categoryLocalized.MetaKeywords    = metaKeywords;
            categoryLocalized.MetaDescription = metaDescription;
            categoryLocalized.MetaTitle       = metaTitle;
            categoryLocalized.SEName          = seName;

            context.CategoryLocalized.AddObject(categoryLocalized);
            context.SaveChanges();

            if (CategoryManager.CategoriesCacheEnabled)
            {
                NopRequestCache.RemoveByPattern(CATEGORIES_PATTERN_KEY);
            }

            return(categoryLocalized);
        }
示例#10
0
        /// <summary>
        /// Inserts a shipping rate computation method
        /// </summary>
        /// <param name="name">The name</param>
        /// <param name="description">The description</param>
        /// <param name="configureTemplatePath">The configure template path</param>
        /// <param name="className">The class name</param>
        /// <param name="isActive">The value indicating whether the method is active</param>
        /// <param name="displayOrder">The display order</param>
        /// <returns>Shipping rate computation method</returns>
        public static ShippingRateComputationMethod InsertShippingRateComputationMethod(string name,
                                                                                        string description, string configureTemplatePath, string className,
                                                                                        bool isActive, int displayOrder)
        {
            name                  = CommonHelper.EnsureMaximumLength(name, 100);
            description           = CommonHelper.EnsureMaximumLength(description, 4000);
            configureTemplatePath = CommonHelper.EnsureMaximumLength(configureTemplatePath, 500);
            className             = CommonHelper.EnsureMaximumLength(className, 500);

            var context = ObjectContextHelper.CurrentObjectContext;

            var shippingRateComputationMethod = context.ShippingRateComputationMethods.CreateObject();

            shippingRateComputationMethod.Name                  = name;
            shippingRateComputationMethod.Description           = description;
            shippingRateComputationMethod.ConfigureTemplatePath = configureTemplatePath;
            shippingRateComputationMethod.ClassName             = className;
            shippingRateComputationMethod.IsActive              = isActive;
            shippingRateComputationMethod.DisplayOrder          = displayOrder;

            context.ShippingRateComputationMethods.AddObject(shippingRateComputationMethod);
            context.SaveChanges();

            if (ShippingRateComputationMethodManager.CacheEnabled)
            {
                NopRequestCache.RemoveByPattern(SHIPPINGRATECOMPUTATIONMETHODS_PATTERN_KEY);
            }
            return(shippingRateComputationMethod);
        }
示例#11
0
        /// <summary>
        /// Updates an IP address
        /// </summary>
        /// <param name="ipAddressId">IP address unique identifier</param>
        /// <param name="address">IP address</param>
        /// <param name="comment">Reason why the IP was banned</param>
        /// <param name="createdOn">When the record was inserted</param>
        /// <param name="updatedOn">When the record was last updated</param>
        /// <returns>IP address</returns>
        public static BannedIpAddress UpdateBannedIpAddress(int ipAddressId, string address,
                                                            string comment, DateTime createdOn, DateTime updatedOn)
        {
            address = address.Trim();

            address = CommonHelper.EnsureMaximumLength(address, 50);
            comment = CommonHelper.EnsureMaximumLength(comment, 500);

            var ipAddress = GetBannedIpAddressById(ipAddressId);

            if (ipAddress == null)
            {
                return(null);
            }

            var context = ObjectContextHelper.CurrentObjectContext;

            if (!context.IsAttached(ipAddress))
            {
                context.BannedIpAddresses.Attach(ipAddress);
            }

            ipAddress.Address   = address;
            ipAddress.Comment   = comment;
            ipAddress.CreatedOn = createdOn;
            ipAddress.UpdatedOn = updatedOn;
            context.SaveChanges();

            if (IpBlacklistManager.CacheEnabled)
            {
                NopRequestCache.RemoveByPattern(BLACKLIST_IP_PATTERN_KEY);
            }
            return(ipAddress);
        }
        /// <summary>
        /// Updates the product specification attribute mapping
        /// </summary>
        /// <param name="productSpecificationAttributeId">product specification attribute mapping identifier</param>
        /// <param name="productId">Product identifier</param>
        /// <param name="specificationAttributeOptionId">Specification attribute identifier</param>
        /// <param name="allowFiltering">Allow product filtering by this attribute</param>
        /// <param name="showOnProductPage">Show the attribute on the product page</param>
        /// <param name="displayOrder">The display order</param>
        /// <returns>Product specification attribute mapping</returns>
        public static ProductSpecificationAttribute UpdateProductSpecificationAttribute(int productSpecificationAttributeId,
                                                                                        int productId, int specificationAttributeOptionId, bool allowFiltering, bool showOnProductPage, int displayOrder)
        {
            var productSpecificationAttribute = GetProductSpecificationAttributeById(productSpecificationAttributeId);

            if (productSpecificationAttribute == null)
            {
                return(null);
            }

            var context = ObjectContextHelper.CurrentObjectContext;

            if (!context.IsAttached(productSpecificationAttribute))
            {
                context.ProductSpecificationAttributes.Attach(productSpecificationAttribute);
            }

            productSpecificationAttribute.ProductId = productId;
            productSpecificationAttribute.SpecificationAttributeOptionId = specificationAttributeOptionId;
            productSpecificationAttribute.AllowFiltering    = allowFiltering;
            productSpecificationAttribute.ShowOnProductPage = showOnProductPage;
            productSpecificationAttribute.DisplayOrder      = displayOrder;
            context.SaveChanges();

            if (SpecificationAttributeManager.CacheEnabled)
            {
                NopRequestCache.RemoveByPattern(SPECIFICATIONATTRIBUTEOPTION_PATTERN_KEY);
                NopRequestCache.RemoveByPattern(SPECIFICATIONATTRIBUTEOPTION_PATTERN_KEY);
                NopRequestCache.RemoveByPattern(PRODUCTSPECIFICATIONATTRIBUTE_PATTERN_KEY);
            }
            return(productSpecificationAttribute);
        }
        /// <summary>
        /// Deletes a product specification attribute mapping
        /// </summary>
        /// <param name="productSpecificationAttributeId">Product specification attribute identifier</param>
        public static void DeleteProductSpecificationAttribute(int productSpecificationAttributeId)
        {
            var productSpecificationAttribute = GetProductSpecificationAttributeById(productSpecificationAttributeId);

            if (productSpecificationAttribute == null)
            {
                return;
            }

            var context = ObjectContextHelper.CurrentObjectContext;

            if (!context.IsAttached(productSpecificationAttribute))
            {
                context.ProductSpecificationAttributes.Attach(productSpecificationAttribute);
            }
            context.DeleteObject(productSpecificationAttribute);
            context.SaveChanges();

            if (SpecificationAttributeManager.CacheEnabled)
            {
                NopRequestCache.RemoveByPattern(SPECIFICATIONATTRIBUTEOPTION_PATTERN_KEY);
                NopRequestCache.RemoveByPattern(SPECIFICATIONATTRIBUTEOPTION_PATTERN_KEY);
                NopRequestCache.RemoveByPattern(PRODUCTSPECIFICATIONATTRIBUTE_PATTERN_KEY);
            }
        }
        /// <summary>
        /// Inserts a localized specification attribute option
        /// </summary>
        /// <param name="specificationAttributeOptionId">Specification attribute option identifier</param>
        /// <param name="languageId">Language identifier</param>
        /// <param name="name">Name text</param>
        /// <returns>Localized specification attribute option</returns>
        public static SpecificationAttributeOptionLocalized InsertSpecificationAttributeOptionLocalized(int specificationAttributeOptionId,
                                                                                                        int languageId, string name)
        {
            name = CommonHelper.EnsureMaximumLength(name, 500);

            var context = ObjectContextHelper.CurrentObjectContext;

            var specificationAttributeOptionLocalized = context.SpecificationAttributeOptionLocalized.CreateObject();

            specificationAttributeOptionLocalized.SpecificationAttributeOptionId = specificationAttributeOptionId;
            specificationAttributeOptionLocalized.LanguageId = languageId;
            specificationAttributeOptionLocalized.Name       = name;

            context.SpecificationAttributeOptionLocalized.AddObject(specificationAttributeOptionLocalized);
            context.SaveChanges();

            if (SpecificationAttributeManager.CacheEnabled)
            {
                NopRequestCache.RemoveByPattern(SPECIFICATIONATTRIBUTE_PATTERN_KEY);
                NopRequestCache.RemoveByPattern(SPECIFICATIONATTRIBUTEOPTION_PATTERN_KEY);
                NopRequestCache.RemoveByPattern(PRODUCTSPECIFICATIONATTRIBUTE_PATTERN_KEY);
            }

            return(specificationAttributeOptionLocalized);
        }
示例#15
0
        /// <summary>
        /// Deletes a product variant attribute value
        /// </summary>
        /// <param name="productVariantAttributeValueId">Product variant attribute value identifier</param>
        public static void DeleteProductVariantAttributeValue(int productVariantAttributeValueId)
        {
            var productVariantAttributeValue = GetProductVariantAttributeValueById(productVariantAttributeValueId);

            if (productVariantAttributeValue == null)
            {
                return;
            }

            var context = ObjectContextHelper.CurrentObjectContext;

            if (!context.IsAttached(productVariantAttributeValue))
            {
                context.ProductVariantAttributeValues.Attach(productVariantAttributeValue);
            }
            context.DeleteObject(productVariantAttributeValue);
            context.SaveChanges();

            if (ProductAttributeManager.CacheEnabled)
            {
                NopRequestCache.RemoveByPattern(PRODUCTATTRIBUTES_PATTERN_KEY);
                NopRequestCache.RemoveByPattern(PRODUCTVARIANTATTRIBUTES_PATTERN_KEY);
                NopRequestCache.RemoveByPattern(PRODUCTVARIANTATTRIBUTEVALUES_PATTERN_KEY);
            }
        }
示例#16
0
        /// <summary>
        /// Deletes a product category mapping
        /// </summary>
        /// <param name="productCategoryId">Product category identifier</param>
        public static void DeleteProductCategory(int productCategoryId)
        {
            if (productCategoryId == 0)
            {
                return;
            }

            var productCategory = GetProductCategoryById(productCategoryId);

            if (productCategory == null)
            {
                return;
            }

            var context = ObjectContextHelper.CurrentObjectContext;

            if (!context.IsAttached(productCategory))
            {
                context.ProductCategories.Attach(productCategory);
            }
            context.DeleteObject(productCategory);
            context.SaveChanges();

            if (CategoryManager.CategoriesCacheEnabled || CategoryManager.MappingsCacheEnabled)
            {
                NopRequestCache.RemoveByPattern(CATEGORIES_PATTERN_KEY);
                NopRequestCache.RemoveByPattern(PRODUCTCATEGORIES_PATTERN_KEY);
            }
        }
示例#17
0
        /// <summary>
        /// Inserts a product variant attribute value
        /// </summary>
        /// <param name="productVariantAttributeId">The product variant attribute mapping identifier</param>
        /// <param name="name">The product variant attribute name</param>
        /// <param name="priceAdjustment">The price adjustment</param>
        /// <param name="weightAdjustment">The weight adjustment</param>
        /// <param name="isPreSelected">The value indicating whether the value is pre-selected</param>
        /// <param name="displayOrder">The display order</param>
        /// <returns>Product variant attribute value</returns>
        public static ProductVariantAttributeValue InsertProductVariantAttributeValue(int productVariantAttributeId,
                                                                                      string name, decimal priceAdjustment, decimal weightAdjustment,
                                                                                      bool isPreSelected, int displayOrder)
        {
            name = CommonHelper.EnsureMaximumLength(name, 100);

            var context = ObjectContextHelper.CurrentObjectContext;

            var productVariantAttributeValue = context.ProductVariantAttributeValues.CreateObject();

            productVariantAttributeValue.ProductVariantAttributeId = productVariantAttributeId;
            productVariantAttributeValue.Name             = name;
            productVariantAttributeValue.PriceAdjustment  = priceAdjustment;
            productVariantAttributeValue.WeightAdjustment = weightAdjustment;
            productVariantAttributeValue.IsPreSelected    = isPreSelected;
            productVariantAttributeValue.DisplayOrder     = displayOrder;

            context.ProductVariantAttributeValues.AddObject(productVariantAttributeValue);
            context.SaveChanges();

            if (ProductAttributeManager.CacheEnabled)
            {
                NopRequestCache.RemoveByPattern(PRODUCTATTRIBUTES_PATTERN_KEY);
                NopRequestCache.RemoveByPattern(PRODUCTVARIANTATTRIBUTES_PATTERN_KEY);
                NopRequestCache.RemoveByPattern(PRODUCTVARIANTATTRIBUTEVALUES_PATTERN_KEY);
            }

            return(productVariantAttributeValue);
        }
示例#18
0
        /// <summary>
        /// Updates the product category mapping
        /// </summary>
        /// <param name="productCategoryId">Product category mapping  identifier</param>
        /// <param name="productId">Product identifier</param>
        /// <param name="categoryId">Category identifier</param>
        /// <param name="isFeaturedProduct">A value indicating whether the product is featured</param>
        /// <param name="displayOrder">The display order</param>
        /// <returns>Product category mapping </returns>
        public static ProductCategory UpdateProductCategory(int productCategoryId,
                                                            int productId, int categoryId, bool isFeaturedProduct, int displayOrder)
        {
            var productCategory = GetProductCategoryById(productCategoryId);

            if (productCategory == null)
            {
                return(null);
            }

            var context = ObjectContextHelper.CurrentObjectContext;

            if (!context.IsAttached(productCategory))
            {
                context.ProductCategories.Attach(productCategory);
            }

            productCategory.ProductId         = productId;
            productCategory.CategoryId        = categoryId;
            productCategory.IsFeaturedProduct = isFeaturedProduct;
            productCategory.DisplayOrder      = displayOrder;
            context.SaveChanges();

            if (CategoryManager.CategoriesCacheEnabled || CategoryManager.MappingsCacheEnabled)
            {
                NopRequestCache.RemoveByPattern(CATEGORIES_PATTERN_KEY);
                NopRequestCache.RemoveByPattern(PRODUCTCATEGORIES_PATTERN_KEY);
            }
            return(productCategory);
        }
示例#19
0
        /// <summary>
        /// Inserts a news item
        /// </summary>
        /// <param name="languageId">The language identifier</param>
        /// <param name="title">The news title</param>
        /// <param name="shortText">The short text</param>
        /// <param name="fullText">The full text</param>
        /// <param name="published">A value indicating whether the entity is published</param>
        /// <param name="allowComments">A value indicating whether the entity allows comments</param>
        /// <param name="createdOn">The date and time of instance creation</param>
        /// <returns>News item</returns>
        public static News InsertNews(int languageId, string title, string shortText,
                                      string fullText, bool published, bool allowComments, DateTime createdOn)
        {
            title     = CommonHelper.EnsureMaximumLength(title, 1000);
            shortText = CommonHelper.EnsureMaximumLength(shortText, 4000);

            var context = ObjectContextHelper.CurrentObjectContext;

            var news = context.News.CreateObject();

            news.LanguageId    = languageId;
            news.Title         = title;
            news.Short         = shortText;
            news.Full          = fullText;
            news.Published     = published;
            news.AllowComments = allowComments;
            news.CreatedOn     = createdOn;

            context.News.AddObject(news);
            context.SaveChanges();

            if (NewsManager.CacheEnabled)
            {
                NopRequestCache.RemoveByPattern(NEWS_PATTERN_KEY);
            }

            return(news);
        }
示例#20
0
        /// <summary>
        /// Updates an activity log type item
        /// </summary>
        /// <param name="activityLogTypeId">Activity log type identifier</param>
        /// <param name="systemKeyword">The system keyword</param>
        /// <param name="name">The display name</param>
        /// <param name="enabled">Value indicating whether the activity log type is enabled</param>
        /// <returns>Activity log type item</returns>
        public static ActivityLogType UpdateActivityType(int activityLogTypeId,
                                                         string systemKeyword, string name, bool enabled)
        {
            systemKeyword = CommonHelper.EnsureMaximumLength(systemKeyword, 50);
            name          = CommonHelper.EnsureMaximumLength(name, 100);

            var activityLogType = GetActivityTypeById(activityLogTypeId);

            if (activityLogType == null)
            {
                return(null);
            }

            var context = ObjectContextHelper.CurrentObjectContext;

            if (!context.IsAttached(activityLogType))
            {
                context.ActivityLogTypes.Attach(activityLogType);
            }

            activityLogType.SystemKeyword = systemKeyword;
            activityLogType.Name          = name;
            activityLogType.Enabled       = enabled;

            context.SaveChanges();

            if (NopRequestCache.IsEnabled)
            {
                NopRequestCache.RemoveByPattern(ACTIVITYTYPE_PATTERN_KEY);
            }

            return(activityLogType);
        }
示例#21
0
        /// <summary>
        /// Inserts a checkout attribute
        /// </summary>
        /// <param name="name">Name</param>
        /// <param name="textPrompt">Text prompt</param>
        /// <param name="isRequired">Value indicating whether the entity is required</param>
        /// <param name="shippableProductRequired">Value indicating whether shippable products are required in order to display this attribute</param>
        /// <param name="isTaxExempt">Value indicating whether the attribute is marked as tax exempt</param>
        /// <param name="taxCategoryId">Tax category identifier</param>
        /// <param name="attributeControlTypeId">Attribute control type identifier</param>
        /// <param name="displayOrder">Display order</param>
        /// <returns>Checkout attribute</returns>
        public static CheckoutAttribute InsertCheckoutAttribute(string name,
                                                                string textPrompt, bool isRequired, bool shippableProductRequired,
                                                                bool isTaxExempt, int taxCategoryId, int attributeControlTypeId,
                                                                int displayOrder)
        {
            name       = CommonHelper.EnsureMaximumLength(name, 100);
            textPrompt = CommonHelper.EnsureMaximumLength(textPrompt, 300);

            var context = ObjectContextHelper.CurrentObjectContext;

            var checkoutAttribute = context.CheckoutAttributes.CreateObject();

            checkoutAttribute.Name       = name;
            checkoutAttribute.TextPrompt = textPrompt;
            checkoutAttribute.IsRequired = isRequired;
            checkoutAttribute.ShippableProductRequired = shippableProductRequired;
            checkoutAttribute.IsTaxExempt            = isTaxExempt;
            checkoutAttribute.TaxCategoryId          = taxCategoryId;
            checkoutAttribute.AttributeControlTypeId = attributeControlTypeId;
            checkoutAttribute.DisplayOrder           = displayOrder;

            context.CheckoutAttributes.AddObject(checkoutAttribute);
            context.SaveChanges();

            if (CheckoutAttributeManager.CacheEnabled)
            {
                NopRequestCache.RemoveByPattern(CHECKOUTATTRIBUTES_PATTERN_KEY);
                NopRequestCache.RemoveByPattern(CHECKOUTATTRIBUTEVALUES_PATTERN_KEY);
            }
            return(checkoutAttribute);
        }
示例#22
0
        /// <summary>
        /// Updates the measure dimension
        /// </summary>
        /// <param name="measureDimensionId">Measure dimension identifier</param>
        /// <param name="name">The name</param>
        /// <param name="systemKeyword">The system keyword</param>
        /// <param name="ratio">The ratio</param>
        /// <param name="displayOrder">The display order</param>
        /// <returns>A measure dimension</returns>
        public static MeasureDimension UpdateMeasureDimension(int measureDimensionId,
                                                              string name, string systemKeyword, decimal ratio, int displayOrder)
        {
            name          = CommonHelper.EnsureMaximumLength(name, 100);
            systemKeyword = CommonHelper.EnsureMaximumLength(systemKeyword, 100);

            var measure = GetMeasureDimensionById(measureDimensionId);

            if (measure == null)
            {
                return(null);
            }

            var context = ObjectContextHelper.CurrentObjectContext;

            if (!context.IsAttached(measure))
            {
                context.MeasureDimensions.Attach(measure);
            }

            measure.Name          = name;
            measure.SystemKeyword = systemKeyword;
            measure.Ratio         = ratio;
            measure.DisplayOrder  = displayOrder;
            context.SaveChanges();

            if (MeasureManager.CacheEnabled)
            {
                NopRequestCache.RemoveByPattern(MEASUREDIMENSIONS_PATTERN_KEY);
            }
            return(measure);
        }
示例#23
0
        /// <summary>
        /// Inserts a checkout attribute value
        /// </summary>
        /// <param name="checkoutAttributeId">The checkout attribute identifier</param>
        /// <param name="name">The checkout attribute name</param>
        /// <param name="priceAdjustment">The price adjustment</param>
        /// <param name="weightAdjustment">The weight adjustment</param>
        /// <param name="isPreSelected">The value indicating whether the value is pre-selected</param>
        /// <param name="displayOrder">The display order</param>
        /// <returns>Checkout attribute value</returns>
        public static CheckoutAttributeValue InsertCheckoutAttributeValue(int checkoutAttributeId,
                                                                          string name, decimal priceAdjustment, decimal weightAdjustment,
                                                                          bool isPreSelected, int displayOrder)
        {
            name = CommonHelper.EnsureMaximumLength(name, 100);

            var context = ObjectContextHelper.CurrentObjectContext;

            var checkoutAttributeValue = context.CheckoutAttributeValues.CreateObject();

            checkoutAttributeValue.CheckoutAttributeId = checkoutAttributeId;
            checkoutAttributeValue.Name             = name;
            checkoutAttributeValue.PriceAdjustment  = priceAdjustment;
            checkoutAttributeValue.WeightAdjustment = weightAdjustment;
            checkoutAttributeValue.IsPreSelected    = isPreSelected;
            checkoutAttributeValue.DisplayOrder     = displayOrder;

            context.CheckoutAttributeValues.AddObject(checkoutAttributeValue);
            context.SaveChanges();

            if (CheckoutAttributeManager.CacheEnabled)
            {
                NopRequestCache.RemoveByPattern(CHECKOUTATTRIBUTES_PATTERN_KEY);
                NopRequestCache.RemoveByPattern(CHECKOUTATTRIBUTEVALUES_PATTERN_KEY);
            }

            return(checkoutAttributeValue);
        }
示例#24
0
        /// <summary>
        /// Updates the measure weight
        /// </summary>
        /// <param name="measureWeightId">Measure weight identifier</param>
        /// <param name="name">The name</param>
        /// <param name="systemKeyword">The system keyword</param>
        /// <param name="ratio">The ratio</param>
        /// <param name="displayOrder">The display order</param>
        /// <returns>A measure weight</returns>
        public static MeasureWeight UpdateMeasureWeight(int measureWeightId, string name,
                                                        string systemKeyword, decimal ratio, int displayOrder)
        {
            name          = CommonHelper.EnsureMaximumLength(name, 100);
            systemKeyword = CommonHelper.EnsureMaximumLength(systemKeyword, 100);

            var weight = GetMeasureWeightById(measureWeightId);

            if (weight == null)
            {
                return(null);
            }

            var context = ObjectContextHelper.CurrentObjectContext;

            if (!context.IsAttached(weight))
            {
                context.MeasureWeights.Attach(weight);
            }

            weight.Name          = name;
            weight.SystemKeyword = systemKeyword;
            weight.Ratio         = ratio;
            weight.DisplayOrder  = displayOrder;
            context.SaveChanges();

            if (MeasureManager.CacheEnabled)
            {
                NopRequestCache.RemoveByPattern(MEASUREWEIGHTS_PATTERN_KEY);
            }
            return(weight);
        }
示例#25
0
        /// <summary>
        /// Updates the product template
        /// </summary>
        /// <param name="productTemplateId">The product template identifier</param>
        /// <param name="name">The name</param>
        /// <param name="templatePath">The template path</param>
        /// <param name="displayOrder">The display order</param>
        /// <param name="createdOn">The date and time of instance creation</param>
        /// <param name="updatedOn">The date and time of instance update</param>
        /// <returns>Product template</returns>
        public static ProductTemplate UpdateProductTemplate(int productTemplateId,
                                                            string name, string templatePath, int displayOrder,
                                                            DateTime createdOn, DateTime updatedOn)
        {
            name         = CommonHelper.EnsureMaximumLength(name, 100);
            templatePath = CommonHelper.EnsureMaximumLength(templatePath, 200);

            var productTemplate = GetProductTemplateById(productTemplateId);

            if (productTemplate == null)
            {
                return(null);
            }

            var context = ObjectContextHelper.CurrentObjectContext;

            if (!context.IsAttached(productTemplate))
            {
                context.ProductTemplates.Attach(productTemplate);
            }

            productTemplate.Name         = name;
            productTemplate.TemplatePath = templatePath;
            productTemplate.DisplayOrder = displayOrder;
            productTemplate.CreatedOn    = createdOn;
            productTemplate.UpdatedOn    = updatedOn;
            context.SaveChanges();

            if (TemplateManager.CacheEnabled)
            {
                NopRequestCache.RemoveByPattern(PRODUCTTEMPLATES_PATTERN_KEY);
            }

            return(productTemplate);
        }
示例#26
0
        /// <summary>
        /// Updates the product attribute
        /// </summary>
        /// <param name="productAttributeId">Product attribute identifier</param>
        /// <param name="name">The name</param>
        /// <param name="description">The description</param>
        /// <returns>Product attribute </returns>
        public static ProductAttribute UpdateProductAttribute(int productAttributeId,
                                                              string name, string description)
        {
            name        = CommonHelper.EnsureMaximumLength(name, 100);
            description = CommonHelper.EnsureMaximumLength(description, 400);

            var productAttribute = GetProductAttributeById(productAttributeId);

            if (productAttribute == null)
            {
                return(null);
            }

            var context = ObjectContextHelper.CurrentObjectContext;

            if (!context.IsAttached(productAttribute))
            {
                context.ProductAttributes.Attach(productAttribute);
            }

            productAttribute.Name        = name;
            productAttribute.Description = description;
            context.SaveChanges();

            if (ProductAttributeManager.CacheEnabled)
            {
                NopRequestCache.RemoveByPattern(PRODUCTATTRIBUTES_PATTERN_KEY);
                NopRequestCache.RemoveByPattern(PRODUCTVARIANTATTRIBUTES_PATTERN_KEY);
                NopRequestCache.RemoveByPattern(PRODUCTVARIANTATTRIBUTEVALUES_PATTERN_KEY);
            }

            return(productAttribute);
        }
示例#27
0
        /// <summary>
        /// Removes a discount from a product variant
        /// </summary>
        /// <param name="productVariantId">Product variant identifier</param>
        /// <param name="discountId">Discount identifier</param>
        public static void RemoveDiscountFromProductVariant(int productVariantId, int discountId)
        {
            var productVariant = ProductManager.GetProductVariantById(productVariantId);

            if (productVariant == null)
            {
                return;
            }

            var discount = GetDiscountById(discountId);

            if (discount == null)
            {
                return;
            }

            var context = ObjectContextHelper.CurrentObjectContext;

            if (!context.IsAttached(productVariant))
            {
                context.ProductVariants.Attach(productVariant);
            }
            if (!context.IsAttached(discount))
            {
                context.Discounts.Attach(discount);
            }

            productVariant.NpDiscounts.Remove(discount);
            context.SaveChanges();

            if (DiscountManager.CacheEnabled)
            {
                NopRequestCache.RemoveByPattern(DISCOUNTS_PATTERN_KEY);
            }
        }
示例#28
0
        /// <summary>
        /// Inserts a product variant attribute mapping
        /// </summary>
        /// <param name="productVariantId">The product variant identifier</param>
        /// <param name="productAttributeId">The product attribute identifier</param>
        /// <param name="textPrompt">The text prompt</param>
        /// <param name="isRequired">The value indicating whether the entity is required</param>
        /// <param name="attributeControlType">The attribute control type</param>
        /// <param name="displayOrder">The display order</param>
        /// <returns>Product variant attribute mapping</returns>
        public static ProductVariantAttribute InsertProductVariantAttribute(int productVariantId,
                                                                            int productAttributeId, string textPrompt, bool isRequired, AttributeControlTypeEnum attributeControlType, int displayOrder)
        {
            textPrompt = CommonHelper.EnsureMaximumLength(textPrompt, 200);

            var context = ObjectContextHelper.CurrentObjectContext;

            var productVariantAttribute = context.ProductVariantAttributes.CreateObject();

            productVariantAttribute.ProductVariantId       = productVariantId;
            productVariantAttribute.ProductAttributeId     = productAttributeId;
            productVariantAttribute.TextPrompt             = textPrompt;
            productVariantAttribute.IsRequired             = isRequired;
            productVariantAttribute.AttributeControlTypeId = (int)attributeControlType;
            productVariantAttribute.DisplayOrder           = displayOrder;

            context.ProductVariantAttributes.AddObject(productVariantAttribute);
            context.SaveChanges();

            if (ProductAttributeManager.CacheEnabled)
            {
                NopRequestCache.RemoveByPattern(PRODUCTATTRIBUTES_PATTERN_KEY);
                NopRequestCache.RemoveByPattern(PRODUCTVARIANTATTRIBUTES_PATTERN_KEY);
                NopRequestCache.RemoveByPattern(PRODUCTVARIANTATTRIBUTEVALUES_PATTERN_KEY);
            }

            return(productVariantAttribute);
        }
示例#29
0
        /// <summary>
        /// Updates the shipping method
        /// </summary>
        /// <param name="shippingMethodId">The shipping method identifier</param>
        /// <param name="name">The name</param>
        /// <param name="description">The description</param>
        /// <param name="displayOrder">The display order</param>
        /// <returns>Shipping method</returns>
        public static ShippingMethod UpdateShippingMethod(int shippingMethodId,
                                                          string name, string description, int displayOrder)
        {
            name        = CommonHelper.EnsureMaximumLength(name, 100);
            description = CommonHelper.EnsureMaximumLength(description, 2000);

            var shippingMethod = GetShippingMethodById(shippingMethodId);

            if (shippingMethod == null)
            {
                return(null);
            }

            var context = ObjectContextHelper.CurrentObjectContext;

            if (!context.IsAttached(shippingMethod))
            {
                context.ShippingMethods.Attach(shippingMethod);
            }

            shippingMethod.Name         = name;
            shippingMethod.Description  = description;
            shippingMethod.DisplayOrder = displayOrder;
            context.SaveChanges();

            if (ShippingMethodManager.CacheEnabled)
            {
                NopRequestCache.RemoveByPattern(SHIPPINGMETHODS_PATTERN_KEY);
            }

            return(shippingMethod);
        }
        /// <summary>
        /// Inserts a specification attribute option
        /// </summary>
        /// <param name="specificationAttributeId">The specification attribute identifier</param>
        /// <param name="name">The name</param>
        /// <param name="displayOrder">Display order</param>
        /// <returns>Specification attribute option</returns>
        public static SpecificationAttributeOption InsertSpecificationAttributeOption(int specificationAttributeId,
                                                                                      string name, int displayOrder)
        {
            name = CommonHelper.EnsureMaximumLength(name, 500);

            var context = ObjectContextHelper.CurrentObjectContext;

            var specificationAttributeOption = context.SpecificationAttributeOptions.CreateObject();

            specificationAttributeOption.SpecificationAttributeId = specificationAttributeId;
            specificationAttributeOption.Name         = name;
            specificationAttributeOption.DisplayOrder = displayOrder;

            context.SpecificationAttributeOptions.AddObject(specificationAttributeOption);
            context.SaveChanges();

            if (SpecificationAttributeManager.CacheEnabled)
            {
                NopRequestCache.RemoveByPattern(SPECIFICATIONATTRIBUTEOPTION_PATTERN_KEY);
                NopRequestCache.RemoveByPattern(SPECIFICATIONATTRIBUTEOPTION_PATTERN_KEY);
                NopRequestCache.RemoveByPattern(PRODUCTSPECIFICATIONATTRIBUTE_PATTERN_KEY);
            }

            return(specificationAttributeOption);
        }