Search in sources :

Example 26 with Customer

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

the class CustomerAddressTest method readCustomerAddresses.

@Test(groups = "testCustomerAddress")
@Transactional
public void readCustomerAddresses() {
    Customer customer = createCustomerWithAddresses();
    List<CustomerAddress> customerAddressList = customerAddressService.readActiveCustomerAddressesByCustomerId(customer.getId());
    for (CustomerAddress ca : customerAddressList) {
        assert ca != null;
    }
}
Also used : Customer(org.broadleafcommerce.profile.core.domain.Customer) CustomerAddress(org.broadleafcommerce.profile.core.domain.CustomerAddress) Test(org.testng.annotations.Test) CommonSetupBaseTest(org.broadleafcommerce.test.CommonSetupBaseTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 27 with Customer

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

the class CustomerAddressTest method createNewDefaultAddress.

@Test(groups = "testCustomerAddress")
@Transactional
public void createNewDefaultAddress() {
    Customer customer = createCustomerWithAddresses();
    CustomerAddress ca = new CustomerAddressImpl();
    Address address = new AddressImpl();
    address.setAddressLine1("123 Main");
    address.setCity("Dallas");
    address.setPostalCode("75201");
    address.setDefault(true);
    ca.setAddress(address);
    ca.setCustomer(customer);
    ca.setAddressName("address3");
    CustomerAddress savedAddress = saveCustomerAddress(ca);
    List<CustomerAddress> customerAddressList = customerAddressService.readActiveCustomerAddressesByCustomerId(customer.getId());
    for (CustomerAddress customerAddress : customerAddressList) {
        if (customerAddress.getId().equals(savedAddress.getId())) {
            assert customerAddress.getAddress().isDefault();
        } else {
            assert !customerAddress.getAddress().isDefault();
        }
    }
}
Also used : CustomerAddressImpl(org.broadleafcommerce.profile.core.domain.CustomerAddressImpl) Address(org.broadleafcommerce.profile.core.domain.Address) CustomerAddress(org.broadleafcommerce.profile.core.domain.CustomerAddress) Customer(org.broadleafcommerce.profile.core.domain.Customer) CustomerAddressImpl(org.broadleafcommerce.profile.core.domain.CustomerAddressImpl) AddressImpl(org.broadleafcommerce.profile.core.domain.AddressImpl) CustomerAddress(org.broadleafcommerce.profile.core.domain.CustomerAddress) Test(org.testng.annotations.Test) CommonSetupBaseTest(org.broadleafcommerce.test.CommonSetupBaseTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 28 with Customer

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

the class CustomerTest method createCustomer.

@Test(groups = "createCustomers", dependsOnGroups = "createCustomerIdGeneration", dataProvider = "setupCustomers", dataProviderClass = CustomerDataProvider.class)
@Rollback(false)
public void createCustomer(Customer customerInfo) {
    Customer customer = customerService.createCustomerFromId(null);
    customer.setPassword(customerInfo.getPassword());
    customer.setUsername(customerInfo.getUsername());
    Long customerId = customer.getId();
    assert customerId != null;
    customer = customerService.saveCustomer(customer);
    assert customer.getId() == customerId;
    userIds.add(customer.getId());
    userNames.add(customer.getUsername());
}
Also used : Customer(org.broadleafcommerce.profile.core.domain.Customer) Test(org.testng.annotations.Test) Rollback(org.springframework.test.annotation.Rollback)

Example 29 with Customer

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

the class CustomerTest method changeCustomerPasswords.

/*@Test(groups = { "readCustomer1" }, dependsOnGroups = { "createCustomers" })
    public void readCustomersByUsername1() {
        for (String userName : userNames) {
            UserDetails userDetails = userDetailsService.loadUserByUsername(userName);
            assert userDetails != null && userDetails.getPassword().equals(userDetails.getUsername() + "Password");
        }
    }*/
@Test(groups = { "changeCustomerPassword" }, dependsOnGroups = { "readCustomer" })
@Transactional
@Commit
public void changeCustomerPasswords() {
    for (String userName : userNames) {
        Customer customer = customerService.readCustomerByUsername(userName);
        customer.setPassword(customer.getPassword() + "-Changed");
        customerService.saveCustomer(customer);
    }
}
Also used : Customer(org.broadleafcommerce.profile.core.domain.Customer) Commit(org.springframework.test.annotation.Commit) Test(org.testng.annotations.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 30 with Customer

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

the class CustomerStateRequestProcessor method mergeCustomerIfRequired.

/**
 * Allows the merging of anonymous customer data and / or session data, to the logged in customer, if required.
 * This is written to only require it to happen once.
 * @param request
 * @param customer
 * @return
 */
protected Customer mergeCustomerIfRequired(WebRequest request, Customer customer) {
    if (BLCRequestUtils.isOKtoUseSession(request)) {
        // Don't call this if it has already been called
        if (request.getAttribute(getAnonymousCustomerMergedSessionAttributeName(), WebRequest.SCOPE_GLOBAL_SESSION) == null) {
            // Set this so we don't do this every time.
            request.setAttribute(getAnonymousCustomerMergedSessionAttributeName(), Boolean.TRUE, WebRequest.SCOPE_GLOBAL_SESSION);
            Customer anonymousCustomer = getAnonymousCustomer(request);
            customer = copyAnonymousCustomerInfoToCustomer(request, anonymousCustomer, customer);
        }
    }
    return customer;
}
Also used : Customer(org.broadleafcommerce.profile.core.domain.Customer)

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