use of com.salesmanager.core.model.catalog.product.instance.ProductInstance 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.catalog.product.instance.ProductInstance 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.catalog.product.instance.ProductInstance 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);
}
use of com.salesmanager.core.model.catalog.product.instance.ProductInstance 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.catalog.product.instance.ProductInstance in project shopizer by shopizer-ecommerce.
the class ProductInstanceFacadeImpl method update.
@Override
public void update(Long instanceId, PersistableProductInstance productInstance, Long productId, MerchantStore store, Language language) {
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(productInstance, "ProductInstance cannot be null");
Validate.notNull(productId, "Product id cannot be null");
Validate.notNull(instanceId, "Product instance id cannot be null");
Optional<ProductInstance> instanceModel = this.getProductInstance(instanceId, productId, store);
if (instanceModel.isEmpty()) {
throw new ResourceNotFoundException("ProductInstance with id [" + instanceId + "] not found for store [" + store.getCode() + "] and productId [" + productId + "]");
}
ProductInstance mergedModel = persistableProductInstanceMapper.merge(productInstance, instanceModel.get(), store, language);
try {
productInstanceService.save(mergedModel);
} catch (ServiceException e) {
throw new ServiceRuntimeException("Cannot save product instance for store [" + store.getCode() + "] and productId [" + productId + "]", e);
}
}
Aggregations