use of com.salesmanager.core.model.merchant.MerchantStore in project shopizer by shopizer-ecommerce.
the class ShopProductRESTController method getProducts.
private ReadableProductList getProducts(final int start, final int max, final String store, final String language, final String category, final List<QueryFilter> filters, HttpServletRequest request, HttpServletResponse response) throws Exception {
try {
/**
* How to Spring MVC Rest web service - ajax / jquery
* http://codetutr.com/2013/04/09/spring-mvc-easy-rest-based-json-services-with-responsebody/
*/
MerchantStore merchantStore = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
Map<String, Language> langs = languageService.getLanguagesMap();
if (merchantStore != null) {
if (!merchantStore.getCode().equals(store)) {
// reset for the current request
merchantStore = null;
}
}
if (merchantStore == null) {
merchantStore = merchantStoreService.getByCode(store);
}
if (merchantStore == null) {
LOGGER.error("Merchant store is null for code " + store);
// TODO localized message
response.sendError(503, "Merchant store is null for code " + store);
return null;
}
Language lang = langs.get(language);
if (lang == null) {
lang = langs.get(Constants.DEFAULT_LANGUAGE);
}
ProductCriteria productCriteria = new ProductCriteria();
productCriteria.setMaxCount(max);
productCriteria.setStartIndex(start);
// get the category by code
if (!StringUtils.isBlank(category)) {
Category cat = categoryService.getBySeUrl(merchantStore, category);
if (cat == null) {
LOGGER.error("Category " + category + " is null");
// TODO localized message
response.sendError(503, "Category is null");
return null;
}
String lineage = new StringBuilder().append(cat.getLineage()).append(cat.getId()).append("/").toString();
List<Category> categories = categoryService.getListByLineage(store, lineage);
List<Long> ids = new ArrayList<Long>();
if (categories != null && categories.size() > 0) {
for (Category c : categories) {
ids.add(c.getId());
}
}
ids.add(cat.getId());
productCriteria.setCategoryIds(ids);
}
if (filters != null) {
for (QueryFilter filter : filters) {
if (filter.getFilterType().name().equals(QueryFilterType.BRAND.name())) {
// the only filter implemented
productCriteria.setManufacturerId(filter.getFilterId());
}
}
}
com.salesmanager.core.model.catalog.product.ProductList products = productService.listByStore(merchantStore, lang, productCriteria);
ReadableProductPopulator populator = new ReadableProductPopulator();
populator.setPricingService(pricingService);
populator.setimageUtils(imageUtils);
ReadableProductList productList = new ReadableProductList();
for (Product product : products.getProducts()) {
// create new proxy product
ReadableProduct readProduct = populator.populate(product, new ReadableProduct(), merchantStore, lang);
productList.getProducts().add(readProduct);
}
productList.setTotalPages(Math.toIntExact(products.getTotalCount()));
return productList;
} catch (Exception e) {
LOGGER.error("Error while getting products", e);
response.sendError(503, "An error occured while retrieving products " + e.getMessage());
}
return null;
}
use of com.salesmanager.core.model.merchant.MerchantStore in project shopizer by shopizer-ecommerce.
the class PaymentApi method configure.
@PostMapping(value = "/private/modules/payment")
public void configure(@RequestBody IntegrationModuleConfiguration configuration, @ApiIgnore MerchantStore merchantStore) {
try {
List<IntegrationModule> modules = paymentService.getPaymentMethods(merchantStore);
Map<String, IntegrationModule> map = modules.stream().collect(Collectors.toMap(IntegrationModule::getCode, module -> module));
IntegrationModule config = map.get(configuration.getCode());
if (config == null) {
throw new ResourceNotFoundException("Payment module [" + configuration.getCode() + "] not found");
}
Map<String, IntegrationConfiguration> configuredModules = paymentService.getPaymentModulesConfigured(merchantStore);
IntegrationConfiguration integrationConfiguration = configuredModules.get(configuration.getCode());
if (integrationConfiguration == null) {
integrationConfiguration = new IntegrationConfiguration();
integrationConfiguration.setModuleCode(configuration.getCode());
}
integrationConfiguration.setActive(configuration.isActive());
integrationConfiguration.setDefaultSelected(configuration.isDefaultSelected());
integrationConfiguration.setIntegrationKeys(configuration.getIntegrationKeys());
integrationConfiguration.setIntegrationOptions(configuration.getIntegrationOptions());
paymentService.savePaymentModuleConfiguration(integrationConfiguration, merchantStore);
} catch (ServiceException e) {
LOGGER.error("Error getting payment modules", e);
throw new ServiceRuntimeException("Error saving payment module", e);
}
}
use of com.salesmanager.core.model.merchant.MerchantStore in project shopizer by shopizer-ecommerce.
the class ShippingConfigurationApi method shippingModule.
/**
* Get merchant shipping module details
*
* @param code
* @param merchantStore
* @param language
* @return
*/
@GetMapping("/private/modules/shipping/{code}")
@ApiOperation(httpMethod = "GET", value = "Shipping module by code", produces = "application/json", response = List.class)
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT") })
public IntegrationConfiguration shippingModule(@PathVariable String code, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) {
try {
// configured modules
List<IntegrationModule> modules = shippingService.getShippingMethods(merchantStore);
// check if exist
Optional<IntegrationModule> checkIfExist = modules.stream().filter(m -> m.getCode().equals(code)).findAny();
if (!checkIfExist.isPresent()) {
throw new ResourceNotFoundException("Shipping module [" + code + "] not found");
}
IntegrationConfiguration config = shippingService.getShippingConfiguration(code, merchantStore);
if (config == null) {
config = new IntegrationConfiguration();
}
/**
* Build return object for now this is a read copy
*/
config.setActive(config.isActive());
config.setDefaultSelected(config.isDefaultSelected());
config.setIntegrationKeys(config.getIntegrationKeys());
config.setIntegrationOptions(config.getIntegrationOptions());
return config;
} catch (ServiceException e) {
LOGGER.error("Error getting shipping module [" + code + "]", e);
throw new ServiceRuntimeException("Error getting shipping module [" + code + "]", e);
}
}
use of com.salesmanager.core.model.merchant.MerchantStore in project shopizer by shopizer-ecommerce.
the class StoreContactRESTController method contact.
@RequestMapping(value = "/public/{store}/contact", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.ACCEPTED)
@ResponseBody
public AjaxResponse contact(@PathVariable final String store, @Valid @RequestBody ContactForm contact, HttpServletRequest request, HttpServletResponse response) {
AjaxResponse ajaxResponse = new AjaxResponse();
try {
/**
* default routine *
*/
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;
}
Language language = merchantStore.getDefaultLanguage();
Map<String, Language> langs = languageService.getLanguagesMap();
if (!StringUtils.isBlank(request.getParameter(Constants.LANG))) {
String lang = request.getParameter(Constants.LANG);
if (lang != null) {
language = langs.get(language);
}
}
if (language == null) {
language = merchantStore.getDefaultLanguage();
}
Locale l = LocaleUtils.getLocale(language);
/**
* end default routine *
*/
emailTemplatesUtils.sendContactEmail(contact, merchantStore, l, request.getContextPath());
ajaxResponse.setStatus(AjaxResponse.RESPONSE_STATUS_SUCCESS);
return ajaxResponse;
} catch (Exception e) {
LOGGER.error("Error while saving category", e);
try {
response.sendError(503, "Error while saving category " + e.getMessage());
} catch (Exception ignore) {
}
return null;
}
}
use of com.salesmanager.core.model.merchant.MerchantStore in project shopizer by shopizer-ecommerce.
the class StoreContactRESTController method store.
@RequestMapping(value = "/public/{store}", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.ACCEPTED)
@ResponseBody
public AjaxResponse store(@PathVariable final String store, HttpServletRequest request, HttpServletResponse response) {
AjaxResponse ajaxResponse = new AjaxResponse();
try {
/**
* default routine *
*/
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;
}
Language language = merchantStore.getDefaultLanguage();
Map<String, Language> langs = languageService.getLanguagesMap();
return null;
} catch (Exception e) {
LOGGER.error("Error while saving category", e);
try {
response.sendError(503, "Error while saving category " + e.getMessage());
} catch (Exception ignore) {
}
return null;
}
}
Aggregations