gpt4 book ai didi

cron - SAP Hybris 电子商务 : Send Email in CronJob

转载 作者:行者123 更新时间:2023-12-01 16:02:00 33 4
gpt4 key购买 nike

我创建了一个完美运行的 CronJob。但我想在这个 Cronjob 中生成电子邮件的发送。我关注了tutorial在互联网上。我从创建 ProductsApprovedEmailProcess 的 itemType 开始。

然后我创建了productsApprovedEmailProcess来定义流程引擎执行的步骤,如下

然后我添加了一个 EmailContext 来保存要传递到电子邮件模板的数据,如下所示

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;
}
}

我已经将ProductsApprovedEmailContext注册为Spring中的bean,如下

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

然后我创建了 2 个 Velocity 模板,一个用于电子邮件主题,另一个用于正文 email-productsapproved-subject.vmemail-productsapproved-body.vm

下面的 impex 允许您为主题和正文创建 RendererTemplates,并将它们附加到 EmailPageTemplate,如下所示

$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 ;

Cronjob中我添加了这段代码!

    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);

但是当我使用 HMC 接口(interface)执行 CronJob 时出现此错误:

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

更新:

这是我的业务流程:

<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>

声明 ProductApprovedEmailTemplate (EmailPageTemplate) 后,我收到此警告,但未生成邮件:

WARN  [TaskExecutor-master-264-ProcessTask [8796715713462]] [GenerateEmailAction] Could not retrieve email page model for ProductApprovedEmail and Electronics Content Catalog:Online, cannot generate email content

最佳答案

看起来,您关注的博客,它正确地提到了每个步骤,但您可能会错过一些东西。

确保您已正确执行以下步骤。

例如

frontendTemplateName 应与 EmailPageTemplate 匹配

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

创建电子邮件页面模板

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

创建电子邮件页面

   INSERT_UPDATE EmailPage  ;$contentCV[unique=true];uid[unique=true]   ;masterTemplate(uid,$contentCV);approvalStatus(code)[default='approved']
; ;ProductApprovedEmail ;ProductApprovedEmailTemplate ;

关于cron - SAP Hybris 电子商务 : Send Email in CronJob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49455900/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com