use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class ProductFacadeImpl method getProduct.
@Override
public ReadableProduct getProduct(MerchantStore store, Long id, Language language) throws Exception {
Product product = productService.findOne(id, store);
if (product == null) {
throw new ResourceNotFoundException("Product [" + id + "] not found");
}
if (product.getMerchantStore().getId() != store.getId()) {
throw new ResourceNotFoundException("Product [" + id + "] not found for store [" + store.getId() + "]");
}
ReadableProduct readableProduct = new ReadableProduct();
ReadableProductPopulator populator = new ReadableProductPopulator();
populator.setPricingService(pricingService);
populator.setimageUtils(imageUtils);
readableProduct = populator.populate(product, readableProduct, store, language);
return readableProduct;
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class ProductFacadeImpl method deleteProduct.
@Override
public void deleteProduct(Long id, MerchantStore store) {
Validate.notNull(id, "Product id cannot be null");
Validate.notNull(store, "store cannot be null");
Product p = productService.getById(id);
if (p == null) {
throw new ResourceNotFoundException("Product with id [" + id + " not found");
}
if (p.getMerchantStore().getId().intValue() != store.getId().intValue()) {
throw new ResourceNotFoundException("Product with id [" + id + " not found for store [" + store.getCode() + "]");
}
try {
productService.delete(p);
} catch (ServiceException e) {
throw new ServiceRuntimeException("Error while deleting ptoduct with id [" + id + "]", e);
}
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException 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.shop.store.api.exception.ResourceNotFoundException 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.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class ProductInstanceFacadeImpl method get.
@Override
public ReadableProductInstance get(Long instanceId, Long productId, MerchantStore store, Language language) {
Optional<ProductInstance> productInstance = this.getProductInstance(instanceId, productId, store);
if (productInstance.isEmpty()) {
throw new ResourceNotFoundException("Product instance + [" + instanceId + "] not found for store [" + store.getCode() + "]");
}
ProductInstance model = productInstance.get();
return readableProductInstanceMapper.convert(model, store, language);
}
Aggregations