Creating Gift Cards with INR value using Groovy script in SAP Hybris
In this article, we are going to explore how to create a number of Gift Cards with INR [₹] value using Groovy script in Hybris.
Groovy script to create a Gift Cards with INR [₹] value:
import com.core.model.GiftCardModel;
import com.core.service.giftcard.GiftCardService;
import com.core.enums.GiftCardType;
import com.core.enums.GiftCardSourceSystem;
// Initiate necessary services
gittCardService = spring.getBean("giftCardService");
userService = spring.getBean("userService");
modelService = spring.getBean("modelService");
int gift_card_count = 10; // Here, pass any number to generate 'n' number of gift cards
double gift_card_amount = 100.0; // INR value of the gift card
var customer_email = 'dummy@gmail.com'; // provided dummy email id and later on we can share this generated gift card with original customer
for (int i = 1; i <= gift_card_count; i++) {
GiftCardModel giftCardModel = giftCardService.giftCardGenerator(gift_card_amount, customer_email, GiftCardType.GIFTCARD", GiftCardSourceSystem.SCRIPT);
giftCardModel.setCreatedBy(userService.getCurrentUser());
giftCardModel.setCreationReason("Gift Card created for new campaign");
// Save the gift card
modelService.save(giftCardModel);
println giftCardModel.getCode() + ' ' + giftCardModel.getBalanceAmount() + ' ' + giftCardModel.getCustomerEmailID();
}
println 'No. of Gift Cards created - ' + gift_card_count;
printly 'Script executed successfully!!!'
Outcome:
Gift card code Amount Customer Email ID
xxxxxxxxxxxxxxx1, 100.0, dummy@gmail.com
xxxxxxxxxxxxxxx2, 100.0, dummy@gmail.com
xxxxxxxxxxxxxxx3, 100.0, dummy@gmail.com
xxxxxxxxxxxxxxx4, 100.0, dummy@gmail.com
xxxxxxxxxxxxxxx5, 100.0, dummy@gmail.com
xxxxxxxxxxxxxxx6, 100.0, dummy@gmail.com
xxxxxxxxxxxxxxx7, 100.0, dummy@gmail.com
xxxxxxxxxxxxxxx8, 100.0, dummy@gmail.com
xxxxxxxxxxxxxxx9, 100.0, dummy@gmail.com
xxxxxxxxxxxxxx10, 100.0, dummy@gmail.com
Please feel free to add your comments if you are having any queries.
Comments
Post a Comment