1

I have added a new attribute Pan (pancard number) on the registration form. Validations are also working fine. But if I hit the register tab, I get an error like

de.hybris.platform.servicelayer.exceptions.ModelSavingException: [de.hybris.platform.servicelayer.interceptor.impl.MandatoryAttributesValidator@246420ba]:missing values for [pan] in model CustomerModel () to create a new Customer] with root cause de.hybris.platform.servicelayer.interceptor.impl.MandatoryAttributesValidator$MissingMandatoryAttributesException: [de.hybris.platform.servicelayer.interceptor.impl.MandatoryAttributesValidator@246420ba]:missing values for [pan] in model CustomerModel () to create a new Customer

To resolve this error I tried modifier optional = "true" in items.xml doing that above error got resolved but I am not able to store the value for the pan.
So please help me to solve both issues customermodel error and storing value in the database.

HoRn
  • 1,458
  • 5
  • 20
  • 25
user0809
  • 11
  • 4

2 Answers2

0

You need to extend RegisterForm, RegisterData, RegistrationPageController and CustomerFacade to transfer new field value to model.

mkysoft
  • 5,392
  • 1
  • 21
  • 30
0

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

Aldali
  • 40
  • 5