cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How can I get the Coupon from a Promotion?

0 Kudos
486

Hi all,

I am making a query that brings me a lot of information about the active promotions.

The query is:

 SELECT
     {pr.startdate} AS 'Data/Hora Inicial',
     {pr.enddate} AS 'Data/Hora Final',
     {pr.code} AS 'Título',
     {rs.code} AS 'Status',
     {pr.priority} AS 'Prioridade'
 FROM
 {
     PromotionSourceRule AS pr
     JOIN DroolsRule AS dr ON {pr:code} = {dr:code}
     JOIN RuleStatus AS rs ON {pr.status} = {rs.pk}
 }
 WHERE
     {pr:enddate} < current_timestamp
     AND {dr.active} = '1'
     AND {dr.currentversion} = '1'
  
 ORDER BY
     {pr.enddate} ASC

But I need to find the Coupon code that triggers these promotions.... How can I join the SingleCodeCoupon at the query??

Thanks all

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Fabio,

CheckDefaultSourceRuleInspector. We extended it to be able to check whether a rule has a coupon condition for a given coupon (couponCode in the fragment). You can then translate this to flex search.

 Map<String, RuleConditionDefinitionData> ruleConditionDefinitions =
             getRuleConditionsRegistry().getConditionDefinitionsForRuleTypeAsMap(sourceRule.getClass());
         List<RuleConditionData>
             ruleConditionDatas = getRuleConditionsConverter().fromString(sourceRule.getConditions(), ruleConditionDefinitions);
         return collectAll(ruleConditionDatas).anyMatch(c -> {
             if (conditionDefinitionId.equals(c.getDefinitionId())) {
                 RuleParameterData ruleParameterData = c.getParameters().get(parameterName);
                 if (ruleParameterData != null) {
                     return StringUtils.contains(ruleParameterData.getValue().toString(), couponCode);
                 }
             }
             return false;
         });

BR, Cristi C.