use of com.salesmanager.shop.model.store.PersistableMerchantStore in project shopizer by shopizer-ecommerce.
the class StoreFacadeImpl method create.
@Override
public void create(PersistableMerchantStore store) {
Validate.notNull(store, "PersistableMerchantStore must not be null");
Validate.notNull(store.getCode(), "PersistableMerchantStore.code must not be null");
// check if store code exists
MerchantStore storeForCheck = get(store.getCode());
if (storeForCheck != null) {
throw new ServiceRuntimeException("MerhantStore " + store.getCode() + " already exists");
}
MerchantStore mStore = convertPersistableMerchantStoreToMerchantStore(store, languageService.defaultLanguage());
createMerchantStore(mStore);
}
use of com.salesmanager.shop.model.store.PersistableMerchantStore 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.shop.model.store.PersistableMerchantStore in project shopizer by shopizer-ecommerce.
the class StoreFacadeImpl method update.
@Override
public void update(PersistableMerchantStore store) {
Validate.notNull(store);
MerchantStore mStore = mergePersistableMerchantStoreToMerchantStore(store, store.getCode(), languageService.defaultLanguage());
updateMerchantStore(mStore);
}
use of com.salesmanager.shop.model.store.PersistableMerchantStore in project shopizer by shopizer-ecommerce.
the class StoreFacadeImpl method convertPersistableMerchantStoreToMerchantStore.
private MerchantStore convertPersistableMerchantStoreToMerchantStore(PersistableMerchantStore store, Language language) {
MerchantStore mStore = new MerchantStore();
// set default values
mStore.setWeightunitcode(MeasureUnit.KG.name());
mStore.setSeizeunitcode(MeasureUnit.IN.name());
try {
mStore = persistableMerchantStorePopulator.populate(store, mStore, language);
} catch (ConversionException e) {
throw new ConversionRuntimeException(e);
}
return mStore;
}
use of com.salesmanager.shop.model.store.PersistableMerchantStore in project shopizer by shopizer-ecommerce.
the class StoreFacadeImpl method mergePersistableMerchantStoreToMerchantStore.
private MerchantStore mergePersistableMerchantStoreToMerchantStore(PersistableMerchantStore store, String code, Language language) {
MerchantStore mStore = getMerchantStoreByCode(code);
store.setId(mStore.getId());
try {
mStore = persistableMerchantStorePopulator.populate(store, mStore, language);
} catch (ConversionException e) {
throw new ConversionRuntimeException(e);
}
return mStore;
}
Aggregations