Class DefaultBundleCommerceRuleService
- java.lang.Object
-
- de.hybris.platform.configurablebundleservices.bundle.impl.DefaultBundleCommerceRuleService
-
- All Implemented Interfaces:
BundleRuleService
- Direct Known Subclasses:
DefaultBundleRuleService
public class DefaultBundleCommerceRuleService extends java.lang.Object implements BundleRuleService
Default implementation of the bundle rule serviceBundleRuleService. It searches for the the lowest price (based on bundle price rules) for a product that is a part of a bundle.
-
-
Constructor Summary
Constructors Constructor Description DefaultBundleCommerceRuleService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleancheckBundleRuleForConditionalProduct(AbstractBundleRuleModel bundleRule, java.util.Set<ProductModel> otherProductsInSameBundle, ProductModel product)Applies the check logic for disable product rules to test if the givenbundleRulemeets the requirements.protected booleancheckBundleRuleForTargetProduct(AbstractBundleRuleModel rule, java.util.Set<ProductModel> otherProductsInSameBundle)Applies the rules for conditional products to check if the givenrulemeets the requirements.protected booleancheckRuleIsFulfilled(AbstractBundleRuleModel bundleRule, ProductModel product, java.util.Set<ProductModel> otherProductsInSameBundle)java.lang.StringcreateMessageForDisableRule(DisableProductBundleRuleModel disableRule, ProductModel product)Generates the message explaining why given product is disabled with specific rule.protected AbstractBundleRuleModelevaluateBundleRules(java.util.List<AbstractBundleRuleModel> bundleRules, ProductModel product, java.util.Set<ProductModel> otherProductsInSameBundle)Evaluates if any of the givenbundleRules is applicable for the givenproductin the context of the list of other products that are already in the same bundle.protected BundleTemplateServicegetBundleTemplateService()protected java.util.Set<ProductModel>getCartProductsInSameBundle(AbstractOrderModel order, ProductModel product, EntryGroup bundleEntryGroup)Returns a list of of products that belong to the same bundle entry group in the given multi-cart as the givenproductChangeProductPriceBundleRuleModelgetChangePriceBundleRule(BundleTemplateModel targetComponent, ProductModel targetProduct, ProductModel conditionalProduct, CurrencyModel currency)Returns aChangeProductPriceBundleRuleModelvalid for the giventargetProduct.ChangeProductPriceBundleRuleModelgetChangePriceBundleRuleForOrderEntry(AbstractOrderEntryModel entry)Returns aChangeProductPriceBundleRuleModelvalid for the givenorderEntryModel.ChangeProductPriceBundleRuleModelgetChangePriceBundleRuleWithLowestPrice(ProductModel targetProduct, CurrencyModel currency)Searches for the lowest priceChangeProductPriceBundleRuleModelof the giventargetProductin any bundle packageprotected ChangeProductPriceBundleRuleDaogetChangeProductPriceBundleRuleDao()protected BundleRuleDaogetDisableProductBundleRuleDao()java.util.List<DisableProductBundleRuleModel>getDisableProductBundleRules(ProductModel product, EntryGroup entryGroup, AbstractOrderModel order)DisableProductBundleRuleModelgetDisableRuleForBundleProduct(BundleTemplateModel bundleTemplate, ProductModel product1, ProductModel product2)Returns aDisableProductBundleRuleModelwhich does not allow that the given productsproduct1andproduct2are added together to a bundle.DisableProductBundleRuleModelgetDisableRuleForBundleProduct(AbstractOrderModel masterAbstractOrder, ProductModel product, EntryGroup entryGroup, boolean ignoreCurrentProducts)Returns aDisableProductBundleRuleModelvalid for the givenproductignoring productsignoreProductsin the cart.protected EntryGroupServicegetEntryGroupService()protected L10NServicegetL10NService()protected ChangeProductPriceBundleRuleModelgetLowestPriceForTargetProductAndTemplate(BundleTemplateModel bundleTemplate, ProductModel targetProduct, CurrencyModel currency, java.util.Set<ProductModel> otherProductsInSameBundle)Finds theChangeProductPriceBundleRuleModelwith the lowest price for the giventargetProduct.protected ModelServicegetModelService()protected SearchRestrictionServicegetSearchRestrictionService()protected SessionServicegetSessionService()voidsetBundleTemplateService(BundleTemplateService bundleTemplateService)voidsetChangeProductPriceBundleRuleDao(ChangeProductPriceBundleRuleDao changeProductPriceBundleRuleDao)voidsetDisableProductBundleRuleDao(BundleRuleDao disableProductBundleRuleDao)voidsetEntryGroupService(EntryGroupService entryGroupService)voidsetL10NService(L10NService l10nService)voidsetModelService(ModelService modelService)voidsetSearchRestrictionService(SearchRestrictionService searchRestrictionService)voidsetSessionService(SessionService sessionService)protected <A extends ItemModel,R>
Runrestricted(A model, java.util.function.Function<A,R> getter)Executesgetterin search-restrictions-off context.
-
-
-
Method Detail
-
getChangePriceBundleRuleForOrderEntry
@Nullable public ChangeProductPriceBundleRuleModel getChangePriceBundleRuleForOrderEntry(@Nonnull AbstractOrderEntryModel entry)
Description copied from interface:BundleRuleServiceReturns aChangeProductPriceBundleRuleModelvalid for the givenorderEntryModel. The method calculates the lowest product price for the product in the givenorderEntryModelwhich is added to a bundle. The calculation is based on the entry's bundle template and the other products in the same bundle (conditional products)- Specified by:
getChangePriceBundleRuleForOrderEntryin interfaceBundleRuleService- Parameters:
entry- entry that is added to the cart as part of a bundle- Returns:
- a
ChangeProductPriceBundleRuleModelif existing or null
-
getDisableProductBundleRules
public java.util.List<DisableProductBundleRuleModel> getDisableProductBundleRules(ProductModel product, EntryGroup entryGroup, AbstractOrderModel order)
Description copied from interface:BundleRuleServiceReturns a list ofDisableProductBundleRuleModelvalid for the givenproductin the givenorder. The method searches forDisableProductBundleRuleModels that can be applied if the givenproductis or would be added to the givenorderin the context of the givenentryGroup.- Specified by:
getDisableProductBundleRulesin interfaceBundleRuleService- Parameters:
product- product that is or shall be added to the bundle and for which applicableDisableProductBundleRuleModels are searchedentryGroup- entry group representing a bundle to which theproductis or shall be addedorder- the cart/order to which the givenproductis added- Returns:
- the list of
DisableProductBundleRuleModelwhich are blocking addingproductcannot be added to the bundle in the cart.
-
getChangePriceBundleRule
@Nullable public ChangeProductPriceBundleRuleModel getChangePriceBundleRule(@Nonnull BundleTemplateModel targetComponent, @Nonnull ProductModel targetProduct, @Nonnull ProductModel conditionalProduct, @Nonnull CurrencyModel currency)
Description copied from interface:BundleRuleServiceReturns aChangeProductPriceBundleRuleModelvalid for the giventargetProduct. The method calculates (forecasts) the lowest product price for the giventargetProductwhich shall be added to a bundle based on the given bundle template (targetComponent) in combination with the givenconditionalProduct. The bundle or a cart to which the given products should be added may or may not yet exist. The method just forecasts the possible price for the given combination of input parameters.- Specified by:
getChangePriceBundleRulein interfaceBundleRuleService- Parameters:
targetComponent- bundle template based on which the giventargetProductis or shall be added to a bundletargetProduct- product that is added to a bundle and for which the product price is calculatedconditionalProduct- second product that is added to the same bundle as the giventargetProductand that is the condition for aChangeProductPriceBundleRuleModelto be selectedcurrency- the currency theChangeProductPriceBundleRuleModelmust match to be selected- Returns:
- a
ChangeProductPriceBundleRuleModelif existing or null
-
getChangePriceBundleRuleWithLowestPrice
@Nullable public ChangeProductPriceBundleRuleModel getChangePriceBundleRuleWithLowestPrice(@Nonnull ProductModel targetProduct, @Nonnull CurrencyModel currency)
Description copied from interface:BundleRuleServiceSearches for the lowest priceChangeProductPriceBundleRuleModelof the giventargetProductin any bundle package- Specified by:
getChangePriceBundleRuleWithLowestPricein interfaceBundleRuleService- Parameters:
targetProduct- the product for which the lowest bundle price is searchedcurrency- the currency theChangeProductPriceBundleRuleModelmust match to be selected- Returns:
ChangeProductPriceBundleRuleModelif existing or null
-
getLowestPriceForTargetProductAndTemplate
@Nullable protected ChangeProductPriceBundleRuleModel getLowestPriceForTargetProductAndTemplate(BundleTemplateModel bundleTemplate, ProductModel targetProduct, CurrencyModel currency, java.util.Set<ProductModel> otherProductsInSameBundle)
Finds theChangeProductPriceBundleRuleModelwith the lowest price for the giventargetProduct. AllChangeProductPriceBundleRuleModels which are assigned to the givenbundleTemplateand have the giventargetProductas target product and meet the requirements for conditional products are selected. The prices of these rules are then evaluated: TheChangeProductPriceBundleRuleModelthat matches the givencurrencyand has the lowest price, is returned.
-
getDisableRuleForBundleProduct
@Nullable public DisableProductBundleRuleModel getDisableRuleForBundleProduct(AbstractOrderModel masterAbstractOrder, ProductModel product, EntryGroup entryGroup, boolean ignoreCurrentProducts)
Description copied from interface:BundleRuleServiceReturns aDisableProductBundleRuleModelvalid for the givenproductignoring productsignoreProductsin the cart. The method searches forDisableProductBundleRuleModel's that can be applied if the givenproductis or would be added to the givenmasterAbstractOrderin the context of the givenentryGroupandbundleTemplate.- Specified by:
getDisableRuleForBundleProductin interfaceBundleRuleService- Parameters:
masterAbstractOrder- the master cart/order to which the givenproductis addedproduct- product that is or shall be added to the bundle and for which applicableDisableProductBundleRuleModel's are searchedentryGroup- entry group based on which the givenproductis or shall be added to the bundleignoreCurrentProducts- if the products in the current bundletemplate should be ignored- Returns:
- the first
DisableProductBundleRuleModelthat is found which means that the givenproductcannot be added to the bundle in the cart.nullif noDisableProductBundleRuleModelapplies and the product can be added to the bundle.
-
getDisableRuleForBundleProduct
@Nullable public DisableProductBundleRuleModel getDisableRuleForBundleProduct(@Nonnull BundleTemplateModel bundleTemplate, @Nonnull ProductModel product1, @Nonnull ProductModel product2)
Description copied from interface:BundleRuleServiceReturns aDisableProductBundleRuleModelwhich does not allow that the given productsproduct1andproduct2are added together to a bundle. In case no such disable rule existsnullis returned.- Specified by:
getDisableRuleForBundleProductin interfaceBundleRuleService- Parameters:
bundleTemplate- bundle template based on which the giventargetProductandconditionalProductshall be added to the bundleproduct1- first product that shall be added to the bundleproduct2- second product that shall be added to the bundle- Returns:
- the first
DisableProductBundleRuleModelthat is found which means that the givenproduct1andproduct2cannot be added together to the bundle in the cart.nullif noDisableProductBundleRuleModelapplies and the products can be added to the bundle.
-
evaluateBundleRules
protected AbstractBundleRuleModel evaluateBundleRules(java.util.List<AbstractBundleRuleModel> bundleRules, ProductModel product, java.util.Set<ProductModel> otherProductsInSameBundle)
Evaluates if any of the givenbundleRules is applicable for the givenproductin the context of the list of other products that are already in the same bundle. Depending on whether the givenproductis a target or a conditional product of the bundleRule the check itself is done either in method checkBundleRuleForTargetProduct or method checkBundleRuleForConditionalProduct.
-
getCartProductsInSameBundle
protected java.util.Set<ProductModel> getCartProductsInSameBundle(AbstractOrderModel order, ProductModel product, EntryGroup bundleEntryGroup)
Returns a list of of products that belong to the same bundle entry group in the given multi-cart as the givenproduct
-
checkBundleRuleForTargetProduct
protected boolean checkBundleRuleForTargetProduct(AbstractBundleRuleModel rule, java.util.Set<ProductModel> otherProductsInSameBundle)
Applies the rules for conditional products to check if the givenrulemeets the requirements. Returnstrueif the given list of productsotherProductsInSameBundlematches the list of conditional products of the givenrule, otherwisefalse.
-
checkBundleRuleForConditionalProduct
protected boolean checkBundleRuleForConditionalProduct(AbstractBundleRuleModel bundleRule, java.util.Set<ProductModel> otherProductsInSameBundle, ProductModel product)
Applies the check logic for disable product rules to test if the givenbundleRulemeets the requirements. Returnstrueif the givenbundleRuleis of type "ALL" and the givenproductis listed as a conditional product, all other conditional products and at least one of the target products are already added to the bundle in the cart. It also returnstrueif the givenbundleRuleis of type "ANY" and the givenproductis listed as a conditional product and at least one of the target products is already added to the bundle in the cart. In all other cases it returnsfalse. It is assumed that the givenproductis in the list of conditional products of the givenbundleRule.
-
checkRuleIsFulfilled
protected boolean checkRuleIsFulfilled(AbstractBundleRuleModel bundleRule, ProductModel product, java.util.Set<ProductModel> otherProductsInSameBundle)
-
unrestricted
protected <A extends ItemModel,R> R unrestricted(A model, java.util.function.Function<A,R> getter)
Executesgetterin search-restrictions-off context.- Type Parameters:
A- type of the objectR- type of the data- Parameters:
model- persistent object to get data fromgetter- data obtaining logic- Returns:
- data collected in restriction-free content
-
createMessageForDisableRule
public java.lang.String createMessageForDisableRule(DisableProductBundleRuleModel disableRule, ProductModel product)
Description copied from interface:BundleRuleServiceGenerates the message explaining why given product is disabled with specific rule.- Specified by:
createMessageForDisableRulein interfaceBundleRuleService- Parameters:
disableRule-DisableProductBundleRuleModelwhich disabled given product for specific conditional productsproduct- Disabled product- Returns:
- Message about the disable rule for given product
-
getBundleTemplateService
protected BundleTemplateService getBundleTemplateService()
-
setBundleTemplateService
public void setBundleTemplateService(BundleTemplateService bundleTemplateService)
-
getChangeProductPriceBundleRuleDao
protected ChangeProductPriceBundleRuleDao getChangeProductPriceBundleRuleDao()
-
setChangeProductPriceBundleRuleDao
public void setChangeProductPriceBundleRuleDao(ChangeProductPriceBundleRuleDao changeProductPriceBundleRuleDao)
-
getDisableProductBundleRuleDao
protected BundleRuleDao getDisableProductBundleRuleDao()
-
setDisableProductBundleRuleDao
public void setDisableProductBundleRuleDao(BundleRuleDao disableProductBundleRuleDao)
-
getSearchRestrictionService
protected SearchRestrictionService getSearchRestrictionService()
-
setSearchRestrictionService
public void setSearchRestrictionService(SearchRestrictionService searchRestrictionService)
-
getModelService
protected ModelService getModelService()
-
setModelService
public void setModelService(ModelService modelService)
-
getSessionService
protected SessionService getSessionService()
-
setSessionService
public void setSessionService(SessionService sessionService)
-
getEntryGroupService
protected EntryGroupService getEntryGroupService()
-
setEntryGroupService
public void setEntryGroupService(EntryGroupService entryGroupService)
-
getL10NService
protected L10NService getL10NService()
-
setL10NService
public void setL10NService(L10NService l10nService)
-
-