return vouchers;
}
@Override
public void sendVoucher(Integer voucherId, Map<String, String> messageMap) {
Voucher voucher = get(voucherId, Voucher.class);
if(voucher==null){
return;
}
VoucherTheme voucherTheme = voucherThemeAdminModel
.get(voucher.getVoucherThemeId(), VoucherTheme.class);
Map<String, Object> model = new HashMap<String, Object>();
String storeName = null;
String storeUrl = null;
String image = voucherTheme.getImage();
image = mediaService.getImageUrl(image);
String amount = null;
Integer orderId = voucher.getOrderId();
Order order = orderAdminModel.get(orderId, Order.class);
// If voucher belongs to an order
if(order!=null){
Integer languageId = order.getLanguageId();
amount = currencyService.format(voucher.getAmount(), order.getCurrencyCode(),
order.getCurrencyValue(), languageId);
storeName = order.getStoreName();
storeUrl = order.getStoreUrl();
}else{
//get default language and currency code TODO: these data should be kept in customer table?
Integer languageId = getSettingService().getConfig(SettingKey.LANGUAGE_ID, Integer.class);
String currencyCode = getSettingService().getConfig(SettingKey.CFG_CURRENCY);
amount = currencyService.format(voucher.getAmount(), currencyCode, null, languageId);
storeName = getSettingService().getConfig(SettingKey.CFG_NAME);
storeUrl = getEnvironment().getProperty("app.http");
}
model.put("fromName", voucher.getFromName());
model.put("amount", amount);
model.put("image", image);
model.put("code", voucher.getCode());
model.put("storeName", storeName);
model.put("storeUrl", storeUrl);
EmailMessage email = new EmailMessage();
email.setTo(voucher.getToEmail());
email.setFrom(getSettingService().getConfig(SettingKey.CFG_EMAIL));
email.setSenderName(storeName);
String subject = MessageFormat.format(messageMap.get("text.subject"), voucher.getFromName());
email.setSubject(subject);
String text = templateService.renderTemplate("/admin/email/voucher", model);
email.setBodyHtml(text);
emailService.send(email);