如何从Commerce Server获取折扣开始和结束日期

本文关键字:开始 结束 日期 获取 Commerce Server | 更新日期: 2023-09-27 18:21:44

我正在尝试使用Microsoft Commerce Server服务器端代码检索折扣的开始和结束日期。如何做到这一点?我唯一坚持的数据是促销代码"测试"。关于如何创建Discount对象或CampaignItem对象并设置促销代码以检索其属性,没有太多的代码示例。请帮忙。

如何从Commerce Server获取折扣开始和结束日期

下面的代码片段演示了如何为Commerce Server Discount获取StartDateEndDate。这假设您使用的是Commerce Server 2007 API,并且您知道您想要的日期折扣的ID。

//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;

注意:MarketingContext.Create重载返回一个MarketingContext实例,该实例在本地模式中使用营销系统管理API。有关这些模式的更多信息,请参阅了解不同类型的Commerce Server API。