Class BaseCandidateOffer
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
CandidateFulfillmentGroupOffer
,CandidateItemOffer
,CandidateOrderOffer
- Author:
- Chad Harchar (charchar)
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncalculateOverrideSegment
(String offerSegment, OfferCode offerCd, com.broadleafcommerce.promotion.offer.client.web.context.OfferCodeDto ocDto) Determines the segment to use for this offer based on the passed in codes.protected boolean
boolean
boolean
Convert offer data into easier structures for combinability algorithmsjavax.money.CurrencyUnit
Offer.getCurrency()
if specified, otherwiseEnhancedOrder.getCurrency()
is used.Convenience method to access this property to improve code readabilityConvenience method to access this property to improve code readabilityConvenience method to access this property to improve code readabilityStore the list of excludedItemIds included which can be passed in via the OfferCodeDtogetOffer()
The candidateOffer
.Holds the combinability criteria for this offer.When processing the same offer more than once due to the offer applying to more than one segment, we need to override its id as part of the offer copy.When processing the same offer for more than one segment, we need to override the id used for the underlying offer id temporarily.javax.money.MonetaryAmount
The total potential amount saved by applying this offer to its targets.TheRoundingMode
to use when rounding.int
hashCode()
void
Using the structure stored bypopulatePropertiesFromCodeData(OfferCodeData)
this method updates the excludedIds for this offer if present on theOfferCodeDto
.boolean
boolean
isNotExcludedFromOffer
(EnhancedOrder order, EnhancedLineItem item) Returns true if the passed in item is NOT excluded from this offer.boolean
Determines whether to roundpotentialSavings
.protected String
normalizeSegment
(String segment) void
populateCombinabilityStructures
(CandidateOffers candidateOffers) protected void
populateCombinabilityStructuresUsedBySameTargetType
(CandidateOffers candidateOffers) void
populatePropertiesFromCodeData
(OfferCodeData codeData) protected boolean
segmentIsValid
(String offerSegment, OfferCode offerCd, com.broadleafcommerce.promotion.offer.client.web.context.OfferCodeDto ocDto) void
setCombinableOverrides
(Set<String> combinableOverrides) Convert offer data into easier structures for combinability algorithmsvoid
setCurrency
(javax.money.CurrencyUnit currency) Offer.getCurrency()
if specified, otherwiseEnhancedOrder.getCurrency()
is used.void
setExcludedItemIds
(Set<String> excludedItemIds) Store the list of excludedItemIds included which can be passed in via the OfferCodeDtovoid
setNonCombinableOverrides
(Set<String> nonCombinableOverrides) void
The candidateOffer
.void
setOfferCodesMap
(Map<String, OfferCode> offerCodesMap) void
setOfferCombinabilityCriteriaKey
(OfferCombinabilityCriteriaKey offerCombinabilityCriteriaKey) Holds the combinability criteria for this offer.void
setOfferDtosMap
(Map<String, com.broadleafcommerce.promotion.offer.client.web.context.OfferCodeDto> offerDtosMap) void
setOverrideOfferId
(String overrideOfferId) When processing the same offer for more than one segment, we need to override the id used for the underlying offer id temporarily.void
setPotentialSavings
(javax.money.MonetaryAmount potentialSavings) The total potential amount saved by applying this offer to its targets.void
setRoundingMode
(RoundingMode roundingMode) TheRoundingMode
to use when rounding.void
setRoundOfferValues
(boolean roundOfferValues) Determines whether to roundpotentialSavings
.void
setSegment
(String segment) Store the effective segment for this Offer.void
setStackableOverrides
(Set<String> stackableOverrides) toString()
protected void
updateAmountCurrency
(@NonNull Offer offer, @NonNull javax.money.CurrencyUnit currencyToSet, @NonNull Function<Offer, javax.money.MonetaryAmount> amountGetter, @NonNull BiConsumer<Offer, javax.money.MonetaryAmount> amountSetter) void
Updates theCurrencySupplier.getCurrency()
of all theMonetaryAmount
fields for thegetOffer()
, if theOffer.getCurrency()
is null.void
updateOfferCombinabilityCriteria
(CandidateOffers candidateOffers) boolean
Using the structure stored bypopulatePropertiesFromCodeData(OfferCodeData)
this method verifies that segments (if used) are valid for the backing Offer
-
Constructor Details
-
BaseCandidateOffer
public BaseCandidateOffer()
-
-
Method Details
-
populateCombinabilityStructures
-
populateCombinabilityStructuresUsedBySameTargetType
-
updateOfferCombinabilityCriteria
-
getDiscountTargetType
Convenience method to access this property to improve code readability -
getDiscountMethodType
Convenience method to access this property to improve code readability -
getDiscountAmount
Convenience method to access this property to improve code readability -
getOfferId
When processing the same offer more than once due to the offer applying to more than one segment, we need to override its id as part of the offer copy. -
isApplicableToDependentItems
public boolean isApplicableToDependentItems() -
validateCodesMatchOfferSegments
public boolean validateCodesMatchOfferSegments()Using the structure stored bypopulatePropertiesFromCodeData(OfferCodeData)
this method verifies that segments (if used) are valid for the backing Offer -
segmentIsValid
-
normalizeSegment
-
calculateOverrideSegment
protected Optional<String> calculateOverrideSegment(String offerSegment, OfferCode offerCd, com.broadleafcommerce.promotion.offer.client.web.context.OfferCodeDto ocDto) Determines the segment to use for this offer based on the passed in codes.- Parameters:
offerSegment
- The value ofOffer.getSegment()
after callingnormalizeSegment(String)
offerCd
- TheOfferCode
which can narrow the segmentocDto
- TheOfferCodeDto
which can further narrow the segment- Returns:
-
getAllValidSegments
-
initializeExcludedCartItemIds
public void initializeExcludedCartItemIds()Using the structure stored bypopulatePropertiesFromCodeData(OfferCodeData)
this method updates the excludedIds for this offer if present on theOfferCodeDto
. -
populatePropertiesFromCodeData
-
getSegment
-
isNotExcludedFromOffer
Returns true if the passed in item is NOT excluded from this offer.- Parameters:
order
-item
-- Returns:
- true if the passed in item is not excluded from this offer.
-
excludeDiscountedItemsFromTotal
public boolean excludeDiscountedItemsFromTotal() -
updateMonetaryAmountCurrencyIfNeeded
public void updateMonetaryAmountCurrencyIfNeeded()Updates theCurrencySupplier.getCurrency()
of all theMonetaryAmount
fields for thegetOffer()
, if theOffer.getCurrency()
is null.This is only needed when
Offer.getCurrency()
is null, because that means the offer doesn't care about the currency and should use theEnhancedOrder.getCurrency()
instead. However, theCurrencySupplier.getCurrency()
of those fields were resolved inJpaOffer.preFromMe(ContextInfo, Object)
based on theContextInfo
, which does not have context of theEnhancedOrder.getCurrency()
, it would cause currency mismatchMonetaryException
if the currency is not updated accordingly. -
updateAmountCurrency
protected void updateAmountCurrency(@NonNull @NonNull Offer offer, @NonNull @NonNull javax.money.CurrencyUnit currencyToSet, @NonNull @NonNull Function<Offer, javax.money.MonetaryAmount> amountGetter, @NonNull @NonNull BiConsumer<Offer, javax.money.MonetaryAmount> amountSetter) - Parameters:
offer
- theOffer
to update itsMonetaryAmount
field forcurrencyToSet
- theCurrencyUnit
to update theCurrencySupplier.getCurrency()
toamountGetter
- the getter to get theMonetaryAmount
from theOffer
amountSetter
- the setter to set theMonetaryAmount
with the updated currency to theOffer
-
getOffer
The candidateOffer
.- Returns:
- The candidate
Offer
.
-
getPotentialSavings
public javax.money.MonetaryAmount getPotentialSavings()The total potential amount saved by applying this offer to its targets.- Returns:
- The total potential amount saved by applying this offer to its targets.
-
getCurrency
public javax.money.CurrencyUnit getCurrency()Offer.getCurrency()
if specified, otherwiseEnhancedOrder.getCurrency()
is used.- Returns:
- The
Offer.getCurrency()
orEnhancedOrder.getCurrency()
order's currency}. - See Also:
-
isRoundOfferValues
public boolean isRoundOfferValues()Determines whether to round
potentialSavings
. Default is false. Note: This is only relevant for adjustments that apply to items. The additional precision is important when multiplying by a "qty". Order and fulfillment group adjustments will always be rounded in the default implementations.It is sometimes problematic to use
DiscountMethodType.PERCENT_OFF
offers
with regards to rounding. For example, consider an item that costs $9.99 and has a 50% discount. To be precise, the offer value is 4.995, but this may be a strange value to display to the user depending on the currency being used. Keeping this false produces more accurate results when using quantities > 1. For example, 20% off of $9.99 with a quantity of 5 will produce a savings of exactly $9.99 which would be expected. The savings will always be rounded to the correct precision of the currency, however theS
"totalSavings" will always be displays may want to round the value unit adjustment will be up to 5 digits of precision if roundOfferValues is false. Client displays may with to round the adjustment amount if showing per quantity level adjustments.- Returns:
- whether to round
potentialSavings
.
-
getRoundingMode
TheRoundingMode
to use when rounding. Default isRoundingMode.HALF_EVEN
.- Returns:
- The
RoundingMode
to use when rounding.
-
getOfferCombinabilityCriteriaKey
Holds the combinability criteria for this offer. The offer domain contains combinability flags and rules but the criteria will vary with each execution of the offer engine. For example, if "item offer a" can be combined with any "order offer except b" and b is not in the scope of the current offer engine execution, then we can say that "item offer a" can be combined with ANY order offer. Practically, this allows us to reduce the overall complexity of offer engine by getting rid of scenarios that are irrelevant to the current execution. -
getCombinableOverrides
Convert offer data into easier structures for combinability algorithms -
getNonCombinableOverrides
-
getStackableOverrides
-
getOverrideOfferId
When processing the same offer for more than one segment, we need to override the id used for the underlying offer id temporarily. -
getExcludedItemIds
Store the list of excludedItemIds included which can be passed in via the OfferCodeDto- See Also:
-
getOfferCodesMap
-
getOfferDtosMap
-
setOffer
The candidateOffer
.- Parameters:
offer
- The candidateOffer
.
-
setPotentialSavings
public void setPotentialSavings(javax.money.MonetaryAmount potentialSavings) The total potential amount saved by applying this offer to its targets.- Parameters:
potentialSavings
- The total potential amount saved by applying this offer to its targets.
-
setCurrency
public void setCurrency(javax.money.CurrencyUnit currency) Offer.getCurrency()
if specified, otherwiseEnhancedOrder.getCurrency()
is used.- Parameters:
currency
- TheOffer.getCurrency()
orEnhancedOrder.getCurrency()
order's currency}.- See Also:
-
setRoundOfferValues
public void setRoundOfferValues(boolean roundOfferValues) Determines whether to round
potentialSavings
. Default is false. Note: This is only relevant for adjustments that apply to items. The additional precision is important when multiplying by a "qty". Order and fulfillment group adjustments will always be rounded in the default implementations.It is sometimes problematic to use
DiscountMethodType.PERCENT_OFF
offers
with regards to rounding. For example, consider an item that costs $9.99 and has a 50% discount. To be precise, the offer value is 4.995, but this may be a strange value to display to the user depending on the currency being used. Keeping this false produces more accurate results when using quantities > 1. For example, 20% off of $9.99 with a quantity of 5 will produce a savings of exactly $9.99 which would be expected. The savings will always be rounded to the correct precision of the currency, however theS
"totalSavings" will always be displays may want to round the value unit adjustment will be up to 5 digits of precision if roundOfferValues is false. Client displays may with to round the adjustment amount if showing per quantity level adjustments.- Parameters:
roundOfferValues
- whether to roundpotentialSavings
.
-
setRoundingMode
TheRoundingMode
to use when rounding. Default isRoundingMode.HALF_EVEN
.- Parameters:
roundingMode
- TheRoundingMode
to use when rounding.
-
setOfferCombinabilityCriteriaKey
public void setOfferCombinabilityCriteriaKey(OfferCombinabilityCriteriaKey offerCombinabilityCriteriaKey) Holds the combinability criteria for this offer. The offer domain contains combinability flags and rules but the criteria will vary with each execution of the offer engine. For example, if "item offer a" can be combined with any "order offer except b" and b is not in the scope of the current offer engine execution, then we can say that "item offer a" can be combined with ANY order offer. Practically, this allows us to reduce the overall complexity of offer engine by getting rid of scenarios that are irrelevant to the current execution. -
setCombinableOverrides
Convert offer data into easier structures for combinability algorithms -
setNonCombinableOverrides
-
setStackableOverrides
-
setSegment
Store the effective segment for this Offer. The segment can be narrowed by the use of an OfferCode or OfferCodeDto. -
setOverrideOfferId
When processing the same offer for more than one segment, we need to override the id used for the underlying offer id temporarily. -
setExcludedItemIds
Store the list of excludedItemIds included which can be passed in via the OfferCodeDto- See Also:
-
setOfferCodesMap
-
setOfferDtosMap
-
equals
-
canEqual
-
hashCode
public int hashCode() -
toString
-