Search in sources :

Example 6 with OfferImpl

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

the class PricingTest method createOffer.

private Offer createOffer(String offerName, OfferType offerType, OfferDiscountType discountType, double value, String customerRule, String orderRule) {
    Offer offer = new OfferImpl();
    offer.setName(offerName);
    offer.setStartDate(SystemTime.asDate());
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DATE, -1);
    offer.setStartDate(calendar.getTime());
    calendar.add(Calendar.DATE, 2);
    offer.setEndDate(calendar.getTime());
    offer.setType(offerType);
    offer.setDiscountType(discountType);
    offer.setValue(BigDecimal.valueOf(value));
    offer.setAutomaticallyAdded(true);
    OfferItemCriteria oic = new OfferItemCriteriaImpl();
    oic.setQuantity(1);
    oic.setMatchRule(orderRule);
    OfferTargetCriteriaXref targetXref = new OfferTargetCriteriaXrefImpl();
    targetXref.setOffer(offer);
    targetXref.setOfferItemCriteria(oic);
    offer.setTargetItemCriteriaXref(Collections.singleton(targetXref));
    offer.setCombinableWithOtherOffers(true);
    offer = offerService.save(offer);
    offer.setMaxUsesPerOrder(50);
    return offer;
}
Also used : OfferItemCriteriaImpl(org.broadleafcommerce.core.offer.domain.OfferItemCriteriaImpl) OfferTargetCriteriaXrefImpl(org.broadleafcommerce.core.offer.domain.OfferTargetCriteriaXrefImpl) Offer(org.broadleafcommerce.core.offer.domain.Offer) Calendar(java.util.Calendar) OfferItemCriteria(org.broadleafcommerce.core.offer.domain.OfferItemCriteria) OfferImpl(org.broadleafcommerce.core.offer.domain.OfferImpl) OfferTargetCriteriaXref(org.broadleafcommerce.core.offer.domain.OfferTargetCriteriaXref)

Example 7 with OfferImpl

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

the class OfferDataItemProvider method createOffer.

public Offer createOffer(String appliesToCustomerRules, String appliesToFulfillmentGroupRules, String appliesToRules, boolean applyToSalePrice, boolean combinableWithOtherOffers, boolean automaticallyAdded, OfferDiscountType type, Date endDate, int maxUses, OfferItemRestrictionRuleType qualifierType, OfferItemRestrictionRuleType targetType, int priority, Set<OfferQualifyingCriteriaXref> qualifyingItemCriteriaXref, boolean stackable, Date startDate, Set<OfferTargetCriteriaXref> targetItemCriteriaXref, boolean totalitarianOffer, OfferType offerType, BigDecimal value) {
    Offer offer = new OfferImpl();
    OfferRule customerRule = new OfferRuleImpl();
    customerRule.setMatchRule(appliesToCustomerRules);
    offer.getOfferMatchRulesXref().put(OfferRuleType.CUSTOMER.getType(), createXref(customerRule, offer, OfferRuleType.CUSTOMER.getType()));
    OfferRule fgRule = new OfferRuleImpl();
    fgRule.setMatchRule(appliesToFulfillmentGroupRules);
    offer.getOfferMatchRulesXref().put(OfferRuleType.FULFILLMENT_GROUP.getType(), createXref(fgRule, offer, OfferRuleType.FULFILLMENT_GROUP.getType()));
    OfferRule orderRule = new OfferRuleImpl();
    orderRule.setMatchRule(appliesToRules);
    offer.getOfferMatchRulesXref().put(OfferRuleType.ORDER.getType(), createXref(orderRule, offer, OfferRuleType.ORDER.getType()));
    offer.setApplyDiscountToSalePrice(applyToSalePrice);
    offer.setCombinableWithOtherOffers(combinableWithOtherOffers);
    offer.setAutomaticallyAdded(automaticallyAdded);
    offer.setDiscountType(type);
    offer.setEndDate(endDate);
    offer.setMaxUsesPerOrder(maxUses);
    offer.setOfferItemQualifierRuleType(qualifierType);
    offer.setOfferItemTargetRuleType(targetType);
    offer.setPriority(priority);
    offer.setQualifyingItemCriteriaXref(qualifyingItemCriteriaXref);
    offer.setStartDate(startDate);
    offer.setTargetItemCriteriaXref(targetItemCriteriaXref);
    offer.setTotalitarianOffer(totalitarianOffer);
    offer.setType(offerType);
    offer.setValue(value);
    offer.setId(getOfferId());
    return offer;
}
Also used : OfferRule(org.broadleafcommerce.core.offer.domain.OfferRule) Offer(org.broadleafcommerce.core.offer.domain.Offer) OfferImpl(org.broadleafcommerce.core.offer.domain.OfferImpl) OfferRuleImpl(org.broadleafcommerce.core.offer.domain.OfferRuleImpl)

Aggregations

OfferImpl (org.broadleafcommerce.core.offer.domain.OfferImpl)7 Offer (org.broadleafcommerce.core.offer.domain.Offer)5 Test (org.testng.annotations.Test)3 Serializable (java.io.Serializable)2 HashMap (java.util.HashMap)2 Money (org.broadleafcommerce.common.money.Money)2 PromotionDiscount (org.broadleafcommerce.core.offer.service.discount.PromotionDiscount)2 PromotionQualifier (org.broadleafcommerce.core.offer.service.discount.PromotionQualifier)2 PromotableCandidateItemOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer)2 PromotableCandidateItemOfferImpl (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOfferImpl)2 ParserContext (org.mvel2.ParserContext)2 Calendar (java.util.Calendar)1 Sku (org.broadleafcommerce.core.catalog.domain.Sku)1 SkuImpl (org.broadleafcommerce.core.catalog.domain.SkuImpl)1 CustomerOffer (org.broadleafcommerce.core.offer.domain.CustomerOffer)1 CustomerOfferImpl (org.broadleafcommerce.core.offer.domain.CustomerOfferImpl)1 OfferItemCriteria (org.broadleafcommerce.core.offer.domain.OfferItemCriteria)1 OfferItemCriteriaImpl (org.broadleafcommerce.core.offer.domain.OfferItemCriteriaImpl)1 OfferRule (org.broadleafcommerce.core.offer.domain.OfferRule)1 OfferRuleImpl (org.broadleafcommerce.core.offer.domain.OfferRuleImpl)1