The existing Qualifier.doFilters()
method evaluates items in the qualifier and target rules. The method uses the Qualifier
service’s filtering methods to disqualify items before comparing them to a promotion’s PMDLRule
.
The filtering process prevents problems with pricing rules. For example, in the promotion “buy one item, get one item free,” most retailers exclude the item that acts as a qualifier from receiving the discount. This prevents a customer from buying just one item and getting that one item free; the customer must put two items in the cart in order to get the discount.
The following example shows how the filterItemsForQualifier
and filterOrdersForTarget
methods work. This example uses the rule “for next 1 item that is blue, discount up to 1 item that is green.”
The filterItemsForQualifier
method is invoked first. By default, this method uses the following criteria to remove items from the environment. This prevents the items from helping to satisfy the constraints specified in the “qualifier” portion of the input PMDL rule:
If an item’s price is zero or negative, the item is removed.
If an item is on sale, it is removed.
If an item has already acted as a qualifier, the item is removed if the
FilterForQualiferActedAsQualifier
filter flag is set totrue
.
After items are filtered out of the environment, the evaluateQualifier
method is invoked. evaluateQualifier
selects one blue item that acts as a qualifier from the environment. (For more information on these methods, refer to the next section, Replacing the Way a PMDL Rule Is Evaluated.)
If the qualifier is satisfied, the system evaluates the offer, if there is one, to determine which objects among all those available should receive the discount that is enabled by the one blue item. Core Commerce currently performs this selection for CommerceItems
only.
When working with For Next or When type promotions, which are promotions where criteria must be met for the promotion applies, you can allow qualifying items that have acted in previous promotions to apply in the current promotion.
The filterForQualifierActedAsQualifier
property identifies if qualifiers can be reused in a promotion. If this property is set to true
, qualifiers can be used only once per promotion evaluation. If this property is set to false
, qualifiers are picked up from FilteredCommerceItem.pendingQuantityAsQualifierDetails
, which temporarily stores items that have acted as qualifiers for the pricingModel
currently being evaluated. This ensures that items that have acted as qualifiers for the current promotion are not reused. Once the pricingModel
evaluation is completed, the pendingQuantityAsQualifierDetails
bucket is cleared.
Before the target element is evaluated, the filterItemsForTarget
method must be invoked. The filterItemsForTarget
method uses the following criteria to remove items from the environment against which the target is compared:
If the item price is zero, negative, or less than the promotion price
If the item is on sale
If an item already acted as a qualifier
If an item already received the discount that is currently being evaluated, or any other discount
If the item meets any of those criteria, the item is removed.
After the filterItemsForTarget
method is invoked, the evaluateTarget
method is called. This method returns a set of items that can receive the discount because they satisfy the target element of the rule.
You can change the criteria by which items are filtered out of the environment before a rule is evaluated. For example, your filter could allow items with a price of zero to act as qualifiers for a rule. You could rewrite the filterItemsForQualifier
method to remove that restriction, or write your own filter component using the atg.commerce.pricing.PromotionQualifyingFilter
interface.