use of com.salesmanager.core.model.merchant.MerchantStore in project shopizer by shopizer-ecommerce.
the class MerchantStoreArgumentResolver method resolveArgument.
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
String storeValue = Optional.ofNullable(webRequest.getParameter(REQUEST_PARAMATER_STORE)).filter(StringUtils::isNotBlank).orElse(DEFAULT_STORE);
// todo get from cache
MerchantStore storeModel = storeFacade.get(storeValue);
HttpServletRequest httpServletRequest = webRequest.getNativeRequest(HttpServletRequest.class);
// TODO Move to an api filter
// authorize request
boolean authorized = userFacade.authorizeStore(storeModel, httpServletRequest.getRequestURI());
LOGGER.debug("is request authorized {} for {} and store {}", authorized, httpServletRequest.getRequestURI(), storeModel.getCode());
if (!authorized) {
throw new UnauthorizedException("Cannot authorize user for store " + storeModel.getCode());
}
return storeModel;
}
use of com.salesmanager.core.model.merchant.MerchantStore in project shopizer by shopizer-ecommerce.
the class ProductFacadeV2Impl method getProductBySeUrl.
@Override
public ReadableProduct getProductBySeUrl(MerchantStore store, String friendlyUrl, Language language) throws Exception {
Product product = productService.getBySeUrl(store, friendlyUrl, LocaleUtils.getLocale(language));
if (product == null) {
throw new ResourceNotFoundException("Product [" + friendlyUrl + "] not found for merchant [" + store.getCode() + "]");
}
ReadableProduct readableProduct = readableProductMapper.convert(product, store, language);
// get all instances for this product group by option
// limit to 15 searches
List<ProductInstance> instances = productInstanceService.getByProductId(store, product, language);
// the above get all possible images
List<ReadableProductInstance> readableInstances = instances.stream().map(p -> this.productInstance(p, store, language)).collect(Collectors.toList());
readableProduct.setVariants(readableInstances);
return readableProduct;
}
use of com.salesmanager.core.model.merchant.MerchantStore in project shopizer by shopizer-ecommerce.
the class ProductFacadeV2Impl method getProductByCode.
@Override
public ReadableProduct getProductByCode(MerchantStore store, String uniqueCode, Language language) {
Product product = productService.getByCode(uniqueCode, language);
if (product == null) {
throw new ResourceNotFoundException("Product [" + uniqueCode + "] not found for merchant [" + store.getCode() + "]");
}
if (product.getMerchantStore().getId() != store.getId()) {
throw new ResourceNotFoundException("Product [" + uniqueCode + "] not found for merchant [" + store.getCode() + "]");
}
ReadableProduct readableProduct = readableProductMapper.convert(product, store, language);
// get all instances for this product group by option
// limit to 15 searches
List<ProductInstance> instances = productInstanceService.getByProductId(store, product, language);
// the above get all possible images
List<ReadableProductInstance> readableInstances = instances.stream().map(p -> this.productInstance(p, store, language)).collect(Collectors.toList());
readableProduct.setVariants(readableInstances);
return readableProduct;
}
use of com.salesmanager.core.model.merchant.MerchantStore in project shopizer by shopizer-ecommerce.
the class ProductInstanceFacadeImpl method list.
@Override
public ReadableEntityList<ReadableProductInstance> list(Long productId, MerchantStore store, Language language, int page, int count) {
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(productId, "Product id cannot be null");
Product product = productFacade.getProduct(productId, store);
if (product == null) {
throw new ResourceNotFoundException("Product with id [" + productId + "] not found for store [" + store.getCode() + "]");
}
Page<ProductInstance> instances = productInstanceService.getByProductId(store, product, language, page, count);
List<ReadableProductInstance> readableInstances = instances.stream().map(rp -> this.readableProductInstanceMapper.convert(rp, store, language)).collect(Collectors.toList());
return createReadableList(instances, readableInstances);
}
use of com.salesmanager.core.model.merchant.MerchantStore in project shopizer by shopizer-ecommerce.
the class TaxFacadeImpl method taxClasses.
@Override
public ReadableEntityList<ReadableTaxClass> taxClasses(MerchantStore store, Language language) {
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(store.getCode(), "MerchantStore code cannot be null");
try {
List<TaxClass> models = taxClassService.listByStore(store);
List<ReadableTaxClass> taxClasses = models.stream().map(t -> convertToReadableTaxClass(t, store, language)).collect(Collectors.toList());
ReadableEntityList<ReadableTaxClass> list = new ReadableEntityList<ReadableTaxClass>();
list.setItems(taxClasses);
list.setNumber(taxClasses.size());
list.setTotalPages(1);
list.setRecordsTotal(taxClasses.size());
return list;
} catch (ServiceException e) {
LOGGER.error("Error while getting taxClasses for store [" + store.getCode() + "]", e);
throw new ServiceRuntimeException("Error while getting taxClasses for store [" + store.getCode() + "]", e);
}
}
Aggregations