on ‎2017 Mar 13 10:01 PM
Hi,
In hybris, for one PromotionResult, you can have many PromomotionActions, as it is a one to many relation. But the relation defines PromotionResult as unique.
So, When the promotion is applied, the PromotionResult is saved through jalo layer, But if you try to clone the cfter the promotion is applied (it uses modelService.save()), its throws the following error bcz of uniqueness constraint in the relation.
[de.hybris.platform.servicelayer.interceptor.impl.UniqueAttributesInterceptor@6e185c4b]:**ambiguous unique keys {promotionResult=PromotionResultModel** ()} for model PromotionOrderEntryAdjustActionModel ()
Please confirm if promotionResult can be made non-unique in the relation?
Same kind of problem: https://experts.hybris.com/questions/5902/multiple-promotionresults-for-abstractpromotionact.html
Thanks, Chitra
Request clarification before answering.
You are correct. Another Workaround is
The change is actually very minimal. The order of the following lines is reversed:
getModelService().saveAll(customer, orderModel); // FAILS HERE
// clear the promotionResults that where cloned from cart //PromotionService.transferPromotionsToOrder will copy them over //bellow. orderModel.setAllPromotionResults(Collections. emptySet());
...
The second line will clear the promotions and avoid the unique key violation. This is actually done anyway, we clear the promotions after cloning the order, they are then applied again. The issue here is that in some cases depending on the promotion result we run into this unique key violation when saving the order. The fix is simply to clear the promotions before saving.
// clear the promotionResults that where cloned from cart //PromotionService.transferPromotionsToOrder will copy them over //bellow. orderModel.setAllPromotionResults(Collections. emptySet());
getModelService().saveAll(customer, orderModel); // SAVES FINE ...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Chitra,
Thanks for the response. We tried the same and it worked but is these changes are suggestible because this is something provided Hybris OOTB and changing Hybris OOTB behavior may lead to some other unknown issue in application.
Thanks & Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
We are also facing similar kind of problem any solution to same.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Anshul,
In promotion-items.xml the PromotionResult to PromotionAction relation is defined as follows. Yes, if we remove unique="true" field from sourceElement's modifiers tag than the problem seems to be resolved because UniqueAttributesInterceptor checks the uniqueness no longer (which is natural for a one to many relationships). But we do not know if it affects any other parts of the application hence we have to do proper testing.
Workaround:
<modifiers read="true" write="true" initial="true" optional="true" search="true"/>
Regards, Chitra
What is the business rationale behind cloning a cart containing promotions? Whats the use case here?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.