Search in sources :

Example 1 with OfferOfferRuleXref

use of org.broadleafcommerce.core.offer.domain.OfferOfferRuleXref in project BroadleafCommerce by BroadleafCommerce.

the class PromotionMessageDTOServiceImpl method getCustomerRule.

protected String getCustomerRule(Offer offer) {
    if (offer != null) {
        Map<String, OfferOfferRuleXref> offerMatchRuleXrefs = offer.getOfferMatchRulesXref();
        OfferOfferRuleXref customerRuleXref = offerMatchRuleXrefs.get(RuleIdentifier.CUSTOMER_FIELD_KEY);
        if (customerRuleXref != null && customerRuleXref.getOfferRule() != null) {
            OfferRule customerOfferRule = customerRuleXref.getOfferRule();
            return customerOfferRule.getMatchRule();
        }
    }
    return null;
}
Also used : OfferRule(org.broadleafcommerce.core.offer.domain.OfferRule) OfferOfferRuleXref(org.broadleafcommerce.core.offer.domain.OfferOfferRuleXref)

Example 2 with OfferOfferRuleXref

use of org.broadleafcommerce.core.offer.domain.OfferOfferRuleXref in project BroadleafCommerce by BroadleafCommerce.

the class AbstractBaseProcessor method couldOfferApplyToTimePeriod.

protected boolean couldOfferApplyToTimePeriod(Offer offer) {
    boolean appliesToTimePeriod = false;
    String rule = null;
    OfferOfferRuleXref ruleXref = offer.getOfferMatchRulesXref().get(OfferRuleType.TIME.getType());
    if (ruleXref != null && ruleXref.getOfferRule() != null) {
        rule = ruleXref.getOfferRule().getMatchRule();
    }
    if (rule != null) {
        TimeZone timeZone = getOfferTimeZoneProcessor().getTimeZone(offer);
        TimeDTO timeDto = new TimeDTO(SystemTime.asCalendar(timeZone));
        HashMap<String, Object> vars = new HashMap<String, Object>();
        vars.put("time", timeDto);
        Boolean expressionOutcome = executeExpression(rule, vars);
        if (expressionOutcome != null && expressionOutcome) {
            appliesToTimePeriod = true;
        }
    } else {
        appliesToTimePeriod = true;
    }
    return appliesToTimePeriod;
}
Also used : TimeZone(java.util.TimeZone) TimeDTO(org.broadleafcommerce.common.TimeDTO) HashMap(java.util.HashMap) OfferOfferRuleXref(org.broadleafcommerce.core.offer.domain.OfferOfferRuleXref)

Example 3 with OfferOfferRuleXref

use of org.broadleafcommerce.core.offer.domain.OfferOfferRuleXref in project BroadleafCommerce by BroadleafCommerce.

the class AbstractBaseProcessor method couldOfferApplyToRequestDTO.

protected boolean couldOfferApplyToRequestDTO(Offer offer, RequestDTO requestDTO) {
    boolean appliesToRequestRule = false;
    String rule = null;
    OfferOfferRuleXref ruleXref = offer.getOfferMatchRulesXref().get(OfferRuleType.REQUEST.getType());
    if (ruleXref != null && ruleXref.getOfferRule() != null) {
        rule = ruleXref.getOfferRule().getMatchRule();
    }
    if (rule != null) {
        HashMap<String, Object> vars = new HashMap<String, Object>();
        vars.put("request", requestDTO);
        Boolean expressionOutcome = executeExpression(rule, vars);
        if (expressionOutcome != null && expressionOutcome) {
            appliesToRequestRule = true;
        }
    } else {
        appliesToRequestRule = true;
    }
    return appliesToRequestRule;
}
Also used : HashMap(java.util.HashMap) OfferOfferRuleXref(org.broadleafcommerce.core.offer.domain.OfferOfferRuleXref)

Example 4 with OfferOfferRuleXref

use of org.broadleafcommerce.core.offer.domain.OfferOfferRuleXref in project BroadleafCommerce by BroadleafCommerce.

the class OrderOfferProcessorImpl method couldOfferApplyToOrder.

/**
 * Private method which executes the appliesToOrderRules in the Offer to determine if this offer
 * can be applied to the Order, OrderItem, or FulfillmentGroup.
 *
 * @param offer
 * @param order
 * @param promotableOrderItem
 * @param promotableFulfillmentGroup
 * @return true if offer can be applied, otherwise false
 */
protected boolean couldOfferApplyToOrder(Offer offer, PromotableOrder promotableOrder, PromotableOrderItem promotableOrderItem, PromotableFulfillmentGroup promotableFulfillmentGroup) {
    boolean appliesToItem = false;
    String rule = null;
    OfferOfferRuleXref orderRule = offer.getOfferMatchRulesXref().get(OfferRuleType.ORDER.getType());
    if (orderRule != null && orderRule.getOfferRule() != null) {
        rule = orderRule.getOfferRule().getMatchRule();
    }
    if (rule != null) {
        HashMap<String, Object> vars = new HashMap<String, Object>();
        promotableOrder.updateRuleVariables(vars);
        vars.put("offer", offer);
        if (promotableFulfillmentGroup != null) {
            promotableFulfillmentGroup.updateRuleVariables(vars);
        }
        if (promotableOrderItem != null) {
            promotableOrderItem.updateRuleVariables(vars);
        }
        Boolean expressionOutcome = executeExpression(rule, vars);
        if (expressionOutcome != null && expressionOutcome) {
            appliesToItem = true;
        }
    } else {
        appliesToItem = true;
    }
    return appliesToItem;
}
Also used : HashMap(java.util.HashMap) OfferOfferRuleXref(org.broadleafcommerce.core.offer.domain.OfferOfferRuleXref)

Example 5 with OfferOfferRuleXref

use of org.broadleafcommerce.core.offer.domain.OfferOfferRuleXref in project BroadleafCommerce by BroadleafCommerce.

the class AbstractBaseProcessor method couldOfferApplyToCustomer.

/**
 * Private method which executes the appliesToCustomerRules in the Offer to determine if this Offer
 * can be applied to the Customer.
 *
 * @param offer
 * @param customer
 * @return true if offer can be applied, otherwise false
 */
protected boolean couldOfferApplyToCustomer(Offer offer, Customer customer) {
    boolean appliesToCustomer = false;
    String rule = null;
    OfferOfferRuleXref ruleXref = offer.getOfferMatchRulesXref().get(OfferRuleType.CUSTOMER.getType());
    if (ruleXref != null && ruleXref.getOfferRule() != null) {
        rule = ruleXref.getOfferRule().getMatchRule();
    }
    if (rule != null) {
        HashMap<String, Object> vars = new HashMap<String, Object>();
        vars.put("customer", customer);
        Boolean expressionOutcome = executeExpression(rule, vars);
        if (expressionOutcome != null && expressionOutcome) {
            appliesToCustomer = true;
        }
    } else {
        appliesToCustomer = true;
    }
    return appliesToCustomer;
}
Also used : HashMap(java.util.HashMap) OfferOfferRuleXref(org.broadleafcommerce.core.offer.domain.OfferOfferRuleXref)

Aggregations

OfferOfferRuleXref (org.broadleafcommerce.core.offer.domain.OfferOfferRuleXref)7 HashMap (java.util.HashMap)5 OfferRule (org.broadleafcommerce.core.offer.domain.OfferRule)3 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 TimeZone (java.util.TimeZone)1 TimeDTO (org.broadleafcommerce.common.TimeDTO)1 Money (org.broadleafcommerce.common.money.Money)1 CandidateItemOffer (org.broadleafcommerce.core.offer.domain.CandidateItemOffer)1 CandidateOrderOffer (org.broadleafcommerce.core.offer.domain.CandidateOrderOffer)1 CustomerOffer (org.broadleafcommerce.core.offer.domain.CustomerOffer)1 Offer (org.broadleafcommerce.core.offer.domain.Offer)1 OfferOfferRuleXrefImpl (org.broadleafcommerce.core.offer.domain.OfferOfferRuleXrefImpl)1 OfferRuleImpl (org.broadleafcommerce.core.offer.domain.OfferRuleImpl)1 FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)1 Order (org.broadleafcommerce.core.order.domain.Order)1 OrderMultishipOption (org.broadleafcommerce.core.order.domain.OrderMultishipOption)1 IAnswer (org.easymock.IAnswer)1