use of org.broadleafcommerce.core.offer.domain.OfferItemCriteria in project BroadleafCommerce by BroadleafCommerce.
the class OfferDataItemProvider method createItemBasedOfferWithItemCriteria.
public List<Offer> createItemBasedOfferWithItemCriteria(String orderRule, OfferDiscountType discountType, String qualRule, String targetRule) {
List<Offer> offers = createItemBasedOffer(orderRule, targetRule, discountType);
if (qualRule != null) {
Offer firstOffer = offers.get(0);
OfferItemCriteria qualCriteria = new OfferItemCriteriaImpl();
// qualCriteria.setQualifyingOffer(offers.get(0));
qualCriteria.setQuantity(1);
qualCriteria.setMatchRule(qualRule);
Set<OfferQualifyingCriteriaXref> criterias = new HashSet<OfferQualifyingCriteriaXref>();
OfferQualifyingCriteriaXref xref = new OfferQualifyingCriteriaXrefImpl();
xref.setOffer(firstOffer);
xref.setOfferItemCriteria(qualCriteria);
criterias.add(xref);
firstOffer.setQualifyingItemCriteriaXref(criterias);
}
return offers;
}
use of org.broadleafcommerce.core.offer.domain.OfferItemCriteria in project BroadleafCommerce by BroadleafCommerce.
the class OfferDataItemProvider method createOrderBasedOfferWithItemCriteria.
public List<Offer> createOrderBasedOfferWithItemCriteria(String orderRule, OfferDiscountType discountType, String orderItemMatchRule) {
List<Offer> offers = createOrderBasedOffer(orderRule, discountType);
Offer firstOffer = offers.get(0);
OfferItemCriteria qualCriteria = new OfferItemCriteriaImpl();
// qualCriteria.setQualifyingOffer(offers.get(0));
qualCriteria.setQuantity(1);
qualCriteria.setMatchRule(orderItemMatchRule);
Set<OfferQualifyingCriteriaXref> criterias = new HashSet<OfferQualifyingCriteriaXref>();
OfferQualifyingCriteriaXref xref = new OfferQualifyingCriteriaXrefImpl();
xref.setOffer(firstOffer);
xref.setOfferItemCriteria(qualCriteria);
criterias.add(xref);
firstOffer.setQualifyingItemCriteriaXref(criterias);
return offers;
}
use of org.broadleafcommerce.core.offer.domain.OfferItemCriteria in project BroadleafCommerce by BroadleafCommerce.
the class OfferDataItemProvider method createFGBasedOfferWithItemCriteria.
public List<Offer> createFGBasedOfferWithItemCriteria(String orderRule, String fgRule, OfferDiscountType discountType, String orderItemMatchRule) {
List<Offer> offers = createFGBasedOffer(orderRule, fgRule, discountType);
Offer firstOffer = offers.get(0);
OfferItemCriteria qualCriteria = new OfferItemCriteriaImpl();
qualCriteria.setQuantity(1);
qualCriteria.setMatchRule(orderItemMatchRule);
Set<OfferQualifyingCriteriaXref> criterias = new HashSet<OfferQualifyingCriteriaXref>();
OfferQualifyingCriteriaXref xref = new OfferQualifyingCriteriaXrefImpl();
xref.setOffer(firstOffer);
xref.setOfferItemCriteria(qualCriteria);
criterias.add(xref);
firstOffer.setQualifyingItemCriteriaXref(criterias);
return offers;
}
use of org.broadleafcommerce.core.offer.domain.OfferItemCriteria in project BroadleafCommerce by BroadleafCommerce.
the class OfferDataItemProvider method createItemBasedOffer.
public List<Offer> createItemBasedOffer(String orderRule, String targetRule, OfferDiscountType discountType) {
List<Offer> offers = createOrderBasedOffer(orderRule, discountType);
offers.get(0).setType(OfferType.ORDER_ITEM);
if (targetRule != null) {
Offer offer = offers.get(0);
OfferItemCriteria targetCriteria = new OfferItemCriteriaImpl();
// targetCriteria.setQualifyingOffer(offers.get(0));
targetCriteria.setQuantity(1);
targetCriteria.setMatchRule(targetRule);
OfferTargetCriteriaXref targetXref = new OfferTargetCriteriaXrefImpl();
targetXref.setOffer(offer);
targetXref.setOfferItemCriteria(targetCriteria);
offer.setTargetItemCriteriaXref(Collections.singleton(targetXref));
}
return offers;
}
use of org.broadleafcommerce.core.offer.domain.OfferItemCriteria in project BroadleafCommerce by BroadleafCommerce.
the class AbstractBaseProcessor method meetsItemQualifierSubtotal.
protected boolean meetsItemQualifierSubtotal(Offer offer, CandidatePromotionItems candidateItem) {
Money qualifyingSubtotal = offer.getQualifyingItemSubTotal();
if (!hasPositiveValue(qualifyingSubtotal)) {
if (LOG.isTraceEnabled()) {
LOG.trace("Offer " + offer.getName() + " does not have an item subtotal requirement.");
}
return true;
}
if (isEmpty(offer.getQualifyingItemCriteriaXref())) {
if (OfferType.ORDER_ITEM.equals(offer.getType())) {
if (LOG.isWarnEnabled()) {
LOG.warn("Offer " + offer.getName() + " has a subtotal item requirement but no item qualification criteria.");
}
return false;
} else {
// Checking if targets meet subtotal for item offer with no item criteria.
Money accumulatedTotal = null;
for (PromotableOrderItem orderItem : candidateItem.getAllCandidateTargets()) {
Money itemPrice = orderItem.getCurrentBasePrice().multiply(orderItem.getQuantity());
accumulatedTotal = accumulatedTotal == null ? itemPrice : accumulatedTotal.add(itemPrice);
if (accumulatedTotal.greaterThan(qualifyingSubtotal)) {
if (LOG.isTraceEnabled()) {
LOG.trace("Offer " + offer.getName() + " meets qualifying item subtotal.");
}
return true;
}
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("Offer " + offer.getName() + " does not meet qualifying item subtotal.");
}
} else {
if (candidateItem.getCandidateQualifiersMap() != null) {
Money accumulatedTotal = null;
Set<PromotableOrderItem> usedItems = new HashSet<PromotableOrderItem>();
for (OfferItemCriteria criteria : candidateItem.getCandidateQualifiersMap().keySet()) {
List<PromotableOrderItem> promotableItems = candidateItem.getCandidateQualifiersMap().get(criteria);
if (promotableItems != null) {
for (PromotableOrderItem item : promotableItems) {
if (!usedItems.contains(item)) {
usedItems.add(item);
Money itemPrice = item.getCurrentBasePrice().multiply(item.getQuantity());
accumulatedTotal = accumulatedTotal == null ? itemPrice : accumulatedTotal.add(itemPrice);
if (accumulatedTotal.greaterThan(qualifyingSubtotal)) {
if (LOG.isTraceEnabled()) {
LOG.trace("Offer " + offer.getName() + " meets the item subtotal requirement.");
}
return true;
}
}
}
}
}
}
}
if (LOG.isTraceEnabled()) {
LOG.trace("Offer " + offer.getName() + " does not meet the item subtotal qualifications.");
}
return false;
}
Aggregations