0

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.

Anna
  • 239
  • 1
  • 7
  • 21
  • You seem to be asking about the start and end date of a discount, but then say you are stuck on getting the promo code properties. Can you clarify your question? – bentayloruk Jul 19 '13 at 08:32
  • The goal is the get the discount start and end date properties from Commerce Server but to do that I'm not sure what method I should use to create the objects needed to obtain those properties – Anna Jul 20 '13 at 13:45
  • OK. Are you using Commerce Server 2007 API or Commerce Server 2009? – bentayloruk Jul 22 '13 at 09:45

1 Answers1

1

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.

bentayloruk
  • 4,060
  • 29
  • 31
  • Is there a way to grab the Discount by promo code name (ie. TENOFF)? Or does it have it be by discount id? – Anna Jul 25 '13 at 01:14
  • You can do this via the API, although it will be quite long winded. Are you happy to use direct SQL? If so, you could try the solution here http://microsoftblog.co.in/commerceserver/get-discounts-for-a-given-promotion-code/ – bentayloruk Jul 25 '13 at 08:47