Search in sources :

Example 1 with OfferImpl

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

the class OrderItemTest method testGetQuantityAvailableToBeUsedAsTarget.

public void testGetQuantityAvailableToBeUsedAsTarget() throws Exception {
    int quantity = priceDetail1.getQuantityAvailableToBeUsedAsTarget(candidateOffer);
    // no previous qualifiers, so all quantity is available
    assertTrue(quantity == 2);
    PromotionDiscount discount = new PromotionDiscount();
    discount.setPromotion(offer);
    discount.setQuantity(1);
    priceDetail1.getPromotionDiscounts().add(discount);
    quantity = priceDetail1.getQuantityAvailableToBeUsedAsTarget(candidateOffer);
    // items that have already received this promotion cannot get it again
    assertTrue(quantity == 1);
    Offer tempOffer = new OfferImpl();
    tempOffer.setCombinableWithOtherOffers(true);
    tempOffer.setOfferItemQualifierRuleType(OfferItemRestrictionRuleType.NONE);
    tempOffer.setOfferItemTargetRuleType(OfferItemRestrictionRuleType.NONE);
    discount.setPromotion(tempOffer);
    quantity = priceDetail1.getQuantityAvailableToBeUsedAsTarget(candidateOffer);
    // this item received a different promotion, but the restriction rule is NONE, so this item cannot be a qualifier
    // for this promotion
    assertTrue(quantity == 1);
    tempOffer.setOfferItemTargetRuleType(OfferItemRestrictionRuleType.TARGET);
    quantity = priceDetail1.getQuantityAvailableToBeUsedAsTarget(candidateOffer);
    // this item received a different promotion, but the restriction rule is TARGET,
    // so this item can be a target of this promotion but since the "candidateOffer"
    // is set to NONE, the quantity can only be 1
    assertTrue(quantity == 1);
    // Now set the candidateOffer to be "TARGET" and we can use the quantity
    // for both promotions.
    candidateOffer.getOffer().setOfferItemTargetRuleType(OfferItemRestrictionRuleType.TARGET);
    quantity = priceDetail1.getQuantityAvailableToBeUsedAsTarget(candidateOffer);
    // this item received a different promotion, but the restriction rule is TARGET,
    // so this item can be a target of this promotion but since the "candidateOffer"
    // is set to NONE, the quantity can only be 1
    assertTrue(quantity == 2);
    priceDetail1.getPromotionDiscounts().clear();
    // rest candidate offer
    candidateOffer.getOffer().setOfferItemTargetRuleType(OfferItemRestrictionRuleType.NONE);
    PromotionQualifier qualifier = new PromotionQualifier();
    qualifier.setPromotion(offer);
    qualifier.setQuantity(1);
    priceDetail1.getPromotionQualifiers().add(qualifier);
    quantity = priceDetail1.getQuantityAvailableToBeUsedAsTarget(candidateOffer);
    // items that have already qualified for this promotion cannot qualify again
    assertTrue(quantity == 1);
    qualifier.setPromotion(tempOffer);
    quantity = priceDetail1.getQuantityAvailableToBeUsedAsTarget(candidateOffer);
    // this item qualified for a different promotion, but the restriction rule is NONE,
    // so this item cannot be a qualifier for this promotion
    assertTrue(quantity == 1);
    tempOffer.setOfferItemQualifierRuleType(OfferItemRestrictionRuleType.TARGET);
    candidateOffer.getOffer().setOfferItemTargetRuleType(OfferItemRestrictionRuleType.QUALIFIER);
    quantity = priceDetail1.getQuantityAvailableToBeUsedAsTarget(candidateOffer);
// this item qualified for a different promotion, but the restriction rule is QUALIFIER,
// so this item can be a qualifier for this promotion
// dpc disabling this test for now        assertTrue(quantity==2);
}
Also used : PromotionQualifier(org.broadleafcommerce.core.offer.service.discount.PromotionQualifier) PromotableCandidateItemOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer) Offer(org.broadleafcommerce.core.offer.domain.Offer) OfferImpl(org.broadleafcommerce.core.offer.domain.OfferImpl) PromotableCandidateItemOfferImpl(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOfferImpl) PromotionDiscount(org.broadleafcommerce.core.offer.service.discount.PromotionDiscount)

Example 2 with OfferImpl

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

the class OrderItemTest method testGetQuantityAvailableToBeUsedAsQualifier.

public void testGetQuantityAvailableToBeUsedAsQualifier() throws Exception {
    int quantity = priceDetail1.getQuantityAvailableToBeUsedAsQualifier(candidateOffer);
    // no previous qualifiers, so all quantity is available
    assertTrue(quantity == 2);
    PromotionDiscount discount = new PromotionDiscount();
    discount.setPromotion(offer);
    discount.setQuantity(1);
    priceDetail1.getPromotionDiscounts().add(discount);
    quantity = priceDetail1.getQuantityAvailableToBeUsedAsQualifier(candidateOffer);
    // items that have already received this promotion cannot get it again
    assertTrue(quantity == 1);
    Offer testOffer = new OfferImpl();
    testOffer.setOfferItemQualifierRuleType(OfferItemRestrictionRuleType.NONE);
    testOffer.setOfferItemTargetRuleType(OfferItemRestrictionRuleType.NONE);
    discount.setPromotion(testOffer);
    quantity = priceDetail1.getQuantityAvailableToBeUsedAsQualifier(candidateOffer);
    // this item received a different promotion, but the restriction rule is NONE, so this item cannot be a qualifier for this promotion
    assertTrue(quantity == 1);
    testOffer.setOfferItemTargetRuleType(OfferItemRestrictionRuleType.QUALIFIER);
    candidateOffer.getOffer().setOfferItemQualifierRuleType(OfferItemRestrictionRuleType.TARGET);
    quantity = priceDetail1.getQuantityAvailableToBeUsedAsQualifier(candidateOffer);
    // this item received a different promotion, but the restriction rule is QUALIFIER, so this item can be a qualifier
    // for this promotion
    // dpc disabling this test for now        assertTrue(quantity==2);
    priceDetail1.getPromotionDiscounts().clear();
    PromotionQualifier qualifier = new PromotionQualifier();
    qualifier.setPromotion(offer);
    qualifier.setQuantity(1);
    priceDetail1.getPromotionQualifiers().add(qualifier);
    quantity = priceDetail1.getQuantityAvailableToBeUsedAsQualifier(candidateOffer);
    // items that have already qualified for this promotion cannot qualify again
    assertTrue(quantity == 1);
    qualifier.setPromotion(testOffer);
    quantity = priceDetail1.getQuantityAvailableToBeUsedAsQualifier(candidateOffer);
    // this item qualified for a different promotion, but the restriction rule is NONE, so this item cannot be a qualifier for this promotion
    assertTrue(quantity == 1);
    testOffer.setOfferItemQualifierRuleType(OfferItemRestrictionRuleType.QUALIFIER);
    candidateOffer.getOffer().setOfferItemQualifierRuleType(OfferItemRestrictionRuleType.QUALIFIER);
    quantity = priceDetail1.getQuantityAvailableToBeUsedAsQualifier(candidateOffer);
// this item qualified for a different promotion, but the restriction rule is QUALIFIER,
// so this item can be a qualifier for this promotion
// dpc disabling this test for now        assertTrue(quantity==2);
}
Also used : PromotionQualifier(org.broadleafcommerce.core.offer.service.discount.PromotionQualifier) PromotableCandidateItemOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer) Offer(org.broadleafcommerce.core.offer.domain.Offer) OfferImpl(org.broadleafcommerce.core.offer.domain.OfferImpl) PromotableCandidateItemOfferImpl(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOfferImpl) PromotionDiscount(org.broadleafcommerce.core.offer.service.discount.PromotionDiscount)

Example 3 with OfferImpl

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

the class MVELTest method testOfferAppliesToFulfillmentGroup.

// @Test
// No longer a valid test
// public void testMarkLawnmowerWhenOfferAppliesToHats() {
// OrderImpl order = new OrderImpl();
// ArrayList<OrderItem> items = new ArrayList<OrderItem>();
// order.setOrderItems(items);
// DiscreteOrderItemImpl item = new DiscreteOrderItemImpl();
// Money amount = new Money(10D);
// items.add(item);
// item.setSalePrice(amount);
// ProductImpl product = new ProductImpl();
// CategoryImpl category = new CategoryImpl();
// category.setName("hat");
// product.setDefaultCategory(category);
// item.setProduct(product);
// item.setQuantity(3);
// 
// DiscreteOrderItemImpl item2 = new DiscreteOrderItemImpl();
// Money amount2 = new Money(250D);
// items.add(item2);
// item2.setSalePrice(amount2);
// ProductImpl product2 = new ProductImpl();
// CategoryImpl category2 = new CategoryImpl();
// category2.setName("lawnmower");
// product2.setDefaultCategory(category2);
// item2.setProduct(product2);
// item2.setQuantity(1);
// 
// HashMap<String, Object> vars = new HashMap<String, Object>();
// vars.put("currentItem", item);
// vars.put("order", order);
// vars.put("doMark", true);
// 
// //This test makes use of the static MVEL function "orderContains(quantity)".
// StringBuffer expression = new StringBuffer(functions);
// expression.append("def evalItemForOrderContains(item) {")
// .append("             return item.product.defaultCategory.name == 'lawnmower'")
// .append("          } ")
// .append("          return (orderContainsPlusMark(1) and currentItem.product.defaultCategory.name == 'hat');");
// 
// Boolean result = (Boolean)MVEL.eval(expression.toString(), vars);
// assert result != null && result;
// assert item2.getMarkedForOffer() == 1;
// assert item.getMarkedForOffer() == 0;
// }
@Test
public void testOfferAppliesToFulfillmentGroup() {
    OrderImpl order = new OrderImpl();
    order.setSubTotal(new Money(110D));
    FulfillmentGroupImpl group = new FulfillmentGroupImpl();
    group.setPrimary(true);
    OfferImpl offer = new OfferImpl();
    offer.setType(OfferType.FULFILLMENT_GROUP);
    order.getFulfillmentGroups().add(group);
    // Set up MVEL Context
    ParserContext context = new ParserContext();
    // Import OfferType into the MVEL context since it may be used
    context.addImport("OfferType", OfferType.class);
    context.addImport("FulfillmentType", FulfillmentType.class);
    // Compile the MVEL Expression
    // This could test SHIPPING, or PICK_UP_AT_STORE, etc.
    // Could also apply to order instead of FULFILLMENT_GROUP
    Serializable domainExp1 = MVEL.compileExpression("offer.type.equals(OfferType.FULFILLMENT_GROUP) and (($ in order.fulfillmentGroups if $.type.equals(FulfillmentType.PHYSICAL)) != empty)", context);
    // Add variables to a HashMap that should be passed in to execute the expression
    HashMap<String, Object> domainVars = new HashMap<>();
    domainVars.put("order", order);
    domainVars.put("offer", offer);
    // Execute the expression
    Boolean expressionOutcome1 = (Boolean) MVEL.executeExpression(domainExp1, domainVars);
    assert expressionOutcome1 != null && expressionOutcome1;
}
Also used : Money(org.broadleafcommerce.common.money.Money) FulfillmentGroupImpl(org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl) Serializable(java.io.Serializable) HashMap(java.util.HashMap) OrderImpl(org.broadleafcommerce.core.order.domain.OrderImpl) OfferImpl(org.broadleafcommerce.core.offer.domain.OfferImpl) ParserContext(org.mvel2.ParserContext) Test(org.testng.annotations.Test)

Example 4 with OfferImpl

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

the class MVELTest method testOfferAppliesToSpecificItems.

@Test
public void testOfferAppliesToSpecificItems() {
    DiscreteOrderItemImpl orderItem = new DiscreteOrderItemImpl();
    Sku sku = new SkuImpl();
    sku.setRetailPrice(new Money("1"));
    sku.setId(1234L);
    orderItem.setSku(sku);
    OfferImpl offer = new OfferImpl();
    offer.setType(OfferType.ORDER_ITEM);
    // Set up MVEL Context
    ParserContext context = new ParserContext();
    // Import OfferType into the MVEL context since it may be used
    context.addImport("OfferType", OfferType.class);
    context.addImport("FulfillmentType", FulfillmentType.class);
    // Compile the MVEL Expression
    Serializable domainExp1 = MVEL.compileExpression("offer.type == OfferType.ORDER_ITEM and (currentItem.sku.id in [1234, 2345, 5678])", context);
    // Add variables to a HashMap that should be passed in to execute the expression
    HashMap<String, Object> domainVars = new HashMap<>();
    domainVars.put("currentItem", orderItem);
    domainVars.put("offer", offer);
    // Execute the expression
    Boolean expressionOutcome1 = (Boolean) MVEL.executeExpression(domainExp1, domainVars);
    assert expressionOutcome1 != null && expressionOutcome1;
}
Also used : Money(org.broadleafcommerce.common.money.Money) SkuImpl(org.broadleafcommerce.core.catalog.domain.SkuImpl) Serializable(java.io.Serializable) DiscreteOrderItemImpl(org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl) HashMap(java.util.HashMap) OfferImpl(org.broadleafcommerce.core.offer.domain.OfferImpl) Sku(org.broadleafcommerce.core.catalog.domain.Sku) ParserContext(org.mvel2.ParserContext) Test(org.testng.annotations.Test)

Example 5 with OfferImpl

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

the class OfferTest method testOfferDelete.

@Test(groups = { "testOfferDelete" }, dependsOnGroups = { "testFulfillmentGroupOffers" })
@Transactional
public void testOfferDelete() throws Exception {
    CustomerOffer customerOffer = customerOfferDao.create();
    Customer customer = createCustomer();
    Long customerId = customer.getId();
    customerOffer.setCustomer(customerService.saveCustomer(customer));
    Offer offer = createOfferUtility.createOffer("1.20 Dollars Off Order Offer", OfferType.ORDER, OfferDiscountType.AMOUNT_OFF, 1.20, null, true, true, 10, null);
    offer = offerService.save(offer);
    Long offerId = offer.getId();
    offerDao.delete(offer);
    Offer deletedOffer = offerDao.readOfferById(offerId);
    assert ((OfferImpl) deletedOffer).getArchived() == 'Y';
    offer = createOfferUtility.createOffer("1.20 Dollars Off Order Offer", OfferType.ORDER, OfferDiscountType.AMOUNT_OFF, 1.20, null, true, true, 10, null);
    offer = offerService.save(offer);
    customerOffer.setOffer(offer);
    customerOffer = customerOfferDao.save(customerOffer);
    Long customerOfferId = customerOffer.getId();
    customerOffer = customerOfferDao.readCustomerOfferById(customerOfferId);
    assert (customerOffer != null);
    Customer customer2 = createCustomer();
    customerOffer.setCustomer(customerService.saveCustomer(customer2));
    customerOffer = customerOfferDao.save(customerOffer);
    assert !customerOffer.getCustomer().getId().equals(customerId);
    customerOfferDao.delete(customerOffer);
    customerOffer = customerOfferDao.readCustomerOfferById(customerOfferId);
    assert customerOffer == null || ((OfferImpl) customerOffer).getArchived() == 'Y';
}
Also used : Customer(org.broadleafcommerce.profile.core.domain.Customer) Offer(org.broadleafcommerce.core.offer.domain.Offer) CustomerOffer(org.broadleafcommerce.core.offer.domain.CustomerOffer) CustomerOfferImpl(org.broadleafcommerce.core.offer.domain.CustomerOfferImpl) OfferImpl(org.broadleafcommerce.core.offer.domain.OfferImpl) CustomerOffer(org.broadleafcommerce.core.offer.domain.CustomerOffer) Test(org.testng.annotations.Test) CommonSetupBaseTest(org.broadleafcommerce.test.CommonSetupBaseTest) Transactional(org.springframework.transaction.annotation.Transactional)

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