Search in sources :

Example 1 with PersistableProductOptionSet

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);
    }
}
Also used : ProductOptionSet(com.salesmanager.core.model.catalog.product.attribute.ProductOptionSet) PersistableProductOptionSet(com.salesmanager.shop.model.catalog.product.attribute.optionset.PersistableProductOptionSet) ReadableProductOptionSet(com.salesmanager.shop.model.catalog.product.attribute.optionset.ReadableProductOptionSet) ServiceException(com.salesmanager.core.business.exception.ServiceException) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 2 with PersistableProductOptionSet

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);
    }
}
Also used : ProductOptionSet(com.salesmanager.core.model.catalog.product.attribute.ProductOptionSet) PersistableProductOptionSet(com.salesmanager.shop.model.catalog.product.attribute.optionset.PersistableProductOptionSet) ReadableProductOptionSet(com.salesmanager.shop.model.catalog.product.attribute.optionset.ReadableProductOptionSet) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 3 with PersistableProductOptionSet

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;
}
Also used : ProductOption(com.salesmanager.core.model.catalog.product.attribute.ProductOption) Mapper(com.salesmanager.shop.mapper.Mapper) ProductOptionSet(com.salesmanager.core.model.catalog.product.attribute.ProductOptionSet) ProductOptionValue(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) ProductOptionValueService(com.salesmanager.core.business.services.catalog.product.attribute.ProductOptionValueService) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ServiceException(com.salesmanager.core.business.exception.ServiceException) HashSet(java.util.HashSet) Language(com.salesmanager.core.model.reference.language.Language) List(java.util.List) Component(org.springframework.stereotype.Component) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) Validate(org.apache.commons.lang3.Validate) ProductOption(com.salesmanager.core.model.catalog.product.attribute.ProductOption) PersistableProductOptionSet(com.salesmanager.shop.model.catalog.product.attribute.optionset.PersistableProductOptionSet) ProductType(com.salesmanager.core.model.catalog.product.type.ProductType) ProductOptionService(com.salesmanager.core.business.services.catalog.product.attribute.ProductOptionService) ProductTypeService(com.salesmanager.core.business.services.catalog.product.type.ProductTypeService) ProductOptionValue(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue) ServiceException(com.salesmanager.core.business.exception.ServiceException) ProductType(com.salesmanager.core.model.catalog.product.type.ProductType) HashSet(java.util.HashSet) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException)

Aggregations

ServiceException (com.salesmanager.core.business.exception.ServiceException)3 ProductOptionSet (com.salesmanager.core.model.catalog.product.attribute.ProductOptionSet)3 PersistableProductOptionSet (com.salesmanager.shop.model.catalog.product.attribute.optionset.PersistableProductOptionSet)3 ReadableProductOptionSet (com.salesmanager.shop.model.catalog.product.attribute.optionset.ReadableProductOptionSet)2 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)2 ProductOptionService (com.salesmanager.core.business.services.catalog.product.attribute.ProductOptionService)1 ProductOptionValueService (com.salesmanager.core.business.services.catalog.product.attribute.ProductOptionValueService)1 ProductTypeService (com.salesmanager.core.business.services.catalog.product.type.ProductTypeService)1 ProductOption (com.salesmanager.core.model.catalog.product.attribute.ProductOption)1 ProductOptionValue (com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue)1 ProductType (com.salesmanager.core.model.catalog.product.type.ProductType)1 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)1 Language (com.salesmanager.core.model.reference.language.Language)1 Mapper (com.salesmanager.shop.mapper.Mapper)1 ConversionRuntimeException (com.salesmanager.shop.store.api.exception.ConversionRuntimeException)1 OperationNotAllowedException (com.salesmanager.shop.store.api.exception.OperationNotAllowedException)1 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1