Determine if promotion is applicable to a given order

865 views
Skip to first unread message

David Herman

unread,
Nov 3, 2008, 10:16:14 AM11/3/08
to ATG_Tech
We need to be able to determine if a promotion is applicable to a
given order, in other words do it's rules apply to the order itself or
items within the order. We have very specific promotions and we want
to be able to alert a user that is applying a coupon that is tied to
that promotion that it is not valid for your current purchase and
prevent it from applying at that time. Is there any way to easily
determine this?

Raja Ramachandran

unread,
Nov 3, 2008, 10:33:02 AM11/3/08
to atg_...@googlegroups.com
David,

Qualifying for a promotion and realizing it in an order are two
distinct steps. You can control it when you define your promotion
rules. So if you can be more specific about your requirement for
promotion, we can see if something OOTB will work or if we need to
customize promotions.

Raja

David Herman

unread,
Nov 3, 2008, 11:03:37 AM11/3/08
to ATG_Tech
Raja, thanks but that's not what I meant. What I need to be able to
do is tell a user specifically that the coupon code(and thus the
promotion it's tied to) that they are trying to use would not have any
effect on their current order. The order may be of the wrong type
(order class type), it may not have any skus that are listed in the
promotions rules etc, and if the promotion would not "apply" to their
order, then don't give it to them (this would be custom on our part,
we just need to know how to determine it).

Ted Davis

unread,
Nov 3, 2008, 11:12:41 AM11/3/08
to atg_...@googlegroups.com
To clarify Dave's question, if the customer puts product A in their
cart then enters a coupon code for "25% off product B" we want to tell
them, "Hey, you don't have a B in your cart; that promotion is
worthless to you!" :-)

O'Brien, Paul

unread,
Nov 3, 2008, 11:15:45 AM11/3/08
to atg_...@googlegroups.com
The methods I believe you are looking for are in atg.commerce.pricing.Qualifier. They are findQualifyingItems, findQualifyingShipping, and findQualifyingOrder. You can find their signatures in the Javadoc. findQualifyingItems will return a collection of items that qualify for the given discount (passed in the pPricingModel parameter). findQualifyingShipping and findQualfyingOrder will return an Object of type atg.commerce.pricing.definition.MatchingObject if the given shipping group or order qualifies for the given discount. Which method you choose to call depends on if your promotion discounts an item, shipping group, or order.

Raja Ramachandran

unread,
Nov 3, 2008, 11:24:05 AM11/3/08
to atg_...@googlegroups.com
Also you will have to override your ClaimableManager.claimCoupon()
method, refer the qualifier to find items matching your pricingModel (
promotion ).

Jeremy Sears

unread,
Nov 3, 2008, 11:36:02 AM11/3/08
to atg_...@googlegroups.com
Rather than extend ClaimableManger, you may want to just extend
CouponFormHandler.claimCoupon(). That will allow you to add a
formException with descriptive text for your exception case.
--
Jeremy Sears

Raja Ramachandran

unread,
Nov 3, 2008, 11:54:24 AM11/3/08
to atg_...@googlegroups.com
right! that's more appropriate.

David Herman

unread,
Nov 3, 2008, 12:48:58 PM11/3/08
to ATG_Tech
It looks like by the description of that method in the javadoc that
the user must already have the promotion or am I readying this wrong
"determines whether an order should receive a discount based on the
given running environment." We want to be able to determine this
before giving the user the promotion.

O'Brien, Paul

unread,
Nov 3, 2008, 1:03:09 PM11/3/08
to atg_...@googlegroups.com
Taking the method out of its usual context, the comment is inaccurate. Usually, the system passes in promotions that are contained in the user profile. But calling it independently, you pass in the promotion you want to evaluate in the pPricingModel parameter. This does not add the promotion to the user profile - it will just return any qualifying items/shipping/order based on the rules in the given pricing model.

David Herman

unread,
Nov 3, 2008, 1:36:06 PM11/3/08
to ATG_Tech
Along these same lines is there a way to prevent ATG from applying
promotions to an order that are already specified in another
promotion? For example a user has a coupon code that is tied to a
promotion that gives him 10% of of sku12345 and there is another promo
that gives the user 15% off sku12345, is there a way to make ATG use
only the first that is in the list?

O'Brien, Paul

unread,
Nov 3, 2008, 1:38:38 PM11/3/08
to atg_...@googlegroups.com
Yes, there is an "order of application" property on promotions. If you specify that the 10% off one is of higher priority (by specifying a lower number), then that promotion will get evaluated first. By default, once an item is discounted, it cannot be discounted again, so the second promotion won't apply. (This behavior is configurable through /atg/commerce/pricing/QualifierService.filterForTargetDiscountedByAnyDiscountId).

David Herman

unread,
Nov 4, 2008, 5:43:46 PM11/4/08
to ATG_Tech
I have added the following code,

Collection matchingCommerceItems = qualifier.findQualifyingItems(
getPriceQuotes(order), order.getCommerceItems(), promotion,
profile, null, order, order.getPriceInfo(),
hardGoodShippingGroup, hardGoodShippingGroup.getPriceInfo(),
null);
if (null != matchingCommerceItems && matchingCommerceItems.size() >
0) {
applicable = true;
} else {
applicable = false;
}

MatchingObject matchingOrder = qualifier.findQualifyingOrder(
getPriceQuotes(order), order.getCommerceItems(),
promotion, profile, null, order, order
.getPriceInfo(), hardGoodShippingGroup,
hardGoodShippingGroup.getPriceInfo(), null);
if (null != matchingOrder
&& null != matchingOrder.getMatchingObject()) {
applicable = true;
} else {
applicable = false;
}


when the promotion i'm testing is Item Discount - Percent Off and the
sku is IN the order matchingCommerceItems has the item that matches,
however when i use that same discount and the sku is NOT in the order,
matchingOrder still returns the order object. Can you please explain
why the order still matches even though the promotion does not
specifically apply to it?

David Herman

unread,
Nov 5, 2008, 11:21:57 AM11/5/08
to ATG_Tech

O'Brien, Paul

unread,
Nov 5, 2008, 2:42:28 PM11/5/08
to atg_...@googlegroups.com
It doesn't make sense to pass an item-level promotion to findQualifyingOrder. Because the target of an order-level promotion is always the current order, findQualifyingOrder does not evaluate the target of the promotion. So if the qualifying condition of your promotion is met, findQualifyingOrder will return the order. You should only be using findQualifyingItems to evaluate an item-level promotion.

David Herman

unread,
Nov 5, 2008, 3:14:23 PM11/5/08
to atg_...@googlegroups.com
We might not know the promotion type, we just want to know if the coupon code will effect the users order in any way

O'Brien, Paul

unread,
Nov 7, 2008, 11:33:17 AM11/7/08
to atg_...@googlegroups.com
You can determine the promotion type by checking if its item descriptor is a subtype of the base item, shipping, and order discount item descriptors:

if (((GSAItemDescriptor) pricingModel.getItemDescriptor()).isSubTypeOf("Item Discount"))

List qualifyingItems = qualifierService.findQualifyingItems(...params..);

David Herman

unread,
Nov 7, 2008, 2:20:41 PM11/7/08
to atg_...@googlegroups.com
once i changed how he promo worked this was not an issue any more

The only thing I'm still facing is priceInfo record getting nulled when I get a transaction. ATG Support suggested taht I try setting it for markForRollbackOnly instead of calling td.end(true).  Not sure if this will help or not though

Kishor

unread,
Nov 8, 2008, 1:14:59 AM11/8/08
to ATG_Tech
Hi All,

Just a thought...

Would it make sense to assoicate a closessness qualifier to the
promotion... and setup the closeness qualifier with the exact revers
PMDL rule as that of the promotion....i.e. if the promotion rule in
"give 25% if item B is in cart" then the closeness qualifier would be
"item B not in cart". So, when the customer uses the coupon, the
promotion will not qualify, but the associated closeness qualifier
will qualify. The closeness qualifier can be associated with a Meida-
Internal-Text (lets say an error message that says Item B should be in
cart to apply the Coupon). So, we can use a scenario/droplet to get
the active closeness qualifiers and display the associated text.

Please let me know if this makes sense and if this is a good approach
per ATG Commerce design philosophy.

Cheers,
Kishor
> > /atg/commerce/pricing/QualifierService.filterForTargetDiscountedByAnyDiscou­ntId).
> > > > > > > determine this?- Hide quoted text -
>
> - Show quoted text -

David Herman

unread,
Nov 8, 2008, 1:26:07 AM11/8/08
to atg_...@googlegroups.com
it sounds like it would work but it sounds way over complicated.  If we weren't meant to use the QualifierService it wouldn't have been exposed.
Reply all
Reply to author
Forward
0 new messages