use of com.salesmanager.shop.model.catalog.product.attribute.optionset.PersistableProductOptionSet in project shopizer by shopizer-ecommerce.
the class ProductOptionSetFacadeImpl method create.
@Override
public void create(PersistableProductOptionSet optionSet, MerchantStore store, Language language) {
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(language, "Language cannot be null");
Validate.notNull(optionSet, "PersistableProductOptionSet cannot be null");
if (this.exists(optionSet.getCode(), store)) {
throw new OperationNotAllowedException("Option set with code [" + optionSet.getCode() + "] already exist");
}
ProductOptionSet opt = persistableProductOptionSetMapper.convert(optionSet, store, language);
try {
opt.setStore(store);
productOptionSetService.create(opt);
} catch (ServiceException e) {
throw new ServiceRuntimeException("Exception while creating ProductOptionSet", e);
}
}
use of com.salesmanager.shop.model.catalog.product.attribute.optionset.PersistableProductOptionSet in project shopizer by shopizer-ecommerce.
the class ProductOptionSetFacadeImpl method update.
@Override
public void update(Long id, PersistableProductOptionSet optionSet, MerchantStore store, Language language) {
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(language, "Language cannot be null");
Validate.notNull(optionSet, "PersistableProductOptionSet cannot be null");
ProductOptionSet opt = productOptionSetService.getById(store, id, language);
if (opt == null) {
throw new ResourceNotFoundException("ProductOptionSet not found for id [" + id + "] and store [" + store.getCode() + "]");
}
optionSet.setId(id);
optionSet.setCode(opt.getCode());
ProductOptionSet model = persistableProductOptionSetMapper.convert(optionSet, store, language);
try {
model.setStore(store);
productOptionSetService.save(model);
} catch (ServiceException e) {
throw new ServiceRuntimeException("Exception while creating ProductOptionSet", e);
}
}
use of com.salesmanager.shop.model.catalog.product.attribute.optionset.PersistableProductOptionSet in project shopizer by shopizer-ecommerce.
the class PersistableProductOptionSetMapper method merge.
@Override
public ProductOptionSet merge(PersistableProductOptionSet source, ProductOptionSet destination, MerchantStore store, Language language) {
Validate.notNull(destination, "ProductOptionSet must not be null");
destination.setId(source.getId());
destination.setCode(source.getCode());
destination.setOptionDisplayOnly(source.isReadOnly());
ProductOption option = productOptionService.getById(store, source.getOption());
destination.setOption(option);
if (!CollectionUtils.isEmpty(source.getOptionValues())) {
List<ProductOptionValue> values = source.getOptionValues().stream().map(id -> value(id, store)).collect(Collectors.toList());
destination.setValues(values);
}
if (!CollectionUtils.isEmpty(source.getProductTypes())) {
try {
List<ProductType> types = productTypeService.listProductTypes(source.getProductTypes(), store, language);
Set<ProductType> typesSet = new HashSet<ProductType>(types);
destination.setProductTypes(typesSet);
} catch (ServiceException e) {
throw new ConversionRuntimeException("Error while mpping ProductOptionSet", e);
}
}
return destination;
}
Aggregations