Jaa


How to Create a Promotion Code

This topic shows how to create a new promotion code.

To create a promotion code

  1. In Visual Studio, create a new Commerce Server Core Systems Web application.

  2. Add the Microsoft.CommerceServer.CrossTierTypes and Microsoft.CommerceServer.Marketing.CrossTierTypes references to the application.

  3. Add a using directive for the Microsoft.CommerceServer and Microsoft.CommerceServer.Marketing namespaces.

  4. Define the Marketing Web Service URL.

  5. Create the MarketingContext.

    For more information, see How to Connect to the Marketing System. In this example, the MarketingContext object is named marketingSystem.

  6. Create a new public promotion code.

  7. Enter the promotion code details.

  8. Save the promotion code.

Example

The following code example illustrates how to create a promotion code.

using Microsoft.CommerceServer;
using Microsoft.CommerceServer.Marketing;

namespace CommerceServerMarketingExamples
{
    public class CSMarketingExamples
    {
        public void NewPromotionCode()
        {
            try
            {
                // Set the Marketing service URL.
                string marketingWebServiceUrl = @"https://localhost/MarketingWebService/MarketingWebService.asmx";
                // Create an instance of the Marketing System agent.
                MarketingServiceAgent ma = new MarketingServiceAgent(marketingWebServiceUrl);
                MarketingContext marketingSystem = MarketingContext.Create(ma);

                // Create a new public promotion code (limit one per basket).
                PromoCodeDefinition promo = marketingSystem.PromoCodeDefinitions.NewPromoCodeDefinition(PromoCodeUsageOption.Public, 1);
                promo.Name = "Promo1";
                promo.UsageLimit = 100;
                promo.PublicPromoCode = "BigDiscount99";
                promo.Save(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: {0}\r\nMessage: {1}", ex.GetType(), ex.Message);
                if (ex.InnerException != null)
                    Console.WriteLine("\r\nInner Exception: {0}\r\nMessage: {1}", ex.InnerException.GetType(), ex.InnerException.Message);
                Console.ReadLine();
            }
        }
    }
}

See Also

Other Resources

Marketing Management Scenarios