Discounts
How can i manpulate many discounts to show them on aspx page?
( we are using commerce server 2007, SQL 2005, VS 2005)
How can i manpulate many discounts to show them on aspx page?
( we are using commerce server 2007, SQL 2005, VS 2005)
You could consider using the runtime discount filter:
http://msdn2.microsoft.com/en-us/library/microsoft.commerceserver.runtime.marketing.aspx
Here's a code sample:
DiscountItemCollection allDiscounts = DiscountItemCollection.CreateFromCache("Discounts");
DiscountCriteriaFilter filter = new DiscountCriteriaFilter();
DiscountItemCollection applicableDiscounts = allDiscounts.ApplyProductFilter(filter, catalog, product);
foreach(DiscountItem item in applicableDiscounts)
{
//your logic here
}
Try tweaking the DiscountCriteriaFilter (documentation provided on the link above) to get what you want to display. You probably want to avoid showing discounts that require a coupon code.
I try Your code and see in allDiscounts all my discounts.
When I apply ApplyProductFilter or ApplyCategoryFilter it always returns zero items. Still I set productid or category id with discount.
Esp. for product id wich in my bascet gets the correct discount.
I use virtual catalogs and set the discount on the virtual catalog for the category the product belongs to.
Any idea why I not get any results at all?
Regards Johan
Johan,
What properties are you setting on the DiscountCriteriaFilter? This is probably the reason you're not getting any records.
Here's the documentation on it:
I don't know what the default setting is for the five member properties, but you'll probably need to set some of them to true to populate the collection.
Using virtual catalogs. Tried diffrent combinations on filter flags. Still no with result.
See code below
void MyTest()
{
DiscountItemCollection allDiscounts = DiscountItemCollection.CreateFromCache("Discounts");
DiscountCriteriaFilter filter = new DiscountCriteriaFilter();
filter.FilterOnAward = false;
filter.FilterOnCondition = false;
filter.IncludeDiscountsWithEligibilityRequirements = false;
filter.IncludeDiscountsWithPromoCodes = false;
filter.IncludeInactiveDiscounts = false;
DiscountItemCollection applicableDiscounts = allDiscounts.ApplyProductFilter(filter, "GB-Catalog", "TG_TSHIRT(ScaniaBaseCatalog)");
foreach (DiscountItem item in applicableDiscounts)
{
Response.Write(item.ToString());
//your logic here
}
}