/**
*
*/
public Customer buildAndSaveNewCustomer(final RequestData requestData, final Market market, final MarketArea marketArea,
final CreateAccountForm createAccountForm) throws Exception {
Customer customer = new Customer();
customer.setLogin(createAccountForm.getEmail());
customer.setFirstname(createAccountForm.getFirstname());
customer.setLastname(createAccountForm.getLastname());
customer.setPassword(securityUtil.encodePassword(createAccountForm.getPassword()));
customer.setEmail(createAccountForm.getEmail());
CustomerAddress defaultAddress = new CustomerAddress();
if(StringUtils.isNotEmpty(createAccountForm.getAddressName())){
defaultAddress.setAddressName(createAccountForm.getAddressName());
} else {
defaultAddress.setAddressName(createAccountForm.getAddress1() + "(" + createAccountForm.getCity() + ")");
}
defaultAddress.setTitle(createAccountForm.getTitle());
defaultAddress.setLastname(createAccountForm.getLastname());
defaultAddress.setFirstname(createAccountForm.getFirstname());
defaultAddress.setAddress1(createAccountForm.getAddress1());
defaultAddress.setAddress2(createAccountForm.getAddress2());
defaultAddress.setAddressAdditionalInformation(createAccountForm.getAddressAdditionalInformation());
defaultAddress.setPostalCode(createAccountForm.getPostalCode());
defaultAddress.setCity(createAccountForm.getCity());
defaultAddress.setStateCode(createAccountForm.getStateCode());
defaultAddress.setCountryCode(createAccountForm.getCountryCode());
defaultAddress.setDefaultBilling(true);
defaultAddress.setDefaultShipping(true);
Set<CustomerAddress> addresses = new HashSet<CustomerAddress>();
addresses.add(defaultAddress);
customer.setAddresses(addresses);
return buildAndSaveNewCustomer(requestData, market, marketArea, customer);
}