Okay I have it working now but found few discrepancies in the guide. Here is my understanding of the process:
Modify applicationContext-email.xml to have to following, exactly as broadleaf guide states:
1) define mail server (blMailSender)
2) define template resolver (blEmailTemplateResolver)
3) define template engine (blEmailTemplateEngine)
4) define message creator (blMessageCreator)
5) define common email attributes (blEmailInfo)
6) define confirmation email template (orderConfirmationEmailInfo)
Now that mail server, template resolver, template engine and template is all set up and defined, we need to add code to bring it all together and use it to send out order confirmation email each time order completes.
There are two ways sending confirmation email can be achieved:1) In OrderConfirmationController call method "sendConfirmationEmail(orderNumber)". Code is already present in controller so you don't need to add anything else. You are all set up to send out confirmation emails if you run the app now!!
Code: Select all
public String displayOrderConfirmationByOrderNumber(@PathVariable("orderNumber") String orderNumber, Model model, HttpServletRequest request, HttpServletResponse response)
{
sendConfirmationEmail(orderNumber);
return super.displayOrderConfirmationByOrderNumber(orderNumber, model, request, response);
}
2) Second way to achieve this is via adding last step to Checkout Workflow. The steps are listed in the guide under "Broadleaf Concepts --> Additional Configuration -->Email". Here is the repetition:
a) In applicationContext.xml, override blCheckoutWorkflow bean definition and add your custom activity as the last activity of the workflow
Code: Select all
<bean id="blCheckoutWorkflow" class="org.broadleafcommerce.core.workflow.SequenceProcessor">
<property name="processContextFactory">
<bean class="org.broadleafcommerce.core.checkout.service.workflow.CheckoutProcessContextFactory"/>
</property>
<property name="activities">
<list>
<bean class="org.broadleafcommerce.core.offer.service.workflow.VerifyCustomerMaxOfferUsesActivity"/>
<bean class="org.broadleafcommerce.core.checkout.service.workflow.PaymentServiceActivity"/>
<bean class="org.broadleafcommerce.core.offer.service.workflow.RecordOfferUsageActivity"/>
<bean class="com.em.core.checkout.service.workflow.YOURCUSTOMCompleteOrderActivity"/>
</list>
</property>
<property name="defaultErrorHandler" ref="blDefaultErrorHandler"/>
</bean>
b) Create/code that custom activity by extending CompleteOrderActivity
Code: Select all
public class YOURCUSTOMCompleteOrderActivity extends CompleteOrderActivity {..}
c) Create custom email service by implementation as stated in the guide
d) As a last step, make sure you have this package (where you have put custom email service) set for component scan in applicationContext.xml, else your bean won't be found and deployed by application server
Code: Select all
<context:component-scan base-package="com.mycomp.core.email.service"/>
Key point to note is that OrderConfirmationController way is already implemented so there is nothing we need to do if this approach is acceptable. It's only if we want to go the WORKFLOW way, we should follow all the steps to create and add that last custom activity to the checkout workflow.
So don't forget to comment out "sendConfirmationEmail(orderNumber);" line from OrderConfirmationController before going the WORKFLOW way, else you will end up receiving two confirmation emails for each successful order, like I did!
My question to broadleaf team would be, what is the recommended approach, the workflow way or adding a method in controller way? Expert opinion is always a privilege, and broadleaf team being best in what they do, I would love to hear their opinion!
Anyways, hope this helps someone struggling!