use of com.salesmanager.shop.model.entity.CodeEntity in project shopizer by shopizer-ecommerce.
the class ProductOptionFacadeImpl method codeEntity.
private CodeEntity codeEntity(ProductAttribute attr) {
CodeEntity entity = new CodeEntity();
entity.setId(attr.getId());
entity.setCode(attr.getProductOption().getCode());
return entity;
}
use of com.salesmanager.shop.model.entity.CodeEntity in project shopizer by shopizer-ecommerce.
the class ProductOptionFacadeImpl method createAttributes.
@Override
public List<CodeEntity> createAttributes(List<PersistableProductAttribute> attributes, Long productId, MerchantStore store) {
Validate.notNull(productId, "Product id must not be null");
Validate.notNull(store, "Merchant cannot be null");
// convert to model
List<ProductAttribute> modelAttributes = attributes.stream().map(attr -> persistableProductAttributeMapper.convert(attr, store, null)).collect(Collectors.toList());
try {
productAttributeService.saveAll(modelAttributes);
// save to a product
Product product = this.product(productId, store);
product.getAttributes().addAll(modelAttributes);
productService.save(product);
} catch (ServiceException e) {
throw new ServiceRuntimeException("Exception while saving product with attributes", e);
}
return modelAttributes.stream().map(e -> codeEntity(e)).collect(Collectors.toList());
}
Aggregations