if (useLimitPerCustomer != null) {
// if partyId is not empty check previous usage
long productPromoCustomerUseSize = 0;
if (UtilValidate.isNotEmpty(partyId)) {
// check to see how many times this has been used for other orders for this customer, the remainder is the limit for this order
EntityCondition checkCondition = EntityCondition.makeCondition(UtilMisc.toList(
EntityCondition.makeCondition("productPromoId", EntityOperator.EQUALS, productPromoId),
EntityCondition.makeCondition("partyId", EntityOperator.EQUALS, partyId),
EntityCondition.makeCondition("statusId", EntityOperator.NOT_EQUAL, "ORDER_REJECTED"),
EntityCondition.makeCondition("statusId", EntityOperator.NOT_EQUAL, "ORDER_CANCELLED")), EntityOperator.AND);
productPromoCustomerUseSize = delegator.findCountByCondition("ProductPromoUseCheck", checkCondition, null, null);
}
long perCustomerThisOrder = useLimitPerCustomer.longValue() - productPromoCustomerUseSize;
if (candidateUseLimit == null || candidateUseLimit.longValue() > perCustomerThisOrder) {
candidateUseLimit = Long.valueOf(perCustomerThisOrder);
}
}
// Debug.logInfo("Promo [" + productPromoId + "] use limit after per customer check: " + candidateUseLimit, module);
Long useLimitPerPromotion = productPromo.getLong("useLimitPerPromotion");
if (useLimitPerPromotion != null) {
// check to see how many times this has been used for other orders for this customer, the remainder is the limit for this order
EntityCondition checkCondition = EntityCondition.makeCondition(UtilMisc.toList(
EntityCondition.makeCondition("productPromoId", EntityOperator.EQUALS, productPromoId),
EntityCondition.makeCondition("statusId", EntityOperator.NOT_EQUAL, "ORDER_REJECTED"),
EntityCondition.makeCondition("statusId", EntityOperator.NOT_EQUAL, "ORDER_CANCELLED")), EntityOperator.AND);
long productPromoUseSize = delegator.findCountByCondition("ProductPromoUseCheck", checkCondition, null, null);
long perPromotionThisOrder = useLimitPerPromotion.longValue() - productPromoUseSize;