Search in sources :

Example 1 with PersistableProductAttribute

use of com.salesmanager.shop.model.catalog.product.attribute.PersistableProductAttribute in project shopizer by shopizer-ecommerce.

the class ProductOptionFacadeImpl method saveAttribute.

@Override
public ReadableProductAttributeEntity saveAttribute(Long productId, PersistableProductAttribute attribute, MerchantStore store, Language language) {
    Validate.notNull(productId, "Product id cannot be null");
    Validate.notNull(attribute, "ProductAttribute cannot be null");
    Validate.notNull(attribute.getOption(), "ProductAttribute option cannot be null");
    Validate.notNull(attribute.getOptionValue(), "ProductAttribute option value cannot be null");
    Validate.notNull(store, "Store cannot be null");
    attribute.setProductId(productId);
    ProductAttribute attr = new ProductAttribute();
    if (attribute.getId() != null && attribute.getId().longValue() > 0) {
        attr = productAttributeService.getById(attribute.getId());
        if (attr == null) {
            throw new ResourceNotFoundException("Product attribute [" + attribute.getId() + "] not found");
        }
        if (productId != attr.getProduct().getId().longValue()) {
            throw new ResourceNotFoundException("Product attribute [" + attribute.getId() + "] not found for product [" + productId + "]");
        }
    }
    attr = persistableProductAttributeMapper.merge(attribute, attr, store, language);
    try {
        productAttributeService.saveOrUpdate(attr);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Exception while saving ProductAttribute", e);
    }
    // refresh
    attr = productAttributeService.getById(attr.getId());
    ReadableProductAttributeEntity readable = readableProductAttributeMapper.convert(attr, store, language);
    return readable;
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) PersistableProductAttribute(com.salesmanager.shop.model.catalog.product.attribute.PersistableProductAttribute) ReadableProductAttributeEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductAttributeEntity) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 2 with PersistableProductAttribute

use of com.salesmanager.shop.model.catalog.product.attribute.PersistableProductAttribute 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());
}
Also used : NotImplementedException(org.apache.commons.lang3.NotImplementedException) ProductService(com.salesmanager.core.business.services.catalog.product.ProductService) ReadableProductAttributeList(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductAttributeList) ReadableProductOptionValueEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionValueEntity) Autowired(org.springframework.beans.factory.annotation.Autowired) ProductOptionValueService(com.salesmanager.core.business.services.catalog.product.attribute.ProductOptionValueService) ServiceException(com.salesmanager.core.business.exception.ServiceException) Language(com.salesmanager.core.model.reference.language.Language) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ReadableProductOptionList(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionList) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Service(org.springframework.stereotype.Service) ReadableProductAttributeMapper(com.salesmanager.shop.mapper.catalog.ReadableProductAttributeMapper) ProductOption(com.salesmanager.core.model.catalog.product.attribute.ProductOption) FileContentType(com.salesmanager.core.model.content.FileContentType) ProductAttributeService(com.salesmanager.core.business.services.catalog.product.attribute.ProductAttributeService) PersistableProductAttributeMapper(com.salesmanager.shop.mapper.catalog.PersistableProductAttributeMapper) ProductOptionFacade(com.salesmanager.shop.store.controller.product.facade.ProductOptionFacade) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) Validate(org.jsoup.helper.Validate) Product(com.salesmanager.core.model.catalog.product.Product) ReadableProductOptionMapper(com.salesmanager.shop.mapper.catalog.ReadableProductOptionMapper) ProductOptionValue(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue) PersistableProductOptionEntity(com.salesmanager.shop.model.catalog.product.attribute.api.PersistableProductOptionEntity) CodeEntity(com.salesmanager.shop.model.entity.CodeEntity) PersistableProductAttribute(com.salesmanager.shop.model.catalog.product.attribute.PersistableProductAttribute) PersistableProductOptionValue(com.salesmanager.shop.model.catalog.product.attribute.PersistableProductOptionValue) Page(org.springframework.data.domain.Page) InputContentFile(com.salesmanager.core.model.content.InputContentFile) Collectors(java.util.stream.Collectors) ContentService(com.salesmanager.core.business.services.content.ContentService) ReadableProductOptionValueList(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionValueList) List(java.util.List) PersistableProductOptionMapper(com.salesmanager.shop.mapper.catalog.PersistableProductOptionMapper) ReadableProductOptionValueMapper(com.salesmanager.shop.mapper.catalog.ReadableProductOptionValueMapper) ReadableProductAttributeEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductAttributeEntity) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) MultipartFile(org.springframework.web.multipart.MultipartFile) ProductOptionService(com.salesmanager.core.business.services.catalog.product.attribute.ProductOptionService) PersistableProductOptionValueMapper(com.salesmanager.shop.mapper.catalog.PersistableProductOptionValueMapper) ReadableProductOptionEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionEntity) InputStream(java.io.InputStream) ServiceException(com.salesmanager.core.business.exception.ServiceException) Product(com.salesmanager.core.model.catalog.product.Product) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) PersistableProductAttribute(com.salesmanager.shop.model.catalog.product.attribute.PersistableProductAttribute) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Aggregations

ServiceException (com.salesmanager.core.business.exception.ServiceException)2 ProductAttribute (com.salesmanager.core.model.catalog.product.attribute.ProductAttribute)2 PersistableProductAttribute (com.salesmanager.shop.model.catalog.product.attribute.PersistableProductAttribute)2 ReadableProductAttributeEntity (com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductAttributeEntity)2 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)2 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)2 ProductService (com.salesmanager.core.business.services.catalog.product.ProductService)1 ProductAttributeService (com.salesmanager.core.business.services.catalog.product.attribute.ProductAttributeService)1 ProductOptionService (com.salesmanager.core.business.services.catalog.product.attribute.ProductOptionService)1 ProductOptionValueService (com.salesmanager.core.business.services.catalog.product.attribute.ProductOptionValueService)1 ContentService (com.salesmanager.core.business.services.content.ContentService)1 Product (com.salesmanager.core.model.catalog.product.Product)1 ProductOption (com.salesmanager.core.model.catalog.product.attribute.ProductOption)1 ProductOptionValue (com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue)1 FileContentType (com.salesmanager.core.model.content.FileContentType)1 InputContentFile (com.salesmanager.core.model.content.InputContentFile)1 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)1 Language (com.salesmanager.core.model.reference.language.Language)1 PersistableProductAttributeMapper (com.salesmanager.shop.mapper.catalog.PersistableProductAttributeMapper)1 PersistableProductOptionMapper (com.salesmanager.shop.mapper.catalog.PersistableProductOptionMapper)1