Search in sources :

Example 1 with PersistableCustomerBillingAddressPopulator

use of com.salesmanager.shop.populator.customer.PersistableCustomerBillingAddressPopulator in project shopizer by shopizer-ecommerce.

the class CustomerFacadeImpl method updateAddress.

@Override
public void updateAddress(Long userId, MerchantStore merchantStore, Address address, final Language language) throws Exception {
    Customer customerModel = customerService.getById(userId);
    Map<String, Country> countriesMap = countryService.getCountriesMap(language);
    Country country = countriesMap.get(address.getCountry());
    if (customerModel == null) {
        LOG.error("Customer with ID {} does not exists..", userId);
        // throw new CustomerNotFoundException( "customer with given id does not exists" );
        throw new Exception("customer with given id does not exists");
    }
    if (address.isBillingAddress()) {
        LOG.info("updating customer billing address..");
        PersistableCustomerBillingAddressPopulator billingAddressPopulator = new PersistableCustomerBillingAddressPopulator();
        customerModel = billingAddressPopulator.populate(address, customerModel, merchantStore, merchantStore.getDefaultLanguage());
        customerModel.getBilling().setCountry(country);
        if (StringUtils.isNotBlank(address.getZone())) {
            Zone zone = zoneService.getByCode(address.getZone());
            if (zone == null) {
                throw new ConversionException("Unsuported zone code " + address.getZone());
            }
            customerModel.getBilling().setZone(zone);
            customerModel.getBilling().setState(null);
        } else {
            customerModel.getBilling().setZone(null);
        }
    } else {
        LOG.info("updating customer shipping address..");
        PersistableCustomerShippingAddressPopulator shippingAddressPopulator = new PersistableCustomerShippingAddressPopulator();
        customerModel = shippingAddressPopulator.populate(address, customerModel, merchantStore, merchantStore.getDefaultLanguage());
        customerModel.getDelivery().setCountry(country);
        if (StringUtils.isNotBlank(address.getZone())) {
            Zone zone = zoneService.getByCode(address.getZone());
            if (zone == null) {
                throw new ConversionException("Unsuported zone code " + address.getZone());
            }
            customerModel.getDelivery().setZone(zone);
            customerModel.getDelivery().setState(null);
        } else {
            customerModel.getDelivery().setZone(null);
        }
    }
    // same update address with customer model
    this.customerService.saveOrUpdate(customerModel);
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) Zone(com.salesmanager.core.model.reference.zone.Zone) Country(com.salesmanager.core.model.reference.country.Country) PersistableCustomerBillingAddressPopulator(com.salesmanager.shop.populator.customer.PersistableCustomerBillingAddressPopulator) ServiceException(com.salesmanager.core.business.exception.ServiceException) UserAlreadyExistException(com.salesmanager.shop.model.customer.UserAlreadyExistException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ConversionException(com.salesmanager.core.business.exception.ConversionException) PersistableCustomerShippingAddressPopulator(com.salesmanager.shop.populator.customer.PersistableCustomerShippingAddressPopulator)

Aggregations

ConversionException (com.salesmanager.core.business.exception.ConversionException)1 ServiceException (com.salesmanager.core.business.exception.ServiceException)1 Customer (com.salesmanager.core.model.customer.Customer)1 Country (com.salesmanager.core.model.reference.country.Country)1 Zone (com.salesmanager.core.model.reference.zone.Zone)1 PersistableCustomer (com.salesmanager.shop.model.customer.PersistableCustomer)1 ReadableCustomer (com.salesmanager.shop.model.customer.ReadableCustomer)1 UserAlreadyExistException (com.salesmanager.shop.model.customer.UserAlreadyExistException)1 PersistableCustomerBillingAddressPopulator (com.salesmanager.shop.populator.customer.PersistableCustomerBillingAddressPopulator)1 PersistableCustomerShippingAddressPopulator (com.salesmanager.shop.populator.customer.PersistableCustomerShippingAddressPopulator)1 ConversionRuntimeException (com.salesmanager.shop.store.api.exception.ConversionRuntimeException)1 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)1 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)1