use of com.salesmanager.core.model.reference.zone.Zone 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);
}
use of com.salesmanager.core.model.reference.zone.Zone in project shopizer by shopizer-ecommerce.
the class ShippingFacadeImpl method getShippingOrigin.
@Override
public ReadableAddress getShippingOrigin(MerchantStore store) {
ShippingOrigin o = shippingOriginService.getByStore(store);
if (o == null) {
throw new ResourceNotFoundException("Shipping origin does not exists for store [" + store.getCode() + "]");
}
ReadableAddress address = new ReadableAddress();
address.setAddress(o.getAddress());
address.setActive(o.isActive());
address.setCity(o.getCity());
address.setPostalCode(o.getPostalCode());
if (o.getCountry() != null) {
address.setCountry(o.getCountry().getIsoCode());
}
Zone z = o.getZone();
if (z != null) {
address.setStateProvince(z.getCode());
} else {
address.setStateProvince(o.getState());
}
return address;
}
use of com.salesmanager.core.model.reference.zone.Zone in project shopizer by shopizer-ecommerce.
the class PersistableMerchantStorePopulator method populate.
@Override
public MerchantStore populate(PersistableMerchantStore source, MerchantStore target, MerchantStore store, Language language) throws ConversionException {
Validate.notNull(source, "PersistableMerchantStore mst not be null");
if (target == null) {
target = new MerchantStore();
}
target.setCode(source.getCode());
if (source.getId() != 0) {
target.setId(source.getId());
}
if (store.getStoreLogo() != null) {
target.setStoreLogo(store.getStoreLogo());
}
if (!StringUtils.isEmpty(source.getInBusinessSince())) {
try {
Date dt = DateUtil.getDate(source.getInBusinessSince());
target.setInBusinessSince(dt);
} catch (Exception e) {
throw new ConversionException("Cannot parse date [" + source.getInBusinessSince() + "]", e);
}
}
if (source.getDimension() != null) {
target.setSeizeunitcode(source.getDimension().name());
}
if (source.getWeight() != null) {
target.setWeightunitcode(source.getWeight().name());
}
target.setCurrencyFormatNational(source.isCurrencyFormatNational());
target.setStorename(source.getName());
target.setStorephone(source.getPhone());
target.setStoreEmailAddress(source.getEmail());
target.setUseCache(source.isUseCache());
target.setRetailer(source.isRetailer());
// get parent store
if (!StringUtils.isBlank(source.getRetailerStore())) {
if (source.getRetailerStore().equals(source.getCode())) {
throw new ConversionException("Parent store [" + source.getRetailerStore() + "] cannot be parent of current store");
}
try {
MerchantStore parent = merchantStoreService.getByCode(source.getRetailerStore());
if (parent == null) {
throw new ConversionException("Parent store [" + source.getRetailerStore() + "] does not exist");
}
target.setParent(parent);
} catch (ServiceException e) {
throw new ConversionException(e);
}
}
try {
if (!StringUtils.isEmpty(source.getDefaultLanguage())) {
Language l = languageService.getByCode(source.getDefaultLanguage());
target.setDefaultLanguage(l);
}
if (!StringUtils.isEmpty(source.getCurrency())) {
Currency c = currencyService.getByCode(source.getCurrency());
target.setCurrency(c);
} else {
target.setCurrency(currencyService.getByCode(Constants.DEFAULT_CURRENCY.getCurrencyCode()));
}
List<String> languages = source.getSupportedLanguages();
if (!CollectionUtils.isEmpty(languages)) {
for (String lang : languages) {
Language ll = languageService.getByCode(lang);
target.getLanguages().add(ll);
}
}
} catch (Exception e) {
throw new ConversionException(e);
}
// address population
PersistableAddress address = source.getAddress();
if (address != null) {
Country country;
try {
country = countryService.getByCode(address.getCountry());
Zone zone = zoneService.getByCode(address.getStateProvince());
if (zone != null) {
target.setZone(zone);
} else {
target.setStorestateprovince(address.getStateProvince());
}
target.setStoreaddress(address.getAddress());
target.setStorecity(address.getCity());
target.setCountry(country);
target.setStorepostalcode(address.getPostalCode());
} catch (ServiceException e) {
throw new ConversionException(e);
}
}
if (StringUtils.isNotEmpty(source.getTemplate()))
target.setStoreTemplate(source.getTemplate());
return target;
}
use of com.salesmanager.core.model.reference.zone.Zone in project shopizer by shopizer-ecommerce.
the class ReadableMerchantStorePopulator method populate.
@Override
public ReadableMerchantStore populate(MerchantStore source, ReadableMerchantStore target, MerchantStore store, Language language) throws ConversionException {
Validate.notNull(countryService, "Must use setter for countryService");
Validate.notNull(zoneService, "Must use setter for zoneService");
if (target == null) {
target = new ReadableMerchantStore();
}
target.setId(source.getId());
target.setCode(source.getCode());
if (source.getDefaultLanguage() != null) {
target.setDefaultLanguage(source.getDefaultLanguage().getCode());
}
target.setCurrency(source.getCurrency().getCode());
target.setPhone(source.getStorephone());
ReadableAddress address = new ReadableAddress();
address.setAddress(source.getStoreaddress());
address.setCity(source.getStorecity());
if (source.getCountry() != null) {
try {
address.setCountry(source.getCountry().getIsoCode());
Country c = countryService.getCountriesMap(language).get(source.getCountry().getIsoCode());
if (c != null) {
address.setCountry(c.getIsoCode());
}
} catch (ServiceException e) {
logger.error("Cannot get Country", e);
}
}
if (source.getParent() != null) {
ReadableMerchantStore parent = populate(source.getParent(), new ReadableMerchantStore(), source, language);
target.setParent(parent);
}
if (target.getParent() == null) {
target.setRetailer(true);
} else {
target.setRetailer(source.isRetailer() != null ? source.isRetailer().booleanValue() : false);
}
target.setDimension(MeasureUnit.valueOf(source.getSeizeunitcode()));
target.setWeight(WeightUnit.valueOf(source.getWeightunitcode()));
if (source.getZone() != null) {
address.setStateProvince(source.getZone().getCode());
try {
Zone z = zoneService.getZones(language).get(source.getZone().getCode());
address.setStateProvince(z.getCode());
} catch (ServiceException e) {
logger.error("Cannot get Zone", e);
}
}
if (!StringUtils.isBlank(source.getStorestateprovince())) {
address.setStateProvince(source.getStorestateprovince());
}
if (!StringUtils.isBlank(source.getStoreLogo())) {
ReadableImage image = new ReadableImage();
image.setName(source.getStoreLogo());
if (filePath != null) {
image.setPath(filePath.buildStoreLogoFilePath(source));
}
target.setLogo(image);
}
address.setPostalCode(source.getStorepostalcode());
target.setAddress(address);
target.setCurrencyFormatNational(source.isCurrencyFormatNational());
target.setEmail(source.getStoreEmailAddress());
target.setName(source.getStorename());
target.setId(source.getId());
target.setInBusinessSince(DateUtil.formatDate(source.getInBusinessSince()));
target.setUseCache(source.isUseCache());
if (!CollectionUtils.isEmpty(source.getLanguages())) {
List<ReadableLanguage> supported = new ArrayList<ReadableLanguage>();
for (Language lang : source.getLanguages()) {
try {
Language langObject = languageService.getLanguagesMap().get(lang.getCode());
if (langObject != null) {
ReadableLanguage l = new ReadableLanguage();
l.setId(langObject.getId());
l.setCode(langObject.getCode());
supported.add(l);
}
} catch (ServiceException e) {
logger.error("Cannot get Language [" + lang.getId() + "]");
}
}
target.setSupportedLanguages(supported);
}
if (source.getAuditSection() != null) {
ReadableAudit audit = new ReadableAudit();
if (source.getAuditSection().getDateCreated() != null) {
audit.setCreated(DateUtil.formatDate(source.getAuditSection().getDateCreated()));
}
if (source.getAuditSection().getDateModified() != null) {
audit.setModified(DateUtil.formatDate(source.getAuditSection().getDateCreated()));
}
audit.setUser(source.getAuditSection().getModifiedBy());
target.setReadableAudit(audit);
}
return target;
}
use of com.salesmanager.core.model.reference.zone.Zone in project shopizer by shopizer-ecommerce.
the class ShippingFacadeImpl method saveShippingOrigin.
@Override
public void saveShippingOrigin(PersistableAddress address, MerchantStore store) {
Validate.notNull(address, "PersistableAddress cannot be null");
try {
ShippingOrigin o = shippingOriginService.getByStore(store);
if (o == null) {
o = new ShippingOrigin();
}
o.setAddress(address.getAddress());
o.setCity(address.getCity());
o.setCountry(countryService.getByCode(address.getCountry()));
o.setMerchantStore(store);
o.setActive(address.isActive());
o.setPostalCode(address.getPostalCode());
Zone zone = zoneService.getByCode(address.getStateProvince());
if (zone == null) {
o.setState(address.getStateProvince());
} else {
o.setZone(zone);
}
shippingOriginService.save(o);
} catch (ServiceException e) {
LOGGER.error("Error while getting shipping origin for country [" + address.getCountry() + "]", e);
throw new ServiceRuntimeException("Error while getting shipping origin for country [" + address.getCountry() + "]", e);
}
}
Aggregations