use of org.broadleafcommerce.core.offer.domain.OfferItemCriteria in project BroadleafCommerce by BroadleafCommerce.
the class ItemOfferProcessorImpl method markQualifiers.
/**
* Loop through ItemCriteria and mark qualifiers required to give the promotion to 1 or more targets.
* @param itemOffer
* @param order
* @return
*/
protected boolean markQualifiers(PromotableCandidateItemOffer itemOffer, PromotableOrder order) {
for (OfferItemCriteria itemCriteria : itemOffer.getCandidateQualifiersMap().keySet()) {
List<PromotableOrderItem> promotableItems = itemOffer.getCandidateQualifiersMap().get(itemCriteria);
List<PromotableOrderItemPriceDetail> priceDetails = buildPriceDetailListFromOrderItems(promotableItems);
int qualifierQtyNeeded = offerServiceUtilities.markQualifiersForCriteria(itemOffer, itemCriteria, priceDetails);
if (qualifierQtyNeeded != 0) {
return false;
}
}
return true;
}
use of org.broadleafcommerce.core.offer.domain.OfferItemCriteria in project BroadleafCommerce by BroadleafCommerce.
the class ItemOfferProcessorImpl method markTargets.
/**
* Loop through ItemCriteria and mark targets that can get this promotion to give the promotion to 1 or more targets.
* @param itemOffer
* @param order
* @return
*/
public boolean markTargets(PromotableCandidateItemOffer itemOffer, PromotableOrder order, OrderItem relatedQualifier, boolean checkOnly) {
Offer promotion = itemOffer.getOffer();
if (itemOffer.getCandidateTargetsMap().keySet().isEmpty()) {
return false;
}
OrderItem relatedQualifierRoot = offerServiceUtilities.findRelatedQualifierRoot(relatedQualifier);
for (OfferItemCriteria itemCriteria : itemOffer.getCandidateTargetsMap().keySet()) {
List<PromotableOrderItem> promotableItems = itemOffer.getCandidateTargetsMap().get(itemCriteria);
List<PromotableOrderItemPriceDetail> priceDetails = buildPriceDetailListFromOrderItems(promotableItems);
offerServiceUtilities.sortTargetItemDetails(priceDetails, itemOffer.getOffer().getApplyDiscountToSalePrice());
int targetQtyNeeded = itemCriteria.getQuantity();
// This code was added to support a requirement of buying at least "x" matching items
// but also applying the item to "x+1", "x+2", etc.
int minRequiredTargetQuantity = itemOffer.getMinimumRequiredTargetQuantity();
if (minRequiredTargetQuantity > 1 && minRequiredTargetQuantity > targetQtyNeeded) {
targetQtyNeeded = minRequiredTargetQuantity;
}
targetQtyNeeded = offerServiceUtilities.markTargetsForCriteria(itemOffer, relatedQualifier, checkOnly, promotion, relatedQualifierRoot, itemCriteria, priceDetails, targetQtyNeeded);
if (targetQtyNeeded != 0) {
return false;
}
}
if (!checkOnly) {
itemOffer.addUse();
}
return true;
}
use of org.broadleafcommerce.core.offer.domain.OfferItemCriteria in project BroadleafCommerce by BroadleafCommerce.
the class ItemOfferProcessorImpl method markRelatedQualifiersAndTargets.
/**
* When the {@link Offer#getRequiresRelatedTargetAndQualifiers()} flag is set to true, we must make sure that we
* identify qualifiers and targets together, as they must be related to each other based on the
* {@link OrderItem#getParentOrderItem()} / {@link OrderItem#getChildOrderItems()} attributes.
*
* @param itemOffer
* @param order
* @return whether or not a suitable qualifier/target pair was found and marked
*/
protected boolean markRelatedQualifiersAndTargets(PromotableCandidateItemOffer itemOffer, PromotableOrder order) {
OrderItemHolder orderItemHolder = new OrderItemHolder(null);
for (Entry<OfferItemCriteria, List<PromotableOrderItem>> entry : itemOffer.getCandidateQualifiersMap().entrySet()) {
OfferItemCriteria itemCriteria = entry.getKey();
List<PromotableOrderItem> promotableItems = entry.getValue();
List<PromotableOrderItemPriceDetail> priceDetails = buildPriceDetailListFromOrderItems(promotableItems);
int qualifierQtyNeeded = offerServiceUtilities.markRelatedQualifiersAndTargetsForItemCriteria(itemOffer, order, orderItemHolder, itemCriteria, priceDetails, this);
if (qualifierQtyNeeded != 0) {
return false;
}
}
return markTargets(itemOffer, order, orderItemHolder.getOrderItem(), false);
}
use of org.broadleafcommerce.core.offer.domain.OfferItemCriteria in project BroadleafCommerce by BroadleafCommerce.
the class PromotableOrderItemPriceDetailImpl method lookupOrCreatePromotionQualifier.
public PromotionQualifier lookupOrCreatePromotionQualifier(PromotableCandidateItemOffer candidatePromotion) {
Offer promotion = candidatePromotion.getOffer();
for (PromotionQualifier pq : promotionQualifiers) {
if (pq.getPromotion().equals(promotion)) {
return pq;
}
}
PromotionQualifier pq = new PromotionQualifier();
Money pqPriceBeforeAdjustment = new Money(0);
for (Map.Entry<OfferItemCriteria, List<PromotableOrderItem>> qualifierMapEntry : candidatePromotion.getCandidateQualifiersMap().entrySet()) {
for (PromotableOrderItem promotableOrderItem : qualifierMapEntry.getValue()) {
Money priceBeforeAdjustments = promotableOrderItem.getOrderItem().getPriceBeforeAdjustments(candidatePromotion.getOffer().getApplyDiscountToSalePrice());
pqPriceBeforeAdjustment = pqPriceBeforeAdjustment.add(priceBeforeAdjustments);
}
}
pq.setPrice(pqPriceBeforeAdjustment);
pq.setPromotion(promotion);
promotionQualifiers.add(pq);
return pq;
}
use of org.broadleafcommerce.core.offer.domain.OfferItemCriteria 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;
}
Aggregations