AI agents: the content index is at /llms.txt. Every page is also available as Markdown — send the request header Accept: text/markdown, or append .md to the page URL.
Xperience Docs

Cookie consent

We use necessary cookies (opens in a new tab) to run our website and improve your experience while browsing. Additional cookies are only used with your consent. You may revoke your consent on the Cookies Policy (opens in a new tab) page or in your browser at any time.

Configure (opens in a new tab)
  • Documentation
    InstallationUsing the Xperience interfaceDeveloping websitesConfiguring XperienceManaging usersSecuring websitesDeploying websitesManaging website contentMultilingual websitesMacro expressionsExternal utilitiesIntegrating 3rd party systemsCustom developmentE-commerce featuresOn-line marketing featuresRelease notes - Xperience 13Xperience terminology glossary
  • Tutorial
    Using the Xperience interfaceDeveloper tutorialBusiness tutorialResource hub for marketers
  • API Examples
    ConfigurationContent managementDevelopmentE-commerceOn-line marketingSocial media
  1. Home
  2. E-commerce
  3. Discounts

Discounts


Was this page helpful?

Send us feedback Go back to top
  • Community Questions & Answers (opens in a new tab)
  • Contact support (opens in a new tab)

List of examples:

  • Buy X Get Y discounts
    • Creating a Buy X Get Y discount
    • Updating a Buy X Get Y discount
    • Updating multiple Buy X Get Y discounts
    • Adding coupon codes to a Buy X Get Y discount
    • Deleting a Buy X Get Y discount
  • Catalog discounts
    • Creating a catalog discount
    • Updating a catalog discount
    • Updating multiple catalog discounts
    • Deleting a catalog discount
  • Order discounts
    • Creating an order discount
    • Updating an order discount
    • Updating multiple order discounts
    • Deleting an order discount
  • Free shipping offers
    • Creating a free shipping offer
    • Updating a free shipping offer
    • Updating multiple free shipping offer
    • Deleting a free shipping offer
  • Volume discounts
    • Creating a volume discount
    • Updating a volume discount
    • Updating multiple volume discounts
    • Deleting a volume discount
  • Product coupons
    • Creating a product coupon
    • Adding coupon codes to a product coupon
    • Updating a product coupon
    • Updating multiple product coupons
    • Removing products from a product coupon
    • Applying a product coupon to product sections
    • Applying a product coupon to departments
    • Applying a product coupon to brands
    • Applying a product coupon to collections
    • Deleting a product coupon

Buy X Get Y discounts

Creating a Buy X Get Y discount

C#
// Gets a product for a 2+1 free Buy X Get Y discount
SKUInfo product = SKUInfo.Provider.Get()
                               .WhereStartsWith("SKUName", "New")
                               .TopN(1)
                               .FirstOrDefault();

if (product != null)
{
    // Creates a new Buy X Get Y discount object and sets its properties
    MultiBuyDiscountInfo newDiscount = new MultiBuyDiscountInfo()
    {
        MultiBuyDiscountName = "MyDiscount",
        MultiBuyDiscountDisplayName = "My Discount",
        MultiBuyDiscountApplyFurtherDiscounts = true,
        MultiBuyDiscountMinimumBuyCount = 2,
        MultiBuyDiscountApplyToSKUID = product.SKUID,
        MultiBuyDiscountIsFlat = false,
        MultiBuyDiscountValue = 100,
        MultiBuyDiscountAutoAddEnabled = true,
        MultiBuyDiscountEnabled = true,
        MultiBuyDiscountCustomerRestriction = DiscountCustomerEnum.All,
        MultiBuyDiscountSiteID = SiteContext.CurrentSiteID
    };

    // Saves the Buy X Get Y discount to the database
    MultiBuyDiscountInfo.Provider.Set(newDiscount);

    // Creates a new relationship of a product that needs to be bought and the discount
    MultiBuyDiscountSKUInfo newSkuDiscount = new MultiBuyDiscountSKUInfo();

    // Sets the product-discount relationship properties
    newSkuDiscount.MultiBuyDiscountID = newDiscount.MultiBuyDiscountID;
    newSkuDiscount.SKUID = product.SKUID;

    // Saves the product-discount relationship to the database
    MultiBuyDiscountSKUInfo.Provider.Set(newSkuDiscount);
}
> Back to list of examples

Updating a Buy X Get Y discount

C#
// Gets the first Buy X Get Y discount that contains 'MyDiscount' on the current site
MultiBuyDiscountInfo discount = MultiBuyDiscountInfoProvider.GetMultiBuyDiscounts(SiteContext.CurrentSiteID)
                                                            .WhereContains("MultiBuyDiscountName", "MyDiscount")
                                                            .TopN(1)
                                                            .FirstOrDefault();

if (discount != null)
{
    // Updates the Buy X Get Y discount properties
    discount.MultiBuyDiscountMinimumBuyCount = 3;

    // Saves the changes to the database
    MultiBuyDiscountInfo.Provider.Set(discount);
}
> Back to list of examples

Updating multiple Buy X Get Y discounts

C#
// Gets all enabled Buy X Get Y discounts on the current site
var discounts = MultiBuyDiscountInfoProvider.GetMultiBuyDiscounts(SiteContext.CurrentSiteID)
                                            .WhereTrue("MultiBuyDiscountEnabled");

// Loops through the Buy X Get Y discounts
foreach (MultiBuyDiscountInfo discount in discounts)
{
    // Updates the Buy X Get Y discounts properties
    discount.MultiBuyDiscountEnabled = false;

    // Saves the changes to the database
    MultiBuyDiscountInfo.Provider.Set(discount);
}
> Back to list of examples

Adding coupon codes to a Buy X Get Y discount

C#
// Gets the first Buy X Get Y discount on the current site whose name contains 'MyDiscount'
MultiBuyDiscountInfo discount = MultiBuyDiscountInfoProvider.GetMultiBuyDiscounts(SiteContext.CurrentSiteID)
                                                            .WhereContains("MultiBuyDiscountName", "MyDiscount")
                                                            .TopN(1)
                                                            .FirstOrDefault();

if (discount != null)
{
    // Enables using of coupon codes for the Buy X Get Y discount
    discount.MultiBuyDiscountUsesCoupons = true;

    // Saves the change to the database
    MultiBuyDiscountInfo.Provider.Set(discount);

    // Prepares a query that gets all existing coupon codes from the current site
    var existingCouponCodeQuery = ECommerceHelper.GetAllCouponCodesQuery(SiteContext.CurrentSiteID);

    // Creates a cache of coupon codes on the current site
    var existingCodes = existingCouponCodeQuery.GetListResult<string>();

    // Prepares an instance of a class that checks against existing coupon codes to avoid duplicates
    var coudeUniquenessChecker = new CodeUniquenessChecker(existingCodes);

    // Initializes a coupon code generator
    RandomCodeGenerator codeGenerator = new RandomCodeGenerator(coudeUniquenessChecker, "**********");

    // Loops to generate 300 coupon codes
    for (int i = 0; i < 300; i++)
    {
        // Generates a new unique code text
        string code = codeGenerator.GenerateCode();

        // Creates a coupon code and adds it to the discount
        MultiBuyCouponCodeInfoProvider.CreateCoupon(discount, code, 1);
    }
}
> Back to list of examples

Deleting a Buy X Get Y discount

C#
// Gets the first Buy X Get Y discount that contains 'MyDiscount' on the current site
MultiBuyDiscountInfo discount = MultiBuyDiscountInfoProvider.GetMultiBuyDiscounts(SiteContext.CurrentSiteID)
                                                            .WhereContains("MultiBuyDiscountName", "MyDiscount")
                                                            .TopN(1)
                                                            .FirstOrDefault();

if (discount != null)
{
    // Deletes the Buy X Get Y discount
    MultiBuyDiscountInfo.Provider.Delete(discount);
}
> Back to list of examples

Catalog discounts

Creating a catalog discount

C#
// Creates a new catalog discount object and sets its properties
DiscountInfo newDiscount = new DiscountInfo()
{
    DiscountName = "MyDiscount",
    DiscountDisplayName = "My Discount",
    DiscountIsFlat = false,
    DiscountValue = 20,
    DiscountApplyTo = DiscountApplicationEnum.Products,
    DiscountProductCondition = @"{% SKU.SKUName.Contains(""new"") %}",
    DiscountEnabled = true,
    DiscountOrder = 1,
    DiscountApplyFurtherDiscounts = true,
    DiscountUsesCoupons = false,
    DiscountSiteID = SiteContext.CurrentSiteID
};

// Saves the catalog discount to the database
DiscountInfo.Provider.Set(newDiscount);
> Back to list of examples

Updating a catalog discount

C#
// Gets the first catalog discount that contains 'MyDiscount' on the current site
DiscountInfo discount = DiscountInfo.Provider.GetBySite(SiteContext.CurrentSiteID)
                                            .WhereContains("DiscountName", "MyDiscount")
                                            .WhereContains("DiscountApplyTo", DiscountApplicationEnum.Products.ToString())
                                            .TopN(1)
                                            .FirstOrDefault();

if (discount != null)
{
    // Updates the catalog discount properties
    discount.DiscountEnabled = false;

    // Saves the changes to the database
    DiscountInfo.Provider.Set(discount);
}
> Back to list of examples

Updating multiple catalog discounts

C#
// Gets all enabled catalog discounts on the current site
var discounts = DiscountInfo.Provider.GetBySite(SiteContext.CurrentSiteID, true)
                                    .WhereContains("DiscountApplyTo", DiscountApplicationEnum.Products.ToString());

// Loops through the catalog discounts
foreach (DiscountInfo discount in discounts)
{
    // Updates the catalog discount properties
    discount.DiscountEnabled = false;

    // Saves the changes to the database
    DiscountInfo.Provider.Set(discount);
}
> Back to list of examples

Deleting a catalog discount

C#
// Gets the first catalog discount that contains 'MyDiscount' on the current site
DiscountInfo discount = DiscountInfo.Provider.GetBySite(SiteContext.CurrentSiteID)
                                            .WhereContains("DiscountName", "MyDiscount")
                                            .WhereContains("DiscountApplyTo", DiscountApplicationEnum.Products.ToString())
                                            .TopN(1)
                                            .FirstOrDefault();

if (discount != null)
{
    // Deletes the catalog discount
    DiscountInfo.Provider.Delete(discount);
}
> Back to list of examples

Order discounts

Creating an order discount

C#
// Creates a new order discount object and sets its properties
DiscountInfo newDiscount = new DiscountInfo()
{
    DiscountDisplayName = "New order discount",
    DiscountName = "NewOrderDiscount",
    DiscountApplyTo = DiscountApplicationEnum.Order,
    DiscountIsFlat = false,
    DiscountSiteID = SiteContext.CurrentSiteID,

    DiscountEnabled = true,
    DiscountValue = 10,
    DiscountCartCondition = @"{% Currency.CurrencyName==""Dollar"" %}",
    DiscountOrder = 1,
    DiscountApplyFurtherDiscounts = true,
    DiscountUsesCoupons = false,
};

// Saves the order discount to the database
DiscountInfo.Provider.Set(newDiscount);
> Back to list of examples

Updating an order discount

C#
// Gets the first order discount on the current site whose name contains 'NewOrderDiscount'
DiscountInfo discount = DiscountInfo.Provider.GetBySite(SiteContext.CurrentSiteID)
                                            .WhereContains("DiscountName", "NewOrderDiscount")
                                            .WhereEquals("DiscountApplyTo", DiscountApplicationEnum.Order.ToString())
                                            .TopN(1)
                                            .FirstOrDefault();

if (discount != null)
{
    // Updates the order discount properties
    discount.DiscountEnabled = false;

    // Saves the changes to the database
    DiscountInfo.Provider.Set(discount);
}
> Back to list of examples

Updating multiple order discounts

C#
// Gets all enabled order discounts on the current site
var discounts = DiscountInfo.Provider.GetBySite(SiteContext.CurrentSiteID, true)
                                    .WhereEquals("DiscountApplyTo", DiscountApplicationEnum.Order.ToString())
                                    .WhereTrue("DiscountEnabled");

// Loops through the order discounts
foreach (DiscountInfo discount in discounts)
{
    // Updates the order discount properties
    discount.DiscountItemMinOrderAmount = 100;

    // Saves the changes to the database
    DiscountInfo.Provider.Set(discount);
}
> Back to list of examples

Deleting an order discount

C#
// Gets the first order discount on the current site whose name contains 'NewOrderDiscount'
DiscountInfo discount = DiscountInfo.Provider.GetBySite(SiteContext.CurrentSiteID)
                                            .WhereContains("DiscountName", "NewOrderDiscount")
                                            .WhereEquals("DiscountApplyTo", DiscountApplicationEnum.Order.ToString())
                                            .TopN(1)
                                            .FirstOrDefault();

if (discount != null)
{
    // Deletes the order discount
    DiscountInfo.Provider.Delete(discount);
}
> Back to list of examples

Free shipping offers

Creating a free shipping offer

C#
// Creates a new free shipping offer object and sets its properties
DiscountInfo newDiscount = new DiscountInfo()
{
    DiscountName = "MyShippingOffer",
    DiscountDisplayName = "My Shipping Offer",
    DiscountIsFlat = false,
    DiscountValue = 20,
    DiscountApplyTo = DiscountApplicationEnum.Shipping,
    DiscountOrderAmount = 100,
    DiscountEnabled = true,
    DiscountOrder = 1,
    DiscountApplyFurtherDiscounts = true,
    DiscountUsesCoupons = false,
    DiscountSiteID = SiteContext.CurrentSiteID
};

// Saves the free shipping offer to the database
DiscountInfo.Provider.Set(newDiscount);
> Back to list of examples

Updating a free shipping offer

C#
// Gets the first free shipping offer that contains 'MyShippingOffer' on the current site
DiscountInfo discount = DiscountInfo.Provider.GetBySite(SiteContext.CurrentSiteID)
                                            .WhereContains("DiscountName", "MyShippingOffer")
                                            .WhereContains("DiscountApplyTo", DiscountApplicationEnum.Shipping.ToString())
                                            .TopN(1)
                                            .FirstOrDefault();

if (discount != null)
{
    // Updates the free shipping offer properties
    discount.DiscountEnabled = false;

    // Saves the changes to the database
    DiscountInfo.Provider.Set(discount);
}
> Back to list of examples

Updating multiple free shipping offer

C#
// Gets all enabled free shipping offers on the current site
var discounts = DiscountInfo.Provider.GetBySite(SiteContext.CurrentSiteID, true)
                                    .WhereContains("DiscountApplyTo", DiscountApplicationEnum.Shipping.ToString());

// Loops through the free shipping offers
foreach (DiscountInfo discount in discounts)
{
    // Updates the free shipping offer properties
    discount.DiscountEnabled = false;

    // Saves the changes to the database
    DiscountInfo.Provider.Set(discount);
}
> Back to list of examples

Deleting a free shipping offer

C#
// Gets the first free shipping offer that contains 'MyShippingOffer' on the current site
DiscountInfo discount = DiscountInfo.Provider.GetBySite(SiteContext.CurrentSiteID)
                                            .WhereContains("DiscountName", "MyShippingOffer")
                                            .WhereContains("DiscountApplyTo", DiscountApplicationEnum.Shipping.ToString())
                                            .TopN(1)
                                            .FirstOrDefault();

if (discount != null)
{
    // Deletes the free shipping offer
    DiscountInfo.Provider.Delete(discount);
}
> Back to list of examples

Volume discounts

Creating a volume discount

C#
// Gets a product for the volume discount
SKUInfo product = SKUInfo.Provider.Get()
                                 .WhereStartsWith("SKUName", "New")
                                 .TopN(1)
                                 .FirstOrDefault();

if (product != null)
{
    // Creates a new volume discount object
    VolumeDiscountInfo newDiscount = new VolumeDiscountInfo();

    // Sets the volume discount properties
    newDiscount.VolumeDiscountMinCount = 100;
    newDiscount.VolumeDiscountValue = 20;
    newDiscount.VolumeDiscountSKUID = product.SKUID;
    newDiscount.VolumeDiscountIsFlatValue = false;

    // Saves the volume discount to the database
    VolumeDiscountInfo.Provider.Set(newDiscount);
}
> Back to list of examples

Updating a volume discount

C#
// Gets a product
SKUInfo product = SKUInfo.Provider.Get()
                                .WhereEquals("SKUName", "NewProduct")
                                .TopN(1)
                                .FirstOrDefault();

if (product != null)
{
    // Gets the first volume discount defined for the product
    VolumeDiscountInfo discount = VolumeDiscountInfoProvider.GetVolumeDiscounts(product.SKUID).TopN(1).FirstOrDefault();
    if (discount != null)
    {
        // Updates the volume discount properties
        discount.VolumeDiscountMinCount = 800;

        // Saves the changes to the database
        VolumeDiscountInfo.Provider.Set(discount);
    }
}
> Back to list of examples

Updating multiple volume discounts

C#
// Gets a product
SKUInfo product = SKUInfo.Provider.Get()
                               .WhereStartsWith("SKUName", "New")
                               .TopN(1)
                               .FirstOrDefault();

if (product != null)
{
    // Gets the product's volume discounts
    var discounts = VolumeDiscountInfoProvider.GetVolumeDiscounts(product.SKUID);

    // Loops through the volume discounts
    foreach (VolumeDiscountInfo discount in discounts)
    {
        // Updates the volume discount properties
        discount.VolumeDiscountMinCount = 500;

        // Saves the changes to the database
        VolumeDiscountInfo.Provider.Set(discount);
    }
}
> Back to list of examples

Deleting a volume discount

C#
// Gets a product
SKUInfo product = SKUInfo.Provider.Get()
                               .WhereStartsWith("SKUName", "New")
                               .TopN(1)
                               .FirstOrDefault();

if (product != null)
{
    // Gets the first volume discount defined for the product
    VolumeDiscountInfo discount = VolumeDiscountInfoProvider.GetVolumeDiscounts(product.SKUID).TopN(1).FirstOrDefault();
    if (discount != null)
    {
        // Deletes the volume discount
        VolumeDiscountInfo.Provider.Delete(discount);
    }
}
> Back to list of examples

Product coupons

Creating a product coupon

C#
// Gets a product for the product coupon
SKUInfo product = SKUInfo.Provider.Get()
                               .WhereStartsWith("SKUName", "New")
                               .TopN(1)
                               .FirstOrDefault();

if (product != null)
{
    // Creates a new Product coupon object and sets its properties
    MultiBuyDiscountInfo newProductCoupon = new MultiBuyDiscountInfo()
    {
        MultiBuyDiscountName = "NewProductCoupon",
        MultiBuyDiscountDisplayName = "New product coupon",
        MultiBuyDiscountEnabled = true,
        MultiBuyDiscountSiteID = SiteContext.CurrentSiteID,

        // Configures the object as a Product coupon (not a Buy X Get Y discount)
        MultiBuyDiscountIsProductCoupon = true,
        MultiBuyDiscountUsesCoupons = true,
        MultiBuyDiscountApplyFurtherDiscounts = true,
        MultiBuyDiscountMinimumBuyCount = 1,
        MultiBuyDiscountAutoAddEnabled = false,

        // Sets the coupon's discount value to a fixed amount of 10
        MultiBuyDiscountIsFlat = true,
        MultiBuyDiscountValue = 10,

        // Makes the coupon available for all store visitors
        MultiBuyDiscountCustomerRestriction = DiscountCustomerEnum.All,
    };

    // Saves the product coupon to the database
    MultiBuyDiscountInfo.Provider.Set(newProductCoupon);

    // Configures the coupon to apply to the retrieved product
    MultiBuyDiscountSKUInfo couponSkuBinding = new MultiBuyDiscountSKUInfo();
    couponSkuBinding.MultiBuyDiscountID = newProductCoupon.MultiBuyDiscountID;
    couponSkuBinding.SKUID = product.SKUID;

    // Saves the coupon-product relationship to the database
    MultiBuyDiscountSKUInfo.Provider.Set(couponSkuBinding);
}
> Back to list of examples

Adding coupon codes to a product coupon

C#
// Gets the first product coupon on the current site whose name contains 'NewProductCoupon'
MultiBuyDiscountInfo productCoupon = MultiBuyDiscountInfoProvider.GetProductCouponDiscounts(SiteContext.CurrentSiteID)
                                                            .WhereContains("MultiBuyDiscountName", "NewProductCoupon")
                                                            .TopN(1)
                                                            .FirstOrDefault();

if (productCoupon != null)
{
    // Prepares a query that gets all existing coupon codes from the current site
    var existingCouponCodeQuery = ECommerceHelper.GetAllCouponCodesQuery(SiteContext.CurrentSiteID);

    // Creates a cache of coupon codes on the current site
    var existingCodes = existingCouponCodeQuery.GetListResult<string>();

    // Prepares an instance of a class that checks against existing coupon codes to avoid duplicates
    var coudeUniquenessChecker = new CodeUniquenessChecker(existingCodes);

    // Initializes a coupon code generator
    RandomCodeGenerator codeGenerator = new RandomCodeGenerator(coudeUniquenessChecker, "**********");

    // Loops to generate 100 coupon codes
    for (int i = 0; i < 100; i++)
    {
        // Generates a new unique code text
        string code = codeGenerator.GenerateCode();

        // Creates a coupon code and adds it to the product coupon
        MultiBuyCouponCodeInfoProvider.CreateCoupon(productCoupon, code, 1);
    }
}
> Back to list of examples

Updating a product coupon

C#
// Gets the first product coupon on the current site whose name contains 'NewProductCoupon'
MultiBuyDiscountInfo productCoupon = MultiBuyDiscountInfoProvider.GetProductCouponDiscounts(SiteContext.CurrentSiteID)
                                                            .WhereContains("MultiBuyDiscountName", "NewProductCoupon")
                                                            .TopN(1)
                                                            .FirstOrDefault();

if (productCoupon != null)
{
    // Updates the product coupon properties
    productCoupon.MultiBuyDiscountValue = 20;

    // Saves the changes to the database
    MultiBuyDiscountInfo.Provider.Set(productCoupon);
}
> Back to list of examples

Updating multiple product coupons

C#
// Gets all enabled product coupons on the current site
var productCoupons = MultiBuyDiscountInfoProvider.GetProductCouponDiscounts(SiteContext.CurrentSiteID)
                                            .WhereTrue("MultiBuyDiscountEnabled");

// Loops through the product coupons
foreach (MultiBuyDiscountInfo coupon in productCoupons)
{
    // Updates the product coupon properties (disables the coupon)
    coupon.MultiBuyDiscountEnabled = false;

    // Saves the changes to the database
    MultiBuyDiscountInfo.Provider.Set(coupon);
}
> Back to list of examples

Removing products from a product coupon

C#
// Gets the first product coupon on the current site whose name contains 'NewProductCoupon'
MultiBuyDiscountInfo productCoupon = MultiBuyDiscountInfoProvider.GetProductCouponDiscounts(SiteContext.CurrentSiteID)
                                                            .WhereContains("MultiBuyDiscountName", "NewProductCoupon")
                                                            .TopN(1)
                                                            .FirstOrDefault();

// Gets all coupon-product relationships for the product coupon
var couponSkuBindings = MultiBuyDiscountSKUInfo.Provider.Get()
                                                .WhereEquals("MultiBuyDiscountID", productCoupon.MultiBuyDiscountID);

// Loops through the retrieved coupon-product relationships
foreach (MultiBuyDiscountSKUInfo couponSkuBinding in couponSkuBindings)
{
    // Removes the product from the product coupon
    MultiBuyDiscountSKUInfo.Provider.Delete(couponSkuBinding);
}
> Back to list of examples

Applying a product coupon to product sections

C#
// NOTE: Remove any assigned products, departments, brands or collections from the product coupon before assigning sections

// Gets the first product coupon on the current site whose name contains 'NewProductCoupon'
MultiBuyDiscountInfo productCoupon = MultiBuyDiscountInfoProvider.GetProductCouponDiscounts(SiteContext.CurrentSiteID)
                                                            .WhereContains("MultiBuyDiscountName", "NewProductCoupon")
                                                            .TopN(1)
                                                            .FirstOrDefault();

// Gets the starting path of the current site's product section
string productStartingPath = ECommerceSettings.ProductsStartingPath(SiteContext.CurrentSiteID);

// Gets a list of all page type names that represent product sections
var productSectionTypes = CMS.DataEngine.DataClassInfoProvider.GetClasses()
                                                                    .WhereTrue("ClassIsProductSection")
                                                                    .Column("ClassName")
                                                                    .GetListResult<string>();

// Prepares an array of the product section page type names
// Requires a 'using System.Linq;' statement
string[] sectionTypeNames = productSectionTypes.ToArray();

// Gets all product section pages from the current site on the first level under the product section root
IEnumerable<TreeNode> productSections = new MultiDocumentQuery()
                            .Types(sectionTypeNames)
                            .OnCurrentSite()
                            .Path(productStartingPath, PathTypeEnum.Children)
                            .NestingLevel(1);

foreach (TreeNode section in productSections)
{
    // Creates a relationship between the product coupon and product section
    // Tip: To add excluded sections to the product coupon, set the method's 'included' parameter to false
    MultiBuyDiscountTreeInfo.Provider.Add(productCoupon.MultiBuyDiscountID, section.NodeID, included: true);
}

// Clears the product coupon's cache record
CMS.Helpers.CacheHelper.TouchKey(MultiBuyDiscountInfo.OBJECT_TYPE_PRODUCT_COUPON + "|byid|" + productCoupon.MultiBuyDiscountID);
> Back to list of examples

Applying a product coupon to departments

C#
// NOTE: Remove any assigned products, sections, brands or collections from the product coupon before assigning departments

// Gets the first product coupon on the current site whose name contains 'NewProductCoupon'
MultiBuyDiscountInfo productCoupon = MultiBuyDiscountInfoProvider.GetProductCouponDiscounts(SiteContext.CurrentSiteID)
                                                            .WhereContains("MultiBuyDiscountName", "NewProductCoupon")
                                                            .TopN(1)
                                                            .FirstOrDefault();

// Gets all departments on the current site
var departments = DepartmentInfoProvider.GetDepartments(SiteContext.CurrentSiteID);

// Loops through the departments
foreach (DepartmentInfo department in departments)
{
    // Creates a relationship between the product coupon and department
    MultiBuyDiscountDepartmentInfo.Provider.Add(productCoupon.MultiBuyDiscountID, department.DepartmentID);
}

// Clears the product coupon's cache record
CMS.Helpers.CacheHelper.TouchKey(MultiBuyDiscountInfo.OBJECT_TYPE_PRODUCT_COUPON + "|byid|" + productCoupon.MultiBuyDiscountID);
> Back to list of examples

Applying a product coupon to brands

C#
// NOTE: Remove any assigned products, sections, departments or collections from the product coupon before assigning brands

// Gets the first product coupon on the current site whose name contains 'NewProductCoupon'
MultiBuyDiscountInfo productCoupon = MultiBuyDiscountInfoProvider.GetProductCouponDiscounts(SiteContext.CurrentSiteID)
                                                            .WhereContains("MultiBuyDiscountName", "NewProductCoupon")
                                                            .TopN(1)
                                                            .FirstOrDefault();

// Gets all brands on the current site
var brands = BrandInfo.Provider.Get().OnSite(SiteContext.CurrentSiteID);

// Loops through the brands
foreach (BrandInfo brand in brands)
{
    // Creates a relationship between the product coupon and brand
    // Tip: To add excluded brands to the product coupon, set the method's 'included' parameter to false
    MultiBuyDiscountBrandInfo.Provider.Add(productCoupon.MultiBuyDiscountID, brand.BrandID, included: true);
}

// Clears the product coupon's cache record
CMS.Helpers.CacheHelper.TouchKey(MultiBuyDiscountInfo.OBJECT_TYPE_PRODUCT_COUPON + "|byid|" + productCoupon.MultiBuyDiscountID);
> Back to list of examples

Applying a product coupon to collections

C#
// NOTE: Remove any assigned products, sections, departments or brands from the product coupon before assigning collections

// Gets the first product coupon on the current site whose name contains 'NewProductCoupon'
MultiBuyDiscountInfo productCoupon = MultiBuyDiscountInfoProvider.GetProductCouponDiscounts(SiteContext.CurrentSiteID)
                                                            .WhereContains("MultiBuyDiscountName", "NewProductCoupon")
                                                            .TopN(1)
                                                            .FirstOrDefault();

// Gets all collections on the current site
var collections = CollectionInfo.Provider.Get().OnSite(SiteContext.CurrentSiteID);

// Loops through the collections
foreach (CollectionInfo collection in collections)
{
    // Creates a relationship between the product coupon and collection
    // Tip: To add excluded collections to the product coupon, set the method's 'included' parameter to false
    MultiBuyDiscountCollectionInfo.Provider.Add(productCoupon.MultiBuyDiscountID, collection.CollectionID, included: true);
}

// Clears the product coupon's cache record
CMS.Helpers.CacheHelper.TouchKey(MultiBuyDiscountInfo.OBJECT_TYPE_PRODUCT_COUPON + "|byid|" + productCoupon.MultiBuyDiscountID);
> Back to list of examples

Deleting a product coupon

C#
// Gets the first product coupon on the current site whose name contains 'NewProductCoupon'
MultiBuyDiscountInfo productCoupon = MultiBuyDiscountInfoProvider.GetProductCouponDiscounts(SiteContext.CurrentSiteID)
                                                            .WhereContains("MultiBuyDiscountName", "NewProductCoupon")
                                                            .TopN(1)
                                                            .FirstOrDefault();

if (productCoupon != null)
{
    // Deletes the product coupon
    MultiBuyDiscountInfo.Provider.Delete(productCoupon);
}
> Back to list of examples