cancel
Showing results for 
Search instead for 
Did you mean: 

How can i get List of all promotion in Hybris 5.6

Former Member
0 Kudos

How can i get list of all promotions and i would be using promotion group and enable/disable flag from those promotion irrespective of the type of the promotion?

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

I used below groovy:

import de.hybris.platform.core.PK import de.hybris.platform.servicelayer.model.ModelService import de.hybris.platform.servicelayer.search.FlexibleSearchQuery import de.hybris.platform.servicelayer.search.FlexibleSearchService import de.hybris.platform.promotions.model.AbstractPromotionModel import de.hybris.platform.promotions.model.PromotionGroupModel;

final ModelService modelService = spring.getBean("modelService") final FlexibleSearchService fss = spring.getBean("flexibleSearchService") final String queryString = "SELECT {" + AbstractPromotionModel.PK + "} FROM {" + AbstractPromotionModel._TYPECODE + " AS promo} ";

final FlexibleSearchQuery searchQuery = new FlexibleSearchQuery(queryString)

fss.search(searchQuery).result.each { pk -> final AbstractPromotionModel promotion = modelService.get(pk) if(promotion.getEnabled()){ List promotionGroup = promotion.getPromotionGroups(); for(PromotionGroupModel pg : promotionGroup){ if(length(promotionGroup.getIdentifier()) <= 3){ println(promotion.getCode() + ": have coupon group (with count of groups:" + promotion.getPromotionGroups().size() + ")") break; } } } println(promotion.getCode() + ": have promotion group only (with count of groups:" + promotion.getPromotionGroups().size() + ")"); } println("Completed")

But i am getting below error :

Script execution has failed [reason: de.hybris.platform.servicelayer.exceptions.ModelTypeNotSupportedException: invalid source object OrderThresholdDiscountPromotionModel (8796093059986) only supports Item instances] Page description

former_member357259
Active Contributor
0 Kudos

You can first use ModelService.get(PK) to get the AbstractPromotionModel instance and then AbstractPromotionModel.getPromotionGroup()

Former Member
0 Kudos

Thanks Charles.,

From the AbstractPromotion i got the list PK for all the Promotions, but now my requirement is to get promotion group for each promotion but i am not able to get this list.

How can i get an model from the PK of the Abstract promotion

former_member357259
Active Contributor
0 Kudos

On the service layer, you can use the PromotionsService to retrieve order or product level promotions: https://help.hybris.com/6.1.0/api/commercesuite/index.html

Otherwise, you can use ModelService to retrieve all items of type AbstractPromotion to get all promotions irrespective of the type