Search in sources :

Example 1 with CustomerAddress

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

the class CustomerAddressDaoImpl method readBatchCustomerAddresses.

@Override
public List<CustomerAddress> readBatchCustomerAddresses(int start, int pageSize) {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<CustomerAddress> criteria = builder.createQuery(CustomerAddress.class);
    Root<CustomerAddressImpl> customer = criteria.from(CustomerAddressImpl.class);
    criteria.select(customer);
    TypedQuery<CustomerAddress> query = em.createQuery(criteria);
    query.setFirstResult(start);
    query.setMaxResults(pageSize);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.CustomerAddress");
    return query.getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) CustomerAddressImpl(org.broadleafcommerce.profile.core.domain.CustomerAddressImpl) CustomerAddress(org.broadleafcommerce.profile.core.domain.CustomerAddress)

Example 2 with CustomerAddress

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

the class CustomerAddressDaoImpl method makeCustomerAddressDefault.

public void makeCustomerAddressDefault(Long customerAddressId, Long customerId) {
    List<CustomerAddress> customerAddresses = readActiveCustomerAddressesByCustomerId(customerId);
    for (CustomerAddress customerAddress : customerAddresses) {
        customerAddress.getAddress().setDefault(customerAddress.getId().equals(customerAddressId));
        em.merge(customerAddress);
    }
}
Also used : CustomerAddress(org.broadleafcommerce.profile.core.domain.CustomerAddress)

Example 3 with CustomerAddress

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

the class CommonSetupBaseTest method createCustomerWithAddresses.

/**
 * Creates a country, state, and customer with some CustomerAddresses
 * @return customer created
 */
public Customer createCustomerWithAddresses() {
    createCountry();
    createState();
    CustomerAddress ca1 = new CustomerAddressImpl();
    Address address1 = new AddressImpl();
    address1.setAddressLine1("1234 Merit Drive");
    address1.setCity("Bozeman");
    address1.setPostalCode("75251");
    ca1.setAddress(address1);
    ca1.setAddressName("address1");
    CustomerAddress caResult = createCustomerWithAddress(ca1);
    assert caResult != null;
    assert caResult.getCustomer() != null;
    Customer customer = caResult.getCustomer();
    CustomerAddress ca2 = new CustomerAddressImpl();
    Address address2 = new AddressImpl();
    address2.setAddressLine1("12 Testing Drive");
    address2.setCity("Portland");
    address2.setPostalCode("75251");
    ca2.setAddress(address2);
    ca2.setAddressName("address2");
    ca2.setCustomer(customer);
    CustomerAddress addResult = saveCustomerAddress(ca2);
    assert addResult != null;
    return customer;
}
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) AddressImpl(org.broadleafcommerce.profile.core.domain.AddressImpl) CustomerAddressImpl(org.broadleafcommerce.profile.core.domain.CustomerAddressImpl) CustomerAddress(org.broadleafcommerce.profile.core.domain.CustomerAddress)

Example 4 with CustomerAddress

use of org.broadleafcommerce.profile.core.domain.CustomerAddress 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 5 with CustomerAddress

use of org.broadleafcommerce.profile.core.domain.CustomerAddress 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)

Aggregations

CustomerAddress (org.broadleafcommerce.profile.core.domain.CustomerAddress)19 Customer (org.broadleafcommerce.profile.core.domain.Customer)8 Address (org.broadleafcommerce.profile.core.domain.Address)7 Transactional (org.springframework.transaction.annotation.Transactional)5 CustomerAddressImpl (org.broadleafcommerce.profile.core.domain.CustomerAddressImpl)4 Test (org.testng.annotations.Test)4 Order (org.broadleafcommerce.core.order.domain.Order)3 AddressImpl (org.broadleafcommerce.profile.core.domain.AddressImpl)3 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)2 FulfillmentOption (org.broadleafcommerce.core.order.domain.FulfillmentOption)2 CommonSetupBaseTest (org.broadleafcommerce.test.CommonSetupBaseTest)2 Query (javax.persistence.Query)1 TypedQuery (javax.persistence.TypedQuery)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)1 ServiceException (org.broadleafcommerce.common.exception.ServiceException)1 Status (org.broadleafcommerce.common.persistence.Status)1 OrderPayment (org.broadleafcommerce.core.payment.domain.OrderPayment)1 Entity (org.broadleafcommerce.openadmin.dto.Entity)1 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)1