4

I have created a CronJob that works perfectly. But I want to generate the sending of an email within this Cronjob. I followed a tutorial on the internet. I start with the creation itemType of ProductsApprovedEmailProcess.

then I created productsApprovedEmailProcess to define the steps be executed by the Process Engine as follow

Then I have added an EmailContext to holds the data to be passed to the email template as follow

public class ProductsApprovedEmailContext extends CustomerEmailContext
{

private String message;

@Override
public void init(final StoreFrontCustomerProcessModel processModel, final EmailPageModel emailPageModel)
{
    super.init(processModel, emailPageModel);
    if (processModel instanceof ProductsApprovedEmailProcessModel)
    {
        setMessage(((ProductsApprovedEmailProcessModel) processModel).getMessage());
    }
}


public String getMessage()
{
    return message;
}


public void setMessage(final String message)
{
    this.message = message;
}
}

And I had register ProductsApprovedEmailContext as a bean in Spring as follow

    <bean id="productsApprovedEmailContext" class="com.hybris.training.facades.process.email.context.ProductsApprovedEmailContext"
        parent="abstractEmailContext"
        scope="prototype" >
</bean>

Then I created 2 Velocity templates, one for the email Subject and the other for the Body email-productsapproved-subject.vm and email-productsapproved-body.vm

And the following impex allows you to create RendererTemplates for the Subject and the Body, and attach them to an EmailPageTemplate as follow

$contentCatalog=electronicsContentCatalog
$contentCV=catalogVersion(CatalogVersion.catalog(Catalog.id[default=$contentCatalog]),CatalogVersion.version[default=Online])[default=$contentCatalog:Online]
UPDATE GenericItem[processor=de.hybris.platform.commerceservices.impex.impl.ConfigPropertyImportProcessor];pk[unique=true]
$emailResource=$config-emailResourceValue
$emailPackageName=$config-emailContextPackageName
$lang=en
INSERT_UPDATE RendererTemplate  ;code[unique=true]                  ;contextClass                                   ;templateScript[lang=en,translator=de.hybris.platform.commerceservices.impex.impl.FileLoaderValueTranslator];rendererType(code)[default='velocity']
                            ;email-productsapproved-body        ;$emailPackageName.ProductsApprovedEmailContext ;$emailResource/email-productsapproved-body.vm
                            ;email-productsapproved-subject     ;$emailPackageName.ProductsApprovedEmailContext ;$emailResource/email-productsapproved-subject.vm
INSERT_UPDATE EmailPage ;$contentCV[unique=true];uid[unique=true]       ;masterTemplate(uid,$contentCV) ;approvalStatus(code)[default='approved']
                    ;                       ;ProductApprovedEmail   ;ProductApprovedEmailTemplate   ;

And in the Cronjob I added this code !

    final ProductsApprovedEmailProcessModel productsApprovedEmailProcessModel = (ProductsApprovedEmailProcessModel) businessProcessService
            .createProcess("productsApprovedEmailProcess" + "-" + System.currentTimeMillis(), "productsApprovedEmailProcess");
    productsApprovedEmailProcessModel.setMessage("Products approved in csv file");
    productsApprovedEmailProcessModel.setSite(baseSiteService.getBaseSiteForUID("electronics"));
    productsApprovedEmailProcessModel.setLanguage(CommerceCommonI18NService.getCurrentLanguage());
    modelService.save(productsApprovedEmailProcessModel);
    businessProcessService.startProcess(productsApprovedEmailProcessModel);

But a acheive this error when I'm strating CronJob using HMC Interface :

 Error executing ActionNode with ID [generateProductsApprovedEmail]: HtmlTemplate associated with MasterTemplate of EmailPageModel cannot be null

UPDATE :

Here is my business process :

<process xmlns="http://www.hybris.de/xsd/processdefinition"
     start="generateProductsApprovedEmail"
     name="productsApprovedEmailProcess"
     processClass="com.hybris.training.core.model.process.ProductsApprovedEmailProcessModel"
     onError="error">


    <action id="generateProductsApprovedEmail" bean="generateProductsApprovedEmail">
        <transition name="OK" to="sendEmail"/>
        <transition name="NOK" to="error"/>
    </action>        


    <action id="sendEmail" bean="sendEmail">
        <transition name="OK" to="removeSentEmail"/>
        <transition name="NOK" to="failed"/>
    </action>

    <action id="removeSentEmail" bean="removeSentEmail">
        <transition name="OK" to="success"/>
        <transition name="NOK" to="error"/>
    </action>


    <end id="error" state="ERROR">Something went wrong.</end>
    <end id="failed" state="FAILED">Could not send products approved in csv File email.</end>
    <end id="success" state="SUCCEEDED">Sent file in email.</end>

After declaring ProductApprovedEmailTemplate (EmailPageTemplate) i got this warn and the mail is not generated :

WARN  [TaskExecutor-master-264-ProcessTask [8796715713462]] [GenerateEmailAction] Could not retrieve email page model for ProductApprovedEmail and Electronics Content Catalog:Online, cannot generate email content
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Rodik
  • 271
  • 2
  • 19

1 Answers1

6

Look like, the blog you have followed, it has mentioned each step correctly, but you might be missed something.

Make sure you have followed the below steps correctly.

e.g.

frontendTemplateName should be matched with EmailPageTemplate one

<bean id="generateProductApprovedEmail" parent="abstractGenerateEmailAction">
    <property name="frontendTemplateName" value="ProductApprovedEmail"/>
</bean>

Create Email page Template

INSERT_UPDATE EmailPageTemplate ;$contentCV[unique=true];uid[unique=true]       ;active ;frontendTemplateName   ;subject(code)                          ;htmlTemplate(code)     ;restrictedPageTypes(code)
                                ;                       ;ProductApprovedEmailTemplate   ;true   ;ProductApprovedEmail   ;email-productsapproved-subject             ;email-productsapproved-body    ;EmailPage

Create Email Page

   INSERT_UPDATE EmailPage  ;$contentCV[unique=true];uid[unique=true]   ;masterTemplate(uid,$contentCV);approvalStatus(code)[default='approved']
                            ;                       ;ProductApprovedEmail   ;ProductApprovedEmailTemplate   ;
HybrisHelp
  • 5,518
  • 2
  • 27
  • 65
  • helo,Thanks for your feedback. In the first place that was the problem but after changing my code I always get this warn WARN [TaskExecutor-master-255-ProcessTask [8796715647926]] [GenerateEmailAction] Could not retrieve email page model for ProductApprovedEmail and Electronics Content Catalog:Online, cannot generate email content – Rodik Mar 24 '18 at 12:16
  • 1
    Add business process and other remaining Impex in post – HybrisHelp Mar 24 '18 at 12:28
  • 2
    make sure you have sync your content catalog. You can cross check is your EmailPage available in the online version from `HMC` – HybrisHelp Mar 24 '18 at 12:33
  • when I search in the tab System-> Types, with the search criteria identifier EmailPage the results is EmailPage and EmailPageTemplate, extensionName acceleratorServices – Rodik Mar 24 '18 at 12:51
  • 1
    Check WCMS tab > EmailPage, contact me if you are not able to get it. – HybrisHelp Mar 25 '18 at 03:17
  • in WCMS > page I'm looking for ProductApprovedEmail and I find it duplicate in the catalog version staged and online and for both lines the colone is the default page there is no and in the properties tab title page is empty and in administration tab the fields from email from name and locked ny are empty to – Rodik Mar 25 '18 at 13:04
  • You can cross check and correct everything in HMC, identifiers are case sensitive, so make sure you have done thing correctly. This might be the case of your duplicate `ProductApprovedEmail`. – HybrisHelp Mar 26 '18 at 04:53
  • @Rodik Update your post with remaining configuration(XML, business process, Impex etc) – HybrisHelp Mar 27 '18 at 05:28