use of com.salesmanager.shop.model.catalog.product.product.instance.PersistableProductInstance 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);
}
}
use of com.salesmanager.shop.model.catalog.product.product.instance.PersistableProductInstance in project shopizer by shopizer-ecommerce.
the class ProductInstanceFacadeImpl method create.
@Override
public Long create(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");
// variation and variation value should not be of same product option code
if (productInstance.getVariant() != null && productInstance.getVariant().longValue() > 0 && productInstance.getVariantValue() != null && productInstance.getVariantValue().longValue() > 0) {
List<ProductVariation> variations = productVariationService.getByIds(Arrays.asList(productInstance.getVariant(), productInstance.getVariantValue()), store);
boolean differentOption = variations.stream().map(i -> i.getProductOption().getCode()).distinct().count() > 1;
if (!differentOption) {
throw new ConstraintException("Product option of instance.variant and instance.variantValue must be different");
}
}
productInstance.setProductId(productId);
productInstance.setId(null);
ProductInstance instance = persistableProductInstanceMapper.convert(productInstance, store, language);
try {
productInstanceService.save(instance);
} catch (ServiceException e) {
throw new ServiceRuntimeException("Cannot save product instance for store [" + store.getCode() + "] and productId [" + productId + "]", e);
}
return instance.getId();
}
Aggregations