Search in sources :

Example 21 with Customer

use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.

the class CommonSetupBaseTest method createCustomerWithBasicOrderAndAddresses.

/**
 * Create a state, country, and customer with a basic order and some addresses
 */
public Customer createCustomerWithBasicOrderAndAddresses() {
    Customer customer = createCustomerWithAddresses();
    Order order = new OrderImpl();
    order.setStatus(OrderStatus.IN_PROCESS);
    order.setTotal(new Money(BigDecimal.valueOf(1000)));
    assert order.getId() == null;
    order.setCustomer(customer);
    order = orderDao.save(order);
    assert order.getId() != null;
    return customer;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Money(org.broadleafcommerce.common.money.Money) Customer(org.broadleafcommerce.profile.core.domain.Customer) OrderImpl(org.broadleafcommerce.core.order.domain.OrderImpl)

Example 22 with Customer

use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.

the class RegisterCustomerValidator method validate.

public void validate(Object obj, Errors errors, boolean useEmailForUsername) {
    RegisterCustomerForm form = (RegisterCustomerForm) obj;
    Customer customerFromDb = customerService.readCustomerByUsername(form.getCustomer().getUsername());
    if (customerFromDb != null && customerFromDb.isRegistered()) {
        if (useEmailForUsername) {
            errors.rejectValue("customer.emailAddress", "emailAddress.used", null, null);
        } else {
            errors.rejectValue("customer.username", "username.used", null, null);
        }
    }
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "password.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "passwordConfirm", "passwordConfirm.required");
    errors.pushNestedPath("customer");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", "firstName.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", "lastName.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "emailAddress", "emailAddress.required");
    errors.popNestedPath();
    if (!errors.hasErrors()) {
        if (!form.getPassword().matches(getValidatePasswordExpression())) {
            errors.rejectValue("password", "password.invalid", null, null);
        }
        if (!form.getPassword().equals(form.getPasswordConfirm())) {
            errors.rejectValue("password", "passwordConfirm.invalid", null, null);
        }
        if (!GenericValidator.isEmail(form.getCustomer().getEmailAddress())) {
            errors.rejectValue("customer.emailAddress", "emailAddress.invalid", null, null);
        }
    }
}
Also used : Customer(org.broadleafcommerce.profile.core.domain.Customer) RegisterCustomerForm(org.broadleafcommerce.profile.web.core.form.RegisterCustomerForm)

Example 23 with Customer

use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.

the class CustomerStateRefresher method onApplicationEvent.

/**
 * Removes the complete {@link Customer} stored in session and adds a new session variable for just the customer ID. This
 * should occur once the session-based {@link Customer} (all anonymous Customers start out this way) has been persisted.
 *
 * <p>Also updates {@link CustomerState} with the persisted {@link Customer} so that it will always represent the most
 * up-to-date version that is in the database</p>
 *
 * @param request
 * @param databaseCustomer
 */
@Override
public void onApplicationEvent(final CustomerPersistedEvent event) {
    Customer dbCustomer = event.getCustomer();
    // if there is an active request, remove the session-based customer if it exists and update CustomerState
    WebRequest request = BroadleafRequestContext.getBroadleafRequestContext().getWebRequest();
    if (request != null) {
        String customerAttribute = CustomerStateRequestProcessor.getAnonymousCustomerSessionAttributeName();
        String customerIdAttribute = CustomerStateRequestProcessor.getAnonymousCustomerIdSessionAttributeName();
        if (BLCRequestUtils.isOKtoUseSession(request)) {
            Customer sessionCustomer = (Customer) request.getAttribute(customerAttribute, WebRequest.SCOPE_GLOBAL_SESSION);
            // persisted
            if (sessionCustomer != null && sessionCustomer.getId().equals(dbCustomer.getId())) {
                request.removeAttribute(customerAttribute, WebRequest.SCOPE_GLOBAL_SESSION);
                request.setAttribute(customerIdAttribute, dbCustomer.getId(), WebRequest.SCOPE_GLOBAL_SESSION);
            }
        }
        // Update CustomerState if the persisted Customer ID is the same
        if (CustomerState.getCustomer() != null && CustomerState.getCustomer().getId().equals(dbCustomer.getId())) {
            // Copy transient fields from the customer that existed in CustomerState, prior to the DB refresh,
            // to the customer that has been saved (merged) in the DB....
            Customer preMergedCustomer = CustomerState.getCustomer();
            resetTransientFields(preMergedCustomer, dbCustomer);
            CustomerState.setCustomer(dbCustomer);
        }
    }
}
Also used : WebRequest(org.springframework.web.context.request.WebRequest) Customer(org.broadleafcommerce.profile.core.domain.Customer)

Example 24 with Customer

use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.

the class RegisterCustomerControllerTest method createCustomerFromController.

@Test(groups = "createCustomerFromController", dataProvider = "setupCustomerControllerData", dataProviderClass = RegisterCustomerDataProvider.class, enabled = false)
@Transactional
@Rollback(false)
public void createCustomerFromController(RegisterCustomerForm registerCustomer) {
    BindingResult errors = new BeanPropertyBindingResult(registerCustomer, "registerCustomer");
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    registerCustomerController.registerCustomer(registerCustomer, errors, request, response);
    assert (errors.getErrorCount() == 0);
    Customer customerFromDb = customerService.readCustomerByUsername(registerCustomer.getCustomer().getUsername());
    assert (customerFromDb != null);
}
Also used : BindingResult(org.springframework.validation.BindingResult) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) Customer(org.broadleafcommerce.profile.core.domain.Customer) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.testng.annotations.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 25 with Customer

use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.

the class RegisterCustomerDataProvider method createCustomer.

@DataProvider(name = "setupCustomerControllerData")
public static Object[][] createCustomer() {
    Customer customer = new CustomerImpl();
    customer.setEmailAddress("testCase@test.com");
    customer.setFirstName("TestFirstName");
    customer.setLastName("TestLastName");
    customer.setUsername("TestCase");
    ChallengeQuestion question = new ChallengeQuestionImpl();
    question.setId(1L);
    customer.setChallengeQuestion(question);
    customer.setChallengeAnswer("Challenge CandidateItemOfferAnswer");
    RegisterCustomerForm registerCustomer = new RegisterCustomerForm();
    registerCustomer.setCustomer(customer);
    registerCustomer.setPassword("TestPassword");
    registerCustomer.setPasswordConfirm("TestPassword");
    return new Object[][] { new Object[] { registerCustomer } };
}
Also used : Customer(org.broadleafcommerce.profile.core.domain.Customer) ChallengeQuestionImpl(org.broadleafcommerce.profile.core.domain.ChallengeQuestionImpl) RegisterCustomerForm(org.broadleafcommerce.profile.web.core.form.RegisterCustomerForm) CustomerImpl(org.broadleafcommerce.profile.core.domain.CustomerImpl) ChallengeQuestion(org.broadleafcommerce.profile.core.domain.ChallengeQuestion) DataProvider(org.testng.annotations.DataProvider)

Aggregations

Customer (org.broadleafcommerce.profile.core.domain.Customer)98 Order (org.broadleafcommerce.core.order.domain.Order)41 Transactional (org.springframework.transaction.annotation.Transactional)34 Test (org.testng.annotations.Test)33 Address (org.broadleafcommerce.profile.core.domain.Address)14 Rollback (org.springframework.test.annotation.Rollback)11 HashMap (java.util.HashMap)9 CustomerAddress (org.broadleafcommerce.profile.core.domain.CustomerAddress)9 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)8 MergeCartResponse (org.broadleafcommerce.core.order.service.call.MergeCartResponse)6 ArrayList (java.util.ArrayList)5 Money (org.broadleafcommerce.common.money.Money)5 Category (org.broadleafcommerce.core.catalog.domain.Category)5 Product (org.broadleafcommerce.core.catalog.domain.Product)5 AddressImpl (org.broadleafcommerce.profile.core.domain.AddressImpl)5 CommonSetupBaseTest (org.broadleafcommerce.test.CommonSetupBaseTest)5 CustomerImpl (org.broadleafcommerce.profile.core.domain.CustomerImpl)4 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)3 ServiceException (org.broadleafcommerce.common.exception.ServiceException)3 ISOCountry (org.broadleafcommerce.common.i18n.domain.ISOCountry)3