[英]How to get Discount Start and End Date from Commerce Server?
I am trying to retrieve the start and end date of a discount using Microsoft Commerce Server, server side code. 我正在尝试使用Microsoft Commerce Server服务器端代码检索折扣的开始和结束日期。 How can this be achieved? 如何做到这一点? The only data I am stuck with is the promo code "TEST". 我遇到的唯一数据是促销代码“ 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. 关于如何直接创建Discount对象或CampaignItem对象并设置促销代码以检索其属性的代码示例并不多。 Please help. 请帮忙。
The following code snippet demonstrates how to get the StartDate
and EndDate
for a Commerce Server Discount
. 以下代码段演示了如何获取Commerce Server Discount
的StartDate
和EndDate
。 This assumes you are using the Commerce Server 2007 API and that you know the ID of the discount you want the dates from. 这假定您使用的是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;
Note: The MarketingContext.Create
overload, returns a MarketingContext
instance that utilises the marketing system management API in local mode . 注意: MarketingContext.Create
重载,返回在本地模式下使用营销系统管理API的MarketingContext
实例。 For more information on these modes, see Understanding the Different Types of Commerce Server APIs . 有关这些模式的更多信息,请参见了解不同类型的Commerce Server API 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.