Applied promotions of an order - IBM WebSphere Commerce
In this post we will see how we can get the name and other details of promotions already applied to an order from a controller command. These details are stored in the PX_PROMOARG table in XML format. So for this task we need to fetch the PromotionArgument object for the order from the PX_PROMOARG table.
This is achieved using PromotionArgumentSessionBeanPersistenceManager, this class provides a load() method which accepts OrderKey using which we can load the PromotionArgument for the order. From the PromotionArgument we can get the list of PromotionExecutionRecords.
Below is sample code to get all the promotions applied to an order and print the name and description of the promotions.
Hope this help someone. If you find any issue in above code or know better alternatives to this code, do share with us through the comment section. Feel free to share this page with your friends and colleagues.
Thanks!
This is achieved using PromotionArgumentSessionBeanPersistenceManager, this class provides a load() method which accepts OrderKey using which we can load the PromotionArgument for the order. From the PromotionArgument we can get the list of PromotionExecutionRecords.
Below is sample code to get all the promotions applied to an order and print the name and description of the promotions.
OrderKey ordKey = new OrderKey(new Long(orderId));
PromotionArgumentSessionBeanPersistenceManager promoManager = new PromotionArgumentSessionBeanPersistenceManager();
PromotionArgument promArg = promoManager.load(ordKey);
Iterator prmoExeRecds = promArg.getPromotionExecutionRecords();
while(prmoExeRecds.hasNext()) {
PromotionExecutionRecord promoExeRecd = (PromotionExecutionRecord) prmoExeRecds.next();
Promotion promotion = promoExeRecd.getPromotion();
System.out.println("Name: " + promotion.getName());
System.out.println("Admin description: " + promotion.getDescription(commandContext.getLocale(), com.ibm.commerce.marketing.promotion.Description.ADMIN_DESC));
System.out.println("Shopper short description: " + promotion.getDescription(commandContext.getLocale(), com.ibm.commerce.marketing.promotion.Description.SHOPPER_SHORT_DESC));
System.out.println("Shopper long description: " + promotion.getDescription(commandContext.getLocale(), com.ibm.commerce.marketing.promotion.Description.SHOPPER_LONG_DESC));
}
Hope this help someone. If you find any issue in above code or know better alternatives to this code, do share with us through the comment section. Feel free to share this page with your friends and colleagues.
Thanks!
Comments
Post a Comment