use of org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetail in project BroadleafCommerce by BroadleafCommerce.
the class OfferServiceUtilitiesImpl method markRelatedQualifiersAndTargetsForItemCriteria.
@Override
public int markRelatedQualifiersAndTargetsForItemCriteria(PromotableCandidateItemOffer itemOffer, PromotableOrder order, OrderItemHolder orderItemHolder, OfferItemCriteria itemCriteria, List<PromotableOrderItemPriceDetail> priceDetails, ItemOfferMarkTargets itemOfferMarkTargets) {
sortQualifierItemDetails(priceDetails, itemOffer.getOffer().getApplyDiscountToSalePrice());
// Calculate the number of qualifiers needed that will not receive the promotion.
// These will be reserved first before the target is assigned.
int qualifierQtyNeeded = itemCriteria.getQuantity();
for (PromotableOrderItemPriceDetail detail : priceDetails) {
OrderItem oi = detail.getPromotableOrderItem().getOrderItem();
if (qualifierQtyNeeded > 0) {
int itemQtyAvailableToBeUsedAsQualifier = detail.getQuantityAvailableToBeUsedAsQualifier(itemOffer);
if (itemQtyAvailableToBeUsedAsQualifier > 0) {
// We have found a qualifier that meets this offer criteria. First, we'll save some state that we
// might need in the future.
OfferItemCriteria previousQualifierCriteria = null;
for (PromotionQualifier possibleQualifier : detail.getPromotionQualifiers()) {
if (possibleQualifier.getPromotion().equals(itemOffer.getOffer())) {
previousQualifierCriteria = possibleQualifier.getItemCriteria();
break;
}
}
// Go ahead and mark this item as a qualifier
int qtyToMarkAsQualifier = Math.min(qualifierQtyNeeded, itemQtyAvailableToBeUsedAsQualifier);
qualifierQtyNeeded -= qtyToMarkAsQualifier;
PromotionQualifier pq = detail.addPromotionQualifier(itemOffer, itemCriteria, qtyToMarkAsQualifier);
pq.setPrice(detail.getPromotableOrderItem().getPriceBeforeAdjustments(itemOffer.getOffer().getApplyDiscountToSalePrice()));
// that there is an eligible target(s) and continue on.
if (itemOfferMarkTargets.markTargets(itemOffer, order, oi, true)) {
// We found a target. Let's save this related order item used as the qualifier in case
// we succeed
orderItemHolder.setOrderItem(oi);
} else {
// If we didn't find a target, we need to roll back how we marked this item as a qualifier.
qualifierQtyNeeded += qtyToMarkAsQualifier;
if (pq.getQuantity() == qtyToMarkAsQualifier) {
detail.getPromotionQualifiers().remove(pq);
} else {
pq.setItemCriteria(previousQualifierCriteria);
pq.setQuantity(pq.getQuantity() - qtyToMarkAsQualifier);
}
}
}
}
if (qualifierQtyNeeded == 0) {
break;
}
}
return qualifierQtyNeeded;
}
use of org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetail in project BroadleafCommerce by BroadleafCommerce.
the class OfferServiceUtilitiesImpl method applyAdjustmentsForItemPriceDetails.
@Override
public void applyAdjustmentsForItemPriceDetails(PromotableCandidateItemOffer itemOffer, List<PromotableOrderItemPriceDetail> itemPriceDetails) {
for (PromotableOrderItemPriceDetail itemPriceDetail : itemPriceDetails) {
for (PromotionDiscount discount : itemPriceDetail.getPromotionDiscounts()) {
if (discount.getPromotion().equals(itemOffer.getOffer())) {
if (itemOffer.getOffer().isTotalitarianOffer() || !itemOffer.getOffer().isCombinableWithOtherOffers()) {
// the value of the item
if (adjustmentIsNotGoodEnoughToBeApplied(itemOffer, itemPriceDetail)) {
break;
}
}
OrderItem orderItem = itemPriceDetail.getPromotableOrderItem().getOrderItem();
Boolean offerCanApplyToChildOrderItems = itemOffer.getOffer().getApplyToChildItems();
if (isAddOnOrderItem(orderItem) && !offerCanApplyToChildOrderItems) {
break;
}
applyOrderItemAdjustment(itemOffer, itemPriceDetail);
break;
}
}
}
}
Aggregations