How to set fix toAdress in Hybris for all email?

If you want to send all emails to some fix toAddress, in that case, you need to override email and displayName in respective *EmailContext of renderer template.
Let's just assume you want to override toAddress in customer registration flow. So here you need to find context class name form Impex. Below are the renderer template for customer registration subject & body and CustomerEmailContext is the class name which will feed all data to this renderer.
# Email velocity templates     
INSERT_UPDATE RendererTemplate ; code[unique=true]                                         ; contextClass                                                                                ; rendererType(code)[default='velocity']
                               ; powertools_Email_Customer_Registration_Body               ; $emailPackageName.CustomerEmailContext                                                      
                               ; powertools_Email_Customer_Registration_Subject            ; $emailPackageName.CustomerEmailContext  

Now open the CustomerEmailContext.java and change init method
@Override
public void init(final StoreFrontCustomerProcessModel storeFrontCustomerProcessModel, final EmailPageModel emailPageModel)
{
    super.init(storeFrontCustomerProcessModel, emailPageModel);
    String REGISTRATION_EMAIL = Config.getString("fix.registration.email.toaddress", "defaultvalue@gmail.com");
    String REGISTRATION_DISPLAYNAME = Config.getString("fix.registration.email.toaddress.displayName", "New Accounts Team");

    put(DISPLAY_NAME, REGISTRATION_DISPLAYNAME);
    put(EMAIL, REGISTRATION_EMAIL);
    customerData = getCustomerConverter().convert(getCustomer(storeFrontCustomerProcessModel));
}

Author Image

Ankitkumar Patel

Sr. SAP Hybris consultant, having 15+ years experience in SAP Commerce Cloud (Hybris), SAP Spartacus. Extensive experience in SAP Hybris development, third-party integrations, project architecture and design... Read more

Comments

  1. Thank u so much , such a great elaboration

    ReplyDelete
  2. Am getting the below exception while doing that

    Mar 21, 2018 5:16:17 PM org.apache.catalina.core.StandardWrapperValve invoke
    SEVERE: Servlet.service() for servlet [DispatcherServlet] in context with path [/leaseplanstorefront] threw exception [Request processing failed; nested exception is de.hybris.platform.servicelayer.exceptions.ModelSavingException: [de.hybris.platform.servicelayer.interceptor.impl.MandatoryAttributesValidator@5bdff98c]:missing values for [body] in model ReplyEmailNotificationProcessModel () to create a new ReplyEmailNotificationProcess] with root cause
    de.hybris.platform.servicelayer.interceptor.InterceptorException: [de.hybris.platform.servicelayer.interceptor.impl.MandatoryAttributesValidator@5bdff98c]:missing values for [body] in model ReplyEmailNotificationProcessModel () to create a new ReplyEmailNotificationProcess
    at de.hybris.platform.servicelayer.interceptor.impl.MandatoryAttributesValidator.onValidate(MandatoryAttributesValidator.java:97)
    at de.hybris.platform.servicelayer.internal.model.impl.wrapper.ModelWrapper.invokeValidateInterceptors(ModelWrapper.java:290)
    at de.hybris.platform.servicelayer.internal.model.impl.wrapper.ModelWrapper.validate(ModelWrapper.java:238)
    at de.hybris.platform.servicelayer.internal.model.extractor.impl.DefaultModelExtractor.process(DefaultModelExtractor.java:57)
    at de.hybris.platform.servicelayer.internal.model.impl.DefaultModelService.performPersistenceOperations(DefaultModelService.java:719)
    at de.hybris.platform.servicelayer.internal.model.impl.DefaultModelService.saveAllInternal(DefaultModelService.java:714)
    at de.hybris.platform.servicelayer.internal.model.impl.DefaultModelService.saveAll(DefaultModelService.java:694)
    at de.hybris.platform.servicelayer.internal.model.impl.DefaultModelService.save(DefaultModelService.java:642)
    at de.hybris.platform.processengine.impl.DefaultBusinessProcessService.createProcess(DefaultBusinessProcessService.java:81)
    at de.hybris.platform.processengine.impl.DefaultBusinessProcessService.createProcess(DefaultBusinessProcessService.java:67)
    at

    ReplyDelete
    Replies
    1. Look like, you have not set things correctly, Make sure you have created you Business Process Model with all mandatory values. Better you ask question with all detail in stack overflow, I will try to answer it.

      Root-cause:
      -------------------
      missing values for [body] in model ReplyEmailNotificationProcessModel () to create a new ReplyEmailNotificationProcess

      Delete

Post a Comment

Popular posts from this blog

Hybris flexible search query examples

How to remove or update all data records in Hybris?

How to Install temporary Hybris license?