Search in sources :

Example 6 with Email

use of com.salesmanager.core.business.modules.email.Email in project shopizer by shopizer-ecommerce.

the class SendEmailTest method sendEmail.

@Test
public void sendEmail() throws ServiceException, Exception {
    MerchantStore merchant = merchantService.getByCode(MerchantStore.DEFAULT_STORE);
    Map<String, String> templateTokens = new HashMap<String, String>();
    templateTokens.put("EMAIL_ADMIN_LABEL", "");
    templateTokens.put("EMAIL_STORE_NAME", "");
    templateTokens.put("EMAIL_FOOTER_COPYRIGHT", "");
    templateTokens.put("EMAIL_DISCLAIMER", "");
    templateTokens.put("EMAIL_SPAM_DISCLAIMER", "");
    templateTokens.put("LOGOPATH", "");
    templateTokens.put("EMAIL_CONTACT_NAME", "Test");
    templateTokens.put("EMAIL_CONTACT_EMAIL", "test@gmail.com");
    templateTokens.put("EMAIL_CONTACT_CONTENT", "Hello");
    templateTokens.put("EMAIL_CUSTOMER_CONTACT", "Contact");
    templateTokens.put("EMAIL_CONTACT_NAME_LABEL", "Name");
    templateTokens.put("EMAIL_CONTACT_EMAIL_LABEL", "Email");
    Email email = new Email();
    email.setFrom("Default store");
    email.setFromEmail("test@shopizer.com");
    email.setSubject("Contact");
    email.setTo("test@shopizer.com");
    email.setTemplateName("email_template_contact.ftl");
    email.setTemplateTokens(templateTokens);
    emailService.sendHtmlEmail(merchant, email);
}
Also used : Email(com.salesmanager.core.business.modules.email.Email) HashMap(java.util.HashMap) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ConfigurationTest(com.salesmanager.test.configuration.ConfigurationTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with Email

use of com.salesmanager.core.business.modules.email.Email in project shopizer by shopizer-ecommerce.

the class EmailTemplatesUtils method changePasswordNotificationEmail.

/**
 * Sends a change password notification email to the Customer
 * @param customer
 * @param merchantStore
 * @param customerLocale
 * @param contextPath
 */
@Async
public void changePasswordNotificationEmail(Customer customer, MerchantStore merchantStore, Locale customerLocale, String contextPath) {
    LOGGER.debug("Sending change password email");
    try {
        Map<String, String> templateTokens = emailUtils.createEmailObjectsMap(contextPath, merchantStore, messages, customerLocale);
        templateTokens.put(EmailConstants.LABEL_HI, messages.getMessage("label.generic.hi", customerLocale));
        templateTokens.put(EmailConstants.EMAIL_CUSTOMER_FIRSTNAME, customer.getBilling().getFirstName());
        templateTokens.put(EmailConstants.EMAIL_CUSTOMER_LASTNAME, customer.getBilling().getLastName());
        String[] date = { DateUtil.formatLongDate(new Date()) };
        templateTokens.put(EmailConstants.EMAIL_NOTIFICATION_MESSAGE, messages.getMessage("label.notification.message.passwordchanged", date, customerLocale));
        Email email = new Email();
        email.setFrom(merchantStore.getStorename());
        email.setFromEmail(merchantStore.getStoreEmailAddress());
        email.setSubject(messages.getMessage("label.notification.title.passwordchanged", customerLocale));
        email.setTo(customer.getEmailAddress());
        email.setTemplateName(EmailConstants.EMAIL_NOTIFICATION_TMPL);
        email.setTemplateTokens(templateTokens);
        emailService.sendHtmlEmail(merchantStore, email);
    } catch (Exception e) {
        LOGGER.error("Error occured while sending change password email ", e);
    }
}
Also used : Email(com.salesmanager.core.business.modules.email.Email) Date(java.util.Date) Async(org.springframework.scheduling.annotation.Async)

Example 8 with Email

use of com.salesmanager.core.business.modules.email.Email in project shopizer by shopizer-ecommerce.

the class EmailTemplatesUtils method sendUpdateOrderStatusEmail.

/**
 * Send an email to the customer with last order status
 * @param request
 * @param customer
 * @param order
 * @param merchantStore
 * @param customerLocale
 */
@Async
public void sendUpdateOrderStatusEmail(Customer customer, Order order, OrderStatusHistory lastHistory, MerchantStore merchantStore, Locale customerLocale, String contextPath) {
    /**
     * issue with putting that elsewhere *
     */
    LOGGER.info("Sending order status email to customer");
    try {
        Map<String, String> templateTokens = emailUtils.createEmailObjectsMap(contextPath, merchantStore, messages, customerLocale);
        templateTokens.put(EmailConstants.LABEL_HI, messages.getMessage("label.generic.hi", customerLocale));
        templateTokens.put(EmailConstants.EMAIL_CUSTOMER_FIRSTNAME, customer.getBilling().getFirstName());
        templateTokens.put(EmailConstants.EMAIL_CUSTOMER_LASTNAME, customer.getBilling().getLastName());
        String[] statusMessageText = { String.valueOf(order.getId()), DateUtil.formatDate(order.getDatePurchased()) };
        String status = messages.getMessage("label.order." + order.getStatus().name(), customerLocale, order.getStatus().name());
        String[] statusMessage = { DateUtil.formatDate(lastHistory.getDateAdded()), status };
        String comments = lastHistory.getComments();
        if (StringUtils.isBlank(comments)) {
            comments = messages.getMessage("label.order." + order.getStatus().name(), customerLocale, order.getStatus().name());
        }
        templateTokens.put(EmailConstants.EMAIL_ORDER_STATUS_TEXT, messages.getMessage("email.order.statustext", statusMessageText, customerLocale));
        templateTokens.put(EmailConstants.EMAIL_ORDER_STATUS, messages.getMessage("email.order.status", statusMessage, customerLocale));
        templateTokens.put(EmailConstants.EMAIL_TEXT_STATUS_COMMENTS, comments);
        Email email = new Email();
        email.setFrom(merchantStore.getStorename());
        email.setFromEmail(merchantStore.getStoreEmailAddress());
        email.setSubject(messages.getMessage("email.order.status.title", new String[] { String.valueOf(order.getId()) }, customerLocale));
        email.setTo(customer.getEmailAddress());
        email.setTemplateName(EmailConstants.ORDER_STATUS_TMPL);
        email.setTemplateTokens(templateTokens);
        emailService.sendHtmlEmail(merchantStore, email);
    } catch (Exception e) {
        LOGGER.error("Error occured while sending order download email ", e);
    }
}
Also used : Email(com.salesmanager.core.business.modules.email.Email) Async(org.springframework.scheduling.annotation.Async)

Example 9 with Email

use of com.salesmanager.core.business.modules.email.Email in project shopizer by shopizer-ecommerce.

the class EmailTemplatesUtils method sendOrderDownloadEmail.

/**
 * Send download email instructions to customer
 * @param customer
 * @param order
 * @param merchantStore
 * @param customerLocale
 * @param contextPath
 */
@Async
public void sendOrderDownloadEmail(Customer customer, Order order, MerchantStore merchantStore, Locale customerLocale, String contextPath) {
    /**
     * issue with putting that elsewhere *
     */
    LOGGER.info("Sending download email to customer");
    try {
        Map<String, String> templateTokens = emailUtils.createEmailObjectsMap(contextPath, merchantStore, messages, customerLocale);
        templateTokens.put(EmailConstants.LABEL_HI, messages.getMessage("label.generic.hi", customerLocale));
        templateTokens.put(EmailConstants.EMAIL_CUSTOMER_FIRSTNAME, customer.getBilling().getFirstName());
        templateTokens.put(EmailConstants.EMAIL_CUSTOMER_LASTNAME, customer.getBilling().getLastName());
        String[] downloadMessage = { String.valueOf(ApplicationConstants.MAX_DOWNLOAD_DAYS), String.valueOf(order.getId()), filePathUtils.buildCustomerUri(merchantStore, contextPath), merchantStore.getStoreEmailAddress() };
        templateTokens.put(EmailConstants.EMAIL_ORDER_DOWNLOAD, messages.getMessage("email.order.download.text", downloadMessage, customerLocale));
        templateTokens.put(EmailConstants.CUSTOMER_ACCESS_LABEL, messages.getMessage("label.customer.accessportal", customerLocale));
        templateTokens.put(EmailConstants.ACCESS_NOW_LABEL, messages.getMessage("label.customer.accessnow", customerLocale));
        // shop url
        String customerUrl = filePathUtils.buildStoreUri(merchantStore, contextPath);
        templateTokens.put(EmailConstants.CUSTOMER_ACCESS_URL, customerUrl);
        String[] orderInfo = { String.valueOf(order.getId()) };
        Email email = new Email();
        email.setFrom(merchantStore.getStorename());
        email.setFromEmail(merchantStore.getStoreEmailAddress());
        email.setSubject(messages.getMessage("email.order.download.title", orderInfo, customerLocale));
        email.setTo(customer.getEmailAddress());
        email.setTemplateName(EmailConstants.EMAIL_ORDER_DOWNLOAD_TPL);
        email.setTemplateTokens(templateTokens);
        LOGGER.debug("Sending email to {} with download info", customer.getEmailAddress());
        emailService.sendHtmlEmail(merchantStore, email);
    } catch (Exception e) {
        LOGGER.error("Error occured while sending order download email ", e);
    }
}
Also used : Email(com.salesmanager.core.business.modules.email.Email) Async(org.springframework.scheduling.annotation.Async)

Example 10 with Email

use of com.salesmanager.core.business.modules.email.Email in project shopizer by shopizer-ecommerce.

the class EmailTemplatesUtils method sendOrderEmail.

/**
 * Sends an email to the customer after a completed order
 * @param customer
 * @param order
 * @param customerLocale
 * @param language
 * @param merchantStore
 * @param contextPath
 */
@Async
public void sendOrderEmail(String toEmail, Customer customer, Order order, Locale customerLocale, Language language, MerchantStore merchantStore, String contextPath) {
    /**
     * issue with putting that elsewhere *
     */
    LOGGER.info("Sending welcome email to customer");
    try {
        Map<String, Zone> zones = zoneService.getZones(language);
        Map<String, Country> countries = countryService.getCountriesMap(language);
        // format Billing address
        StringBuilder billing = new StringBuilder();
        if (StringUtils.isBlank(order.getBilling().getCompany())) {
            billing.append(order.getBilling().getFirstName()).append(" ").append(order.getBilling().getLastName()).append(LINE_BREAK);
        } else {
            billing.append(order.getBilling().getCompany()).append(LINE_BREAK);
        }
        billing.append(order.getBilling().getAddress()).append(LINE_BREAK);
        billing.append(order.getBilling().getCity()).append(", ");
        if (order.getBilling().getZone() != null) {
            Zone zone = zones.get(order.getBilling().getZone().getCode());
            if (zone != null) {
                billing.append(zone.getName());
            }
            billing.append(LINE_BREAK);
        } else if (!StringUtils.isBlank(order.getBilling().getState())) {
            billing.append(order.getBilling().getState()).append(LINE_BREAK);
        }
        Country country = countries.get(order.getBilling().getCountry().getIsoCode());
        if (country != null) {
            billing.append(country.getName()).append(" ");
        }
        billing.append(order.getBilling().getPostalCode());
        // format shipping address
        StringBuilder shipping = null;
        if (order.getDelivery() != null && !StringUtils.isBlank(order.getDelivery().getFirstName())) {
            shipping = new StringBuilder();
            if (StringUtils.isBlank(order.getDelivery().getCompany())) {
                shipping.append(order.getDelivery().getFirstName()).append(" ").append(order.getDelivery().getLastName()).append(LINE_BREAK);
            } else {
                shipping.append(order.getDelivery().getCompany()).append(LINE_BREAK);
            }
            shipping.append(order.getDelivery().getAddress()).append(LINE_BREAK);
            shipping.append(order.getDelivery().getCity()).append(", ");
            if (order.getDelivery().getZone() != null) {
                Zone zone = zones.get(order.getDelivery().getZone().getCode());
                if (zone != null) {
                    shipping.append(zone.getName());
                }
                shipping.append(LINE_BREAK);
            } else if (!StringUtils.isBlank(order.getDelivery().getState())) {
                shipping.append(order.getDelivery().getState()).append(LINE_BREAK);
            }
            Country deliveryCountry = countries.get(order.getDelivery().getCountry().getIsoCode());
            if (country != null) {
                shipping.append(deliveryCountry.getName()).append(" ");
            }
            shipping.append(order.getDelivery().getPostalCode());
        }
        if (shipping == null && StringUtils.isNotBlank(order.getShippingModuleCode())) {
            // TODO IF HAS NO SHIPPING
            shipping = billing;
        }
        // format order
        // String storeUri = FilePathUtils.buildStoreUri(merchantStore, contextPath);
        StringBuilder orderTable = new StringBuilder();
        orderTable.append(TABLE);
        for (OrderProduct product : order.getOrderProducts()) {
            // Product productModel = productService.getByCode(product.getSku(), language);
            orderTable.append(TR);
            orderTable.append(TD).append(product.getProductName()).append(" - ").append(product.getSku()).append(CLOSING_TD);
            orderTable.append(TD).append(messages.getMessage("label.quantity", customerLocale)).append(": ").append(product.getProductQuantity()).append(CLOSING_TD);
            orderTable.append(TD).append(pricingService.getDisplayAmount(product.getOneTimeCharge(), merchantStore)).append(CLOSING_TD);
            orderTable.append(CLOSING_TR);
        }
        // order totals
        for (OrderTotal total : order.getOrderTotal()) {
            orderTable.append(TR_BORDER);
            // orderTable.append(TD);
            // orderTable.append(CLOSING_TD);
            orderTable.append(TD);
            orderTable.append(CLOSING_TD);
            orderTable.append(TD);
            orderTable.append("<strong>");
            if (total.getModule().equals("tax")) {
                orderTable.append(total.getText()).append(": ");
            } else {
                // if(total.getModule().equals("total") || total.getModule().equals("subtotal")) {
                // }
                orderTable.append(messages.getMessage(total.getOrderTotalCode(), customerLocale)).append(": ");
            // if(total.getModule().equals("total") || total.getModule().equals("subtotal")) {
            // }
            }
            orderTable.append("</strong>");
            orderTable.append(CLOSING_TD);
            orderTable.append(TD);
            orderTable.append("<strong>");
            orderTable.append(pricingService.getDisplayAmount(total.getValue(), merchantStore));
            orderTable.append("</strong>");
            orderTable.append(CLOSING_TD);
            orderTable.append(CLOSING_TR);
        }
        orderTable.append(CLOSING_TABLE);
        Map<String, String> templateTokens = emailUtils.createEmailObjectsMap(contextPath, merchantStore, messages, customerLocale);
        templateTokens.put(EmailConstants.LABEL_HI, messages.getMessage("label.generic.hi", customerLocale));
        templateTokens.put(EmailConstants.EMAIL_CUSTOMER_FIRSTNAME, order.getBilling().getFirstName());
        templateTokens.put(EmailConstants.EMAIL_CUSTOMER_LASTNAME, order.getBilling().getLastName());
        String[] params = { String.valueOf(order.getId()) };
        String[] dt = { DateUtil.formatDate(order.getDatePurchased()) };
        templateTokens.put(EmailConstants.EMAIL_ORDER_NUMBER, messages.getMessage("email.order.confirmation", params, customerLocale));
        templateTokens.put(EmailConstants.EMAIL_ORDER_DATE, messages.getMessage("email.order.ordered", dt, customerLocale));
        templateTokens.put(EmailConstants.EMAIL_ORDER_THANKS, messages.getMessage("email.order.thanks", customerLocale));
        templateTokens.put(EmailConstants.ADDRESS_BILLING, billing.toString());
        templateTokens.put(EmailConstants.ORDER_PRODUCTS_DETAILS, orderTable.toString());
        templateTokens.put(EmailConstants.EMAIL_ORDER_DETAILS_TITLE, messages.getMessage("label.order.details", customerLocale));
        templateTokens.put(EmailConstants.ADDRESS_BILLING_TITLE, messages.getMessage("label.customer.billinginformation", customerLocale));
        templateTokens.put(EmailConstants.PAYMENT_METHOD_TITLE, messages.getMessage("label.order.paymentmode", customerLocale));
        templateTokens.put(EmailConstants.PAYMENT_METHOD_DETAILS, messages.getMessage(new StringBuilder().append("payment.type.").append(order.getPaymentType().name()).toString(), customerLocale, order.getPaymentType().name()));
        if (StringUtils.isNotBlank(order.getShippingModuleCode())) {
            // templateTokens.put(EmailConstants.SHIPPING_METHOD_DETAILS, messages.getMessage(new StringBuilder().append("module.shipping.").append(order.getShippingModuleCode()).toString(),customerLocale,order.getShippingModuleCode()));
            templateTokens.put(EmailConstants.SHIPPING_METHOD_DETAILS, messages.getMessage(new StringBuilder().append("module.shipping.").append(order.getShippingModuleCode()).toString(), new String[] { merchantStore.getStorename() }, customerLocale));
            templateTokens.put(EmailConstants.ADDRESS_SHIPPING_TITLE, messages.getMessage("label.order.shippingmethod", customerLocale));
            templateTokens.put(EmailConstants.ADDRESS_DELIVERY_TITLE, messages.getMessage("label.customer.shippinginformation", customerLocale));
            templateTokens.put(EmailConstants.SHIPPING_METHOD_TITLE, messages.getMessage("label.customer.shippinginformation", customerLocale));
            templateTokens.put(EmailConstants.ADDRESS_DELIVERY, shipping.toString());
        } else {
            templateTokens.put(EmailConstants.SHIPPING_METHOD_DETAILS, "");
            templateTokens.put(EmailConstants.ADDRESS_SHIPPING_TITLE, "");
            templateTokens.put(EmailConstants.ADDRESS_DELIVERY_TITLE, "");
            templateTokens.put(EmailConstants.SHIPPING_METHOD_TITLE, "");
            templateTokens.put(EmailConstants.ADDRESS_DELIVERY, "");
        }
        String status = messages.getMessage("label.order." + order.getStatus().name(), customerLocale, order.getStatus().name());
        String[] statusMessage = { DateUtil.formatDate(order.getDatePurchased()), status };
        templateTokens.put(EmailConstants.ORDER_STATUS, messages.getMessage("email.order.status", statusMessage, customerLocale));
        String[] title = { merchantStore.getStorename(), String.valueOf(order.getId()) };
        Email email = new Email();
        email.setFrom(merchantStore.getStorename());
        email.setFromEmail(merchantStore.getStoreEmailAddress());
        email.setSubject(messages.getMessage("email.order.title", title, customerLocale));
        email.setTo(toEmail);
        email.setTemplateName(EmailConstants.EMAIL_ORDER_TPL);
        email.setTemplateTokens(templateTokens);
        LOGGER.debug("Sending email to {} for order id {} ", customer.getEmailAddress(), order.getId());
        emailService.sendHtmlEmail(merchantStore, email);
    } catch (Exception e) {
        LOGGER.error("Error occured while sending order confirmation email ", e);
    }
}
Also used : Email(com.salesmanager.core.business.modules.email.Email) OrderProduct(com.salesmanager.core.model.order.orderproduct.OrderProduct) Zone(com.salesmanager.core.model.reference.zone.Zone) Country(com.salesmanager.core.model.reference.country.Country) OrderTotal(com.salesmanager.core.model.order.OrderTotal) Async(org.springframework.scheduling.annotation.Async)

Aggregations

Email (com.salesmanager.core.business.modules.email.Email)10 Async (org.springframework.scheduling.annotation.Async)8 ServiceException (com.salesmanager.core.business.exception.ServiceException)3 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)3 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)3 ConversionException (com.salesmanager.core.business.exception.ConversionException)2 ConversionRuntimeException (com.salesmanager.shop.store.api.exception.ConversionRuntimeException)2 GenericRuntimeException (com.salesmanager.shop.store.api.exception.GenericRuntimeException)2 UnauthorizedException (com.salesmanager.shop.store.api.exception.UnauthorizedException)2 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)1 OrderTotal (com.salesmanager.core.model.order.OrderTotal)1 OrderProduct (com.salesmanager.core.model.order.orderproduct.OrderProduct)1 Country (com.salesmanager.core.model.reference.country.Country)1 Zone (com.salesmanager.core.model.reference.zone.Zone)1 UserAlreadyExistException (com.salesmanager.shop.model.customer.UserAlreadyExistException)1 OperationNotAllowedException (com.salesmanager.shop.store.api.exception.OperationNotAllowedException)1 ConfigurationTest (com.salesmanager.test.configuration.ConfigurationTest)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1