Stepan Tuhacek
Stepan Tuhacek

Reputation: 218

Hybris custom email setting custom attributes

I'm creating a custom email, which should be sent to the customer after filling the form for making an appointment. I needed additional attributes, so I've extended AbstractEmailContext:

public class AppointmentEmailContext extends AbstractEmailContext
{
   private String myAttribute;
   ...
}

I'm setting the attributes in my EventListener before I'm starting the process:

final AppointmentProcessModel storeFrontCustomerProcessModel = (AppointmentProcessModel) getBusinessProcessService()
                .createProcess(
                        "appointmentEmailProcess-" + event.getEmail() + "-" + System.currentTimeMillis(),
                        "appointmentEmailProcess");

storeFrontCustomerProcessModel.setMyAttribute("test@test.com");
getModelService().save(storeFrontCustomerProcessModel);
getBusinessProcessService().startProcess(storeFrontCustomerProcessModel);

In the init method of the AppointmentEmailContext I can't get those parameters so I could set them properly and pass them to the email template. The other thing is, the entering ProcessModel in init method isn't instance of AppointmentProcessModel, but it's the instance of StoreFrontCustomerProcessModel, even though my AppointmentProcessModel is extending it.

I also tried to add AppointmentProcessModel like this:

public class AppointmentEmailContext extends AbstractEmailContext<AppointmentProcessModel>
{
...
}

and adjust init method with correct parameters (+ add overriding methods), but then I got error while creating the process:

ERROR [hybrisHTTP21] [HybrisApplicationEventMulticaster] java.lang.InstantiationException: mypackage.core.appointment.model.AppointmentProcessModel
 java.lang.RuntimeException: java.lang.InstantiationException: mypackage.core.appointment.model.AppointmentProcessModel

I don't know if there is a problem with persisting those attributes, or if I should pass those attributes some other way.

UPDATE: I tried to add the AppointmentProcess to the *-items.xml file and I did the system update, but no changes. I checked in the backoffice that the type is added and it is extending from StoreFrontCustomerProcess. The definition is as follows:

        <itemtype code="AppointmentProcess" extends="StoreFrontCustomerProcess"
                  autocreate="true" generate="true"
                  jaloclass="mypackage.jalo.AppointmentProcess">
            <attributes>
                <attribute qualifier="email" type="java.lang.String">
                    <persistence type="property" />
                </attribute>
            </attributes>
        </itemtype>

Upvotes: 0

Views: 1248

Answers (1)

HybrisHelp
HybrisHelp

Reputation: 5810

Cross verify through HMC, whether your attribute gets saved in storeFrontCustomerProcessModel or not?

Try changing AppointmentEmailContext class like

public class AppointmentEmailContext extends AbstractEmailContext<AppointmentProcessModel>
{
   private String myAttribute;

    @Override
    public void init(final AppointmentProcessModel appointmentProcessModel, final EmailPageModel emailPageModel)
    {
        super.init(appointmentProcessModel, emailPageModel);
        myAttribute = appointmentProcessModel.getMyAttribute();
    }

    public String getMyAttribute() {
        return myAttribute;
    }

    //...
}

Edit

A user hasn't created the Item type for AppointmentProcess, later he has created it as I mentioned in the comment and issue resolved!!

Upvotes: 1

Related Questions