Question

I am trying to retrieve the start and end date of a discount using Microsoft Commerce Server, server side code. How can this be achieved? The only data I am stuck with is the promo code "TEST". There are not a lot of code samples on how I can just create the Discount object or CampaignItem object and set the promo code to retrieve its properties. Please help.

Was it helpful?

Solution

The following code snippet demonstrates how to get the StartDate and EndDate for a Commerce Server Discount. This assumes you are using the Commerce Server 2007 API and that you know the ID of the discount you want the dates from.

//The discount id we want to get dates from.
var discountId = 12;//Set to your ID.

//Configure the Commerce Server site name.
var siteName = "StarterSite";

//We need a MarketingContext instance so we can access the marketing API. 
var mc = MarketingContext.Create(siteName, null, AuthorizationMode.NoAuthorization);

//Get our discount.
var discount = (Discount)mc.CampaignItems.GetCampaignItem(discountId);

//Voila.  Start and End dates.
var startDate = discount.StartDate;
var endDate = discount.EndDate;

Note: The MarketingContext.Create overload, returns a MarketingContext instance that utilises the marketing system management API in local mode. For more information on these modes, see Understanding the Different Types of Commerce Server APIs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top