Before I jump into the solution, I'd like to clarify my approach:
A new change request (CR) is needed in the default (OOTB) registration functionality (or it can be any other functionality in SAP CC). The CR includes UI and data model changes. Basically, adding new field in the registration form, then passing it to CustomerModel
to persist it in the database.
Now to the solution:
I'm assuming that you managed to add the new form registration field in the UI, hence, I'm proceeding with java code side.
The method for the registration is in LoginPageController.java
class.
@RequestMapping(value = "/register", method = RequestMethod.POST)
public String doRegister(@RequestHeader(value = "referer", required = false)
final String referer, final RegisterForm form, final BindingResult bindingResult, final Model model,
final HttpServletRequest request, final HttpServletResponse response, final RedirectAttributes redirectModel)
throws CMSItemNotFoundException
{
getRegistrationValidator().validate(form, bindingResult);
return processRegisterUserRequest(referer, form, bindingResult, model, request, response, redirectModel);
}
First of all, you need to add the new attribute pan
to RegisterForm.java by extending the original form.
public class CustomRegisterForm extends RegisterForm
{
private String pan;
public String getPan() {
return pan;
}
public void setPan(String pan) {
this.pan = pan;
}
}
And you need to replace the parameter final RegisterForm form
with final CustomRegisterForm form
in above doRegister
method.
Next, you need to add a new property pan
to RegisterData
bean in custom-beans.xml file.
<bean class="de.hybris.platform.commercefacades.user.data.RegisterData">
<property name="pan" type="String"/>
</bean>
Then you need to write your a custom processRegisterUserRequest
method that has the parameter final CustomRegisterForm form
instead of final RegisterForm form
.
The content of the method will be almost the same with adding one extra line to set the value of the new attribute pan
in RegisterData
.
final RegisterData data = new RegisterData();
...
...
data.setPan(form.getPan());
Lastly, you need to extend the default implementation of DefaultCustomerFacade.java
(let's say DefaultCustomCustomerFacade.java
) and override the bean definition in custom-spring.xml file.
<alias name="defaultCustomCustomerFacade" alias="b2bCustomerFacade"/>
<bean id="defaultCustomCustomerFacade" class="xxx.yyy.uuu.DefaultCustomCustomerFacade" parent="defaultB2BCustomerFacade">
</bean>
In your DefaultCustomCustomerFacade.java
you mainly will override two methods which are register
and setCommonPropertiesForRegister
In setCommonPropertiesForRegister
you will set the value of the new attribute pan
in CustomerModel
.
protected void setCommonPropertiesForRegister(final RegisterData registerData, final CustomerModel customerModel)
{
...
...
...
customerModel.setPan(registerData.getPan());
}
As the CustomerModel.Pan value is set now, when the CustomerModel is saved, the value of pan
will be persisted in the database.