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);
}
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);
}
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;
}
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;
}
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';
}
Aggregations