Search in sources :

Example 1 with CustomerPhone

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);
    }
}
Also used : CustomerPhone(org.broadleafcommerce.profile.core.domain.CustomerPhone)

Example 2 with 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();
}
Also used : CustomerPhone(org.broadleafcommerce.profile.core.domain.CustomerPhone)

Example 3 with CustomerPhone

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;
        }
    }
}
Also used : CustomerPhone(org.broadleafcommerce.profile.core.domain.CustomerPhone) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with CustomerPhone

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;
    }
}
Also used : CustomerPhone(org.broadleafcommerce.profile.core.domain.CustomerPhone) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with CustomerPhone

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;
}
Also used : CustomerPhone(org.broadleafcommerce.profile.core.domain.CustomerPhone) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

CustomerPhone (org.broadleafcommerce.profile.core.domain.CustomerPhone)13 Transactional (org.springframework.transaction.annotation.Transactional)5 Test (org.testng.annotations.Test)4 Customer (org.broadleafcommerce.profile.core.domain.Customer)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 Phone (org.broadleafcommerce.profile.core.domain.Phone)2 PhoneImpl (org.broadleafcommerce.profile.core.domain.PhoneImpl)2 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)2 BindingResult (org.springframework.validation.BindingResult)2 Query (javax.persistence.Query)1 CustomerPhoneImpl (org.broadleafcommerce.profile.core.domain.CustomerPhoneImpl)1 PhoneNameForm (org.broadleafcommerce.profile.web.core.model.PhoneNameForm)1 Commit (org.springframework.test.annotation.Commit)1 Rollback (org.springframework.test.annotation.Rollback)1 DataProvider (org.testng.annotations.DataProvider)1