Professional Documents
Culture Documents
Email Task Documentation
Email Task Documentation
1. Overview
In this documentation, I have created, configured and sent email in SAP Hybris at the
checkout. This email consists of all the cart items available in the customer cart.
The Email is triggered at the checkout on the click of the checkout button the event is
published, and the listener is invoked where the business process is created and once the
required details are saved under the process model the process is started.
The event and listener are created by extending required classes/interfaces separately.
The below process consists of all the required classes and xml files to send the email at the
checkout.
2. Implementation
2.1 Business Process
I. I have created Item type CheckoutEmailProcessModel which is extending
StoreFrontCustomerProcess.
<bean id="checkoutEmailProcessDefinitionResource"
class="de.hybris.platform.processengine.definition.ProcessDefinitionResource" >
<property name="resource"
value="classpath:/yacceleratorcore/processes/checkoutEmailProcess.xml"/>
</bean>
V. Created a new Java class that extends AbstractEmailContext, named
it CheckoutEmailContext.
An EmailContext is the one that holds the data to be passed to the email template, in my
case I have passed CartModel to the template.
@Override
public void init(final CheckoutEmailProcessModel checkoutEmailProcessModel, final
EmailPageModel emailPageModel)
{
super.init(checkoutEmailProcessModel, emailPageModel);
if (checkoutEmailProcessModel instanceof CheckoutEmailProcessModel)
{
setCartData(((CheckoutEmailProcessModel)
checkoutEmailProcessModel).getCartData());
}
}
<html>
<head>
<title> Email of the Checkout</title>
</head>
<body>
<center>
<h3>Cart ID :${ctx.cartData.code}</h3>
<table>
<tr>
<td><strong>Product</strong></td>
<td><strong>Item #</strong></td>
<td><strong>Price</strong></td>
<td><strong>Qty</strong></td>
<td><strong>Item Total</strong></td>
</tr>
#foreach($entry in $ctx.cartData.getEntries())
<tr>
<td>$entry.product.name</td>
<td>$entry.product.code</td>
<td>$entry.basePrice.value</td>
<td>$entry.quantity</td>
<td>$entry.totalPrice.value</td>
</tr>
#end
</table>
</center>
</body>
</html>
2. The following impex is used to create RendererTemplates for the Subject and
the Body, and to attach them to an EmailPageTemplate.
$contentCatalog=powertoolsContentCatalog
$contentCV=catalogVersion(CatalogVersion.catalog(Catalog.id[default=$contentCatalog]),Cata
logVersion.version[default=Online])[default=$contentCatalog:Online]
$wideContent=CMSImageComponent,BannerComponent
$jarEmailResource=jar:de.hybris.platform.powertoolsstore.constants.PowertoolsStoreConstant
s&/powertoolsstore/import/coredata/contentCatalogs/powertoolsContentCatalog/emails
$emailResource=jar:de.hybris.platform.yacceleratorcore.setup.CoreSystemSetup&/yaccelerator
core/import/emails
$emailPackageName=de.hybris.platform.yacceleratorfacades.process.email.context
;templateScript[lang=en,translator=de.hybris.platform.commerceservices.impex.impl.F
ileLoaderValueTranslator];rendererType(code)[default='velocity']
;email-checkout-body
;$emailPackageName.CheckoutEmailContext ;$emailResource/email-checkout-body.vm
;email-checkout-subject
;$emailPackageName.CheckoutEmailContext ;$emailResource/email-checkout-subject.vm
emailservice.send.enabled = true
mail.smtp.server=smtp.mailtrap.io
mail.smtp.port=2525
mail.smtp.user=**************
mail.smtp.password=*************
mail.use.tls=true
2.4. Sending Email
Sending a Cart Details Email by starting a new instance of the Checkout Email Process in the
CheckoutEmailEventListener.
CheckoutEmailEvent