use of org.broadleafcommerce.core.offer.domain.CandidateItemOffer in project BroadleafCommerce by BroadleafCommerce.
the class OrderItemImpl method clone.
@Override
public OrderItem clone() {
// this is likely an extended class - instantiate from the fully qualified name via reflection
OrderItemImpl clonedOrderItem;
try {
clonedOrderItem = (OrderItemImpl) Class.forName(this.getClass().getName()).newInstance();
try {
checkCloneable(clonedOrderItem);
} catch (CloneNotSupportedException e) {
LOG.warn("Clone implementation missing in inheritance hierarchy outside of Broadleaf: " + clonedOrderItem.getClass().getName(), e);
}
if (candidateItemOffers != null) {
for (CandidateItemOffer candidate : candidateItemOffers) {
CandidateItemOffer clone = candidate.clone();
clone.setOrderItem(clonedOrderItem);
clonedOrderItem.getCandidateItemOffers().add(clone);
}
}
if (orderItemAttributeMap != null && !orderItemAttributeMap.isEmpty()) {
for (OrderItemAttribute attribute : orderItemAttributeMap.values()) {
OrderItemAttribute clone = attribute.clone();
clone.setOrderItem(clonedOrderItem);
clonedOrderItem.getOrderItemAttributes().put(clone.getName(), clone);
}
}
if (CollectionUtils.isNotEmpty(childOrderItems)) {
for (OrderItem childOrderItem : childOrderItems) {
OrderItem clone = childOrderItem.clone();
clone.setParentOrderItem(clonedOrderItem);
clonedOrderItem.getChildOrderItems().add(clone);
}
}
clonedOrderItem.setCategory(category);
clonedOrderItem.setGiftWrapOrderItem(giftWrapOrderItem);
clonedOrderItem.setName(name);
clonedOrderItem.setOrder(order);
clonedOrderItem.setOrderItemType(convertOrderItemType(orderItemType));
clonedOrderItem.setPersonalMessage(personalMessage);
clonedOrderItem.setQuantity(quantity);
clonedOrderItem.retailPrice = retailPrice;
clonedOrderItem.salePrice = salePrice;
clonedOrderItem.discountsAllowed = discountsAllowed;
clonedOrderItem.salePriceOverride = salePriceOverride;
clonedOrderItem.retailPriceOverride = retailPriceOverride;
clonedOrderItem.setParentOrderItem(parentOrderItem);
} catch (Exception e) {
throw new RuntimeException(e);
}
return clonedOrderItem;
}
use of org.broadleafcommerce.core.offer.domain.CandidateItemOffer in project BroadleafCommerce by BroadleafCommerce.
the class OrderItemImpl method createOrRetrieveCopyInstance.
@Override
public <G extends OrderItem> CreateResponse<G> createOrRetrieveCopyInstance(MultiTenantCopyContext context) throws CloneNotSupportedException {
CreateResponse<G> createResponse = context.createOrRetrieveCopyInstance(this);
if (createResponse.isAlreadyPopulated()) {
return createResponse;
}
OrderItem cloned = createResponse.getClone();
cloned.setOrder(order == null ? null : order.createOrRetrieveCopyInstance(context).getClone());
cloned.setCategory(category);
cloned.setName(name);
cloned.setOrderItemType(convertOrderItemType(orderItemType));
cloned.setTaxable(isTaxable());
cloned.setQuantity(quantity);
cloned.setPersonalMessage(personalMessage);
((OrderItemImpl) cloned).retailPrice = retailPrice;
((OrderItemImpl) cloned).salePrice = salePrice;
((OrderItemImpl) cloned).discountsAllowed = discountsAllowed;
((OrderItemImpl) cloned).salePriceOverride = salePriceOverride;
((OrderItemImpl) cloned).retailPriceOverride = retailPriceOverride;
// dont clone
cloned.setParentOrderItem(parentOrderItem == null ? null : parentOrderItem.createOrRetrieveCopyInstance(context).getClone());
for (OrderItem entry : childOrderItems) {
OrderItem clonedEntry = ((OrderItem) entry).createOrRetrieveCopyInstance(context).getClone();
clonedEntry.setParentOrderItem(cloned);
cloned.getChildOrderItems().add(clonedEntry);
}
for (CandidateItemOffer entry : candidateItemOffers) {
CandidateItemOffer clonedEntry = entry.createOrRetrieveCopyInstance(context).getClone();
clonedEntry.setOrderItem(cloned);
cloned.getCandidateItemOffers().add(clonedEntry);
}
for (Map.Entry<String, OrderItemAttribute> entry : orderItemAttributeMap.entrySet()) {
OrderItemAttribute clonedEntry = entry.getValue().createOrRetrieveCopyInstance(context).getClone();
clonedEntry.setOrderItem(cloned);
cloned.getOrderItemAttributes().put(entry.getKey(), clonedEntry);
}
// dont clone
cloned.setGiftWrapOrderItem(giftWrapOrderItem);
for (OrderItemPriceDetail entry : orderItemPriceDetails) {
OrderItemPriceDetail clonedEntry = entry.createOrRetrieveCopyInstance(context).getClone();
clonedEntry.setOrderItem(cloned);
cloned.getOrderItemPriceDetails().add(clonedEntry);
}
cloned.finalizePrice();
return createResponse;
}
use of org.broadleafcommerce.core.offer.domain.CandidateItemOffer in project BroadleafCommerce by BroadleafCommerce.
the class ItemOfferProcessorTest method testFilterItemLevelOffer.
public void testFilterItemLevelOffer() throws Exception {
replay();
List<PromotableCandidateItemOffer> qualifiedOffers = new ArrayList<PromotableCandidateItemOffer>();
List<Offer> offers = dataProvider.createItemBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", OfferDiscountType.PERCENT_OFF, null, null);
PromotableOrder order = dataProvider.createBasicPromotableOrder();
itemProcessor.filterItemLevelOffer(order, qualifiedOffers, offers.get(0));
// test that the valid order item offer is included - legacy format - no qualifier
// since there's no qualifier, both items can apply
// This line is commented out because we are no longer creating legacy offers.
// assertTrue(qualifiedOffers.size() == 2 && qualifiedOffers.get(0).getOffer().equals(offers.get(0)) && qualifiedOffers.get(1).getOffer().equals(offers.get(0)));
qualifiedOffers = new ArrayList<PromotableCandidateItemOffer>();
offers = dataProvider.createItemBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", OfferDiscountType.PERCENT_OFF, "([MVEL.eval(\"toUpperCase()\",\"test1\"), MVEL.eval(\"toUpperCase()\",\"test2\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))", "([MVEL.eval(\"toUpperCase()\",\"test1\"), MVEL.eval(\"toUpperCase()\",\"test2\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))");
itemProcessor.filterItemLevelOffer(order, qualifiedOffers, offers.get(0));
// test that the valid order item offer is included
// there is a qualifier and the item qualifying criteria requires only 1, therefore there will be only one qualifier in the qualifiers map
// we don't know the targets yet, so there's only one CandidateItemOffer for now
assertTrue(qualifiedOffers.size() == 1 && qualifiedOffers.get(0).getOffer().equals(offers.get(0)) && qualifiedOffers.get(0).getCandidateQualifiersMap().size() == 1);
// Add a subtotal requirement that will be met by the item offer.
qualifiedOffers = new ArrayList<PromotableCandidateItemOffer>();
offers = dataProvider.createItemBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", OfferDiscountType.PERCENT_OFF, "([MVEL.eval(\"toUpperCase()\",\"test1\"), MVEL.eval(\"toUpperCase()\",\"test2\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))", "([MVEL.eval(\"toUpperCase()\",\"test1\"), MVEL.eval(\"toUpperCase()\",\"test2\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))");
offers.get(0).setQualifyingItemSubTotal(new Money(1));
itemProcessor.filterItemLevelOffer(order, qualifiedOffers, offers.get(0));
// test that the valid order item offer is included
// there is a qualifier and the item qualifying criteria requires only 1, therefore there will be only one qualifier in the qualifiers map
// we don't know the targets yet, so there's only one CandidateItemOffer for now
assertTrue(qualifiedOffers.size() == 1 && qualifiedOffers.get(0).getOffer().equals(offers.get(0)) && qualifiedOffers.get(0).getCandidateQualifiersMap().size() == 1);
// Add a subtotal requirement that will not be met by the item offer.
qualifiedOffers = new ArrayList<PromotableCandidateItemOffer>();
offers = dataProvider.createItemBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", OfferDiscountType.PERCENT_OFF, "([MVEL.eval(\"toUpperCase()\",\"test1\"), MVEL.eval(\"toUpperCase()\",\"test2\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))", "([MVEL.eval(\"toUpperCase()\",\"test1\"), MVEL.eval(\"toUpperCase()\",\"test2\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))");
offers.get(0).setQualifyingItemSubTotal(new Money(99999));
itemProcessor.filterItemLevelOffer(order, qualifiedOffers, offers.get(0));
// Since the item qualification subTotal is not met, the qualified offer size should
// be zero.
assertTrue(qualifiedOffers.size() == 0);
qualifiedOffers = new ArrayList<PromotableCandidateItemOffer>();
offers = dataProvider.createItemBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", OfferDiscountType.PERCENT_OFF, "([MVEL.eval(\"toUpperCase()\",\"test5\"), MVEL.eval(\"toUpperCase()\",\"test6\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))", "([MVEL.eval(\"toUpperCase()\",\"test5\"), MVEL.eval(\"toUpperCase()\",\"test6\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))");
itemProcessor.filterItemLevelOffer(order, qualifiedOffers, offers.get(0));
// test that the invalid order item offer is excluded
assertTrue(qualifiedOffers.size() == 0);
verify();
}
Aggregations