use of com.salesmanager.core.model.merchant.MerchantStore 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.core.model.merchant.MerchantStore in project shopizer by shopizer-ecommerce.
the class CatalogFacadeImpl method listCatalogEntry.
@Override
public ReadableEntityList<ReadableCatalogCategoryEntry> listCatalogEntry(Optional<String> product, Long id, MerchantStore store, Language language, int page, int count) {
Validate.notNull(store, "MerchantStore cannot be null");
String productCode = product.orElse(null);
Catalog catalog = catalogService.getById(id, store).orElseThrow(() -> new ResourceNotFoundException("Catalog with id [" + id + "] not found for store [" + store.getCode() + "]"));
Page<CatalogCategoryEntry> entries = catalogEntryService.list(catalog, store, language, productCode, page, count);
if (entries.isEmpty()) {
return new ReadableEntityList<>();
}
List<ReadableCatalogCategoryEntry> readableList = entries.getContent().stream().map(cat -> readableCatalogEntryMapper.convert(cat, store, language)).collect(Collectors.toList());
return createReadableList(entries, readableList);
}
use of com.salesmanager.core.model.merchant.MerchantStore in project shopizer by shopizer-ecommerce.
the class MerchantStoreServiceImpl method isStoreInGroup.
@Override
public boolean isStoreInGroup(String code) throws ServiceException {
// if exist
MerchantStore store = getByCode(code);
Optional<Integer> id = Optional.ofNullable(store.getId());
List<MerchantStore> stores = merchantRepository.listByGroup(code, id.get());
return stores.size() > 0;
}
use of com.salesmanager.core.model.merchant.MerchantStore 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.merchant.MerchantStore in project shopizer by shopizer-ecommerce.
the class OrderRESTController method listOrders.
/**
* Get a list of orders for a given customer
* accept request parameter 'lang' [en,fr...] otherwise store dafault language
* accept request parameter 'start' start index for count
* accept request parameter 'max' maximum number count, otherwise returns all
* @param store
* @param order
* @param request
* @param response
* @return
* @throws Exception
*/
@RequestMapping(value = "/{store}/orders/customer/{id}", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.ACCEPTED)
@ResponseBody
public ReadableOrderList listOrders(@PathVariable final String store, @PathVariable final Long id, HttpServletRequest request, HttpServletResponse response) throws Exception {
MerchantStore merchantStore = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
if (merchantStore != null) {
if (!merchantStore.getCode().equals(store)) {
merchantStore = null;
}
}
if (merchantStore == null) {
merchantStore = merchantStoreService.getByCode(store);
}
if (merchantStore == null) {
LOGGER.error("Merchant store is null for code " + store);
response.sendError(503, "Merchant store is null for code " + store);
return null;
}
// get additional request parameters for orders
String lang = request.getParameter(Constants.LANG);
String start = request.getParameter(Constants.START);
String max = request.getParameter(Constants.MAX);
int startCount = 0;
int maxCount = 0;
if (StringUtils.isBlank(lang)) {
lang = merchantStore.getDefaultLanguage().getCode();
}
Language language = languageService.getByCode(lang);
if (language == null) {
LOGGER.error("Language is null for code " + lang);
response.sendError(503, "Language is null for code " + lang);
return null;
}
try {
startCount = Integer.parseInt(start);
} catch (Exception e) {
LOGGER.info("Invalid value for start " + start);
}
try {
maxCount = Integer.parseInt(max);
} catch (Exception e) {
LOGGER.info("Invalid value for max " + max);
}
Customer customer = customerService.getById(id);
if (customer == null) {
LOGGER.error("Customer is null for id " + id);
response.sendError(503, "Customer is null for id " + id);
return null;
}
if (customer.getMerchantStore().getId().intValue() != merchantStore.getId().intValue()) {
LOGGER.error("Customer is null for id " + id + " and store id " + store);
response.sendError(503, "Customer is null for id " + id + " and store id " + store);
return null;
}
ReadableOrderList returnList = orderFacade.getReadableOrderList(merchantStore, startCount, maxCount, language);
return returnList;
}
Aggregations