Search in sources :

Example 11 with Address

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

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

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

the class CustomerAddressDataProvider method createCustomerAddress.

@DataProvider(name = "setupCustomerAddress")
public static Object[][] createCustomerAddress() {
    CustomerAddress ca1 = new CustomerAddressImpl();
    Address address1 = new AddressImpl();
    address1.setAddressLine1("1234 Merit Drive");
    address1.setCity("Bozeman");
    address1.setPostalCode("75251");
    ca1.setAddress(address1);
    ca1.setAddressName("address4");
    CustomerAddress ca2 = new CustomerAddressImpl();
    Address address2 = new AddressImpl();
    address2.setAddressLine1("12 Testing Drive");
    address2.setCity("Portland");
    address2.setPostalCode("75251");
    ca2.setAddress(address2);
    ca2.setAddressName("address5");
    return new Object[][] { new Object[] { ca1 }, new Object[] { ca2 } };
}
Also used : CustomerAddressImpl(org.broadleafcommerce.profile.core.domain.CustomerAddressImpl) CustomerAddress(org.broadleafcommerce.profile.core.domain.CustomerAddress) Address(org.broadleafcommerce.profile.core.domain.Address) CustomerAddressImpl(org.broadleafcommerce.profile.core.domain.CustomerAddressImpl) AddressImpl(org.broadleafcommerce.profile.core.domain.AddressImpl) CustomerAddress(org.broadleafcommerce.profile.core.domain.CustomerAddress) DataProvider(org.testng.annotations.DataProvider)

Example 14 with Address

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

the class AddressServiceImpl method verifyAddress.

@Override
public List<Address> verifyAddress(Address address) throws AddressVerificationException {
    if (address.getStandardized() != null && Boolean.TRUE.equals(address.getStandardized())) {
        // If this address is already standardized, don't waste a call.
        ArrayList<Address> out = new ArrayList<Address>();
        out.add(address);
        return out;
    }
    if (providers != null && !providers.isEmpty()) {
        List<ModuleConfiguration> moduleConfigs = moduleConfigService.findActiveConfigurationsByType(ModuleConfigurationType.ADDRESS_VERIFICATION);
        if (moduleConfigs != null && !moduleConfigs.isEmpty()) {
            // Try to find a default configuration
            ModuleConfiguration config = null;
            for (ModuleConfiguration configuration : moduleConfigs) {
                if (configuration.getIsDefault()) {
                    config = configuration;
                    break;
                }
            }
            if (config == null) {
                // if there wasn't a default one, use the first active one...
                config = moduleConfigs.get(0);
            }
            for (AddressVerificationProvider provider : providers) {
                if (provider.canRespond(config)) {
                    return provider.validateAddress(address, config);
                }
            }
        }
    }
    if (mustValidateAddresses) {
        throw new AddressVerificationException("No providers were configured to handle address validation");
    }
    ArrayList<Address> out = new ArrayList<Address>();
    out.add(address);
    return out;
}
Also used : ModuleConfiguration(org.broadleafcommerce.common.config.domain.ModuleConfiguration) Address(org.broadleafcommerce.profile.core.domain.Address) ArrayList(java.util.ArrayList) AddressVerificationException(org.broadleafcommerce.profile.core.service.exception.AddressVerificationException)

Example 15 with Address

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

the class SimpleTaxProvider method determineTaxRateForFulfillmentGroup.

/**
 * Uses the passed in address to determine if the item is taxable.
 *
 * Checks the configured maps in order - (postal code, city, state, country)
 *
 * @param fulfillmentGroup
 * @return
 */
public BigDecimal determineTaxRateForFulfillmentGroup(FulfillmentGroup fulfillmentGroup) {
    boolean isTaxable = true;
    if (fulfillmentGroup.isShippingPriceTaxable() != null) {
        isTaxable = fulfillmentGroup.isShippingPriceTaxable();
    }
    if (isTaxable) {
        Address address = fulfillmentGroup.getAddress();
        if (address != null) {
            Double postalCodeRate = lookupPostalCodeRate(fulfillmentGroupPostalCodeTaxRateMap, address.getPostalCode());
            if (postalCodeRate != null) {
                return BigDecimal.valueOf(postalCodeRate);
            }
            Double cityCodeRate = lookupCityRate(fulfillmentGroupCityTaxRateMap, address.getCity());
            if (cityCodeRate != null) {
                return BigDecimal.valueOf(cityCodeRate);
            }
            Double stateCodeRate;
            if (StringUtils.isNotBlank(address.getStateProvinceRegion())) {
                stateCodeRate = lookupStateRate(fulfillmentGroupStateTaxRateMap, address.getStateProvinceRegion());
            } else {
                stateCodeRate = lookupStateRate(fulfillmentGroupStateTaxRateMap, address.getState());
            }
            if (stateCodeRate != null) {
                return BigDecimal.valueOf(stateCodeRate);
            }
            Double countryCodeRate;
            if (address.getIsoCountryAlpha2() != null) {
                countryCodeRate = lookupCountryRate(fulfillmentGroupCountryTaxRateMap, address.getIsoCountryAlpha2());
            } else {
                countryCodeRate = lookupCountryRate(fulfillmentGroupCountryTaxRateMap, address.getCountry());
            }
            if (countryCodeRate != null) {
                return BigDecimal.valueOf(countryCodeRate);
            }
        }
        if (defaultFulfillmentGroupTaxRate != null) {
            return BigDecimal.valueOf(defaultFulfillmentGroupTaxRate);
        }
    }
    return BigDecimal.ZERO;
}
Also used : Address(org.broadleafcommerce.profile.core.domain.Address)

Aggregations

Address (org.broadleafcommerce.profile.core.domain.Address)37 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)15 Order (org.broadleafcommerce.core.order.domain.Order)15 Customer (org.broadleafcommerce.profile.core.domain.Customer)14 AddressImpl (org.broadleafcommerce.profile.core.domain.AddressImpl)11 CustomerAddress (org.broadleafcommerce.profile.core.domain.CustomerAddress)11 Transactional (org.springframework.transaction.annotation.Transactional)10 Test (org.testng.annotations.Test)10 FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)9 Money (org.broadleafcommerce.common.money.Money)8 ArrayList (java.util.ArrayList)7 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)7 State (org.broadleafcommerce.profile.core.domain.State)7 StateImpl (org.broadleafcommerce.profile.core.domain.StateImpl)7 ISOCountry (org.broadleafcommerce.common.i18n.domain.ISOCountry)6 ISOCountryImpl (org.broadleafcommerce.common.i18n.domain.ISOCountryImpl)6 FulfillmentGroupImpl (org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl)6 FulfillmentGroupItemImpl (org.broadleafcommerce.core.order.domain.FulfillmentGroupItemImpl)6 Country (org.broadleafcommerce.profile.core.domain.Country)6 CountryImpl (org.broadleafcommerce.profile.core.domain.CountryImpl)6