use of org.broadleafcommerce.profile.core.domain.CustomerPhone in project BroadleafCommerce by BroadleafCommerce.
the class CustomerPhoneDaoImpl method makeCustomerPhoneDefault.
public void makeCustomerPhoneDefault(Long customerPhoneId, Long customerId) {
List<CustomerPhone> customerPhones = readActiveCustomerPhonesByCustomerId(customerId);
for (CustomerPhone customerPhone : customerPhones) {
customerPhone.getPhone().setDefault(customerPhone.getId().equals(customerPhoneId));
em.merge(customerPhone);
}
}
use of org.broadleafcommerce.profile.core.domain.CustomerPhone in project BroadleafCommerce by BroadleafCommerce.
the class PaymentRequestDTOServiceImpl method populateCustomerInfo.
@Override
public PaymentRequestDTO populateCustomerInfo(PaymentRequestDTO requestDTO, Customer customer, String defaultEmailAddress) {
String phoneNumber = null;
for (CustomerPhone phone : ListUtils.emptyIfNull(customer.getCustomerPhones())) {
if (phone.getPhone().isDefault()) {
phoneNumber = phone.getPhone().getPhoneNumber();
}
}
String emailAddress = (customer.getEmailAddress() == null) ? defaultEmailAddress : customer.getEmailAddress();
return requestDTO.customer().customerId(customer.getId().toString()).firstName(customer.getFirstName()).lastName(customer.getLastName()).email(emailAddress).phone(phoneNumber).done();
}
use of org.broadleafcommerce.profile.core.domain.CustomerPhone in project BroadleafCommerce by BroadleafCommerce.
the class CustomerPhoneController method viewPhone.
/**
* Provides a blank template for a new Customer Phone to be created if no customerPhoneId is provided.
* Otherwise, when a customerPhoneId is provided, the associated customerPhone object is retrieved,
* and placed on the request.
*
* @param customerPhoneId
* @param request
* @param phoneNameForm
* @param errors
* @return
*/
@RequestMapping(value = "viewPhone", method = { RequestMethod.GET, RequestMethod.POST })
public String viewPhone(@RequestParam(required = false) Long customerPhoneId, HttpServletRequest request, @ModelAttribute("phoneNameForm") PhoneNameForm phoneNameForm, BindingResult errors) {
if (customerPhoneId == null) {
return viewPhoneSuccessView;
} else {
Long currCustomerId = customerState.getCustomer(request).getId();
CustomerPhone cPhone = customerPhoneService.readCustomerPhoneById(customerPhoneId);
if (cPhone != null) {
// ? - do we really need this since we read the phone with the currCustomerId?
if (!cPhone.getCustomer().getId().equals(currCustomerId)) {
return viewPhoneErrorView;
}
phoneNameForm.setPhone(cPhone.getPhone());
phoneNameForm.setPhoneName(cPhone.getPhoneName());
request.setAttribute("customerPhoneId", cPhone.getId());
request.setAttribute("phoneId", cPhone.getPhone().getId());
return viewPhoneSuccessView;
} else {
return viewPhoneErrorView;
}
}
}
use of org.broadleafcommerce.profile.core.domain.CustomerPhone in project BroadleafCommerce by BroadleafCommerce.
the class CustomerPhoneController method savePhone.
/**
* Creates a new phone if no customerPhoneId & phoneId are passed in; otherwise, it creates a new customerPhone object otherwise. If they are passed in,
* it is assumed that there is an update.
*
* @param phoneNameForm
* @param errors
* @param request
* @param customerPhoneId DOCUMENT ME!
* @param phoneId DOCUMENT ME!
*
* @return
*/
@RequestMapping(value = "savePhone", method = { RequestMethod.GET, RequestMethod.POST })
public String savePhone(@ModelAttribute("phoneNameForm") PhoneNameForm phoneNameForm, BindingResult errors, HttpServletRequest request, @RequestParam(required = false) Long customerPhoneId, @RequestParam(required = false) Long phoneId) {
if (GenericValidator.isBlankOrNull(phoneNameForm.getPhoneName())) {
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "phoneName", "phoneName.required");
}
if (phoneId != null) {
phoneNameForm.getPhone().setId(phoneId);
}
phoneFormatter.formatPhoneNumber(phoneNameForm.getPhone());
errors.pushNestedPath("phone");
phoneValidator.validate(phoneNameForm.getPhone(), errors);
errors.popNestedPath();
if (!errors.hasErrors()) {
CustomerPhone customerPhone = (CustomerPhone) entityConfiguration.createEntityInstance("org.broadleafcommerce.profile.core.domain.CustomerPhone");
customerPhone.setCustomer(customerState.getCustomer(request));
customerPhone.setPhoneName(phoneNameForm.getPhoneName());
customerPhone.setPhone(phoneNameForm.getPhone());
if ((customerPhoneId != null) && (customerPhoneId > 0)) {
customerPhone.setId(customerPhoneId);
}
customerPhoneValidator.validate(customerPhone, errors);
if (!errors.hasErrors()) {
customerPhone = customerPhoneService.saveCustomerPhone(customerPhone);
request.setAttribute("customerPhoneId", customerPhone.getId());
request.setAttribute("phoneId", customerPhone.getPhone().getId());
}
return savePhoneSuccessView;
} else {
return savePhoneErrorView;
}
}
use of org.broadleafcommerce.profile.core.domain.CustomerPhone in project BroadleafCommerce by BroadleafCommerce.
the class CustomerPhoneController method makePhoneDefault.
/**
* Sets the passed in customerPhoneId as the default phone for the user.
*
* @param customerPhoneId
* @param request
*
* @return
*/
@RequestMapping(value = "makePhoneDefault", method = { RequestMethod.GET, RequestMethod.POST })
public String makePhoneDefault(@RequestParam(required = true) Long customerPhoneId, HttpServletRequest request) {
CustomerPhone customerPhone = customerPhoneService.readCustomerPhoneById(customerPhoneId);
customerPhoneService.makeCustomerPhoneDefault(customerPhone.getId(), customerPhone.getCustomer().getId());
request.setAttribute("phone.madePhoneDefault", "true");
return makePhoneDefaultSuccessView;
}
Aggregations