Search in sources :

Example 6 with ProductOptionSet

use of com.salesmanager.core.model.catalog.product.attribute.ProductOptionSet in project shopizer by shopizer-ecommerce.

the class ProductOptionSetFacadeImpl method exists.

@Override
public boolean exists(String code, MerchantStore store) {
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(code, "code cannot be null");
    ProductOptionSet optionSet = productOptionSetService.getCode(store, code);
    if (optionSet != null) {
        return true;
    }
    return false;
}
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)

Example 7 with ProductOptionSet

use of com.salesmanager.core.model.catalog.product.attribute.ProductOptionSet in project shopizer by shopizer-ecommerce.

the class ProductOptionSetFacadeImpl method get.

@Override
public ReadableProductOptionSet get(Long id, MerchantStore store, Language language) {
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(language, "Language cannot be null");
    ProductOptionSet optionSet = productOptionSetService.getById(store, id, language);
    if (optionSet == null) {
        throw new ResourceNotFoundException("ProductOptionSet not found for id [" + id + "] and store [" + store.getCode() + "]");
    }
    return readableProductOptionSetMapper.convert(optionSet, store, language);
}
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) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException)

Example 8 with ProductOptionSet

use of com.salesmanager.core.model.catalog.product.attribute.ProductOptionSet in project shopizer by shopizer-ecommerce.

the class ProductOptionSetFacadeImpl method list.

@Override
public List<ReadableProductOptionSet> list(MerchantStore store, Language language, String type) {
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(language, "Language cannot be null");
    Validate.notNull(type, "Product type cannot be null");
    // find product type by id
    ReadableProductType readable = productTypeFacade.get(store, type, language);
    if (readable == null) {
        throw new ResourceNotFoundException("Can't fing product type [" + type + "] fpr merchand [" + store.getCode() + "]");
    }
    List<ProductOptionSet> optionSets = productOptionSetService.getByProductType(readable.getId(), store, language);
    return optionSets.stream().map(opt -> this.convert(opt, store, language)).collect(Collectors.toList());
}
Also used : OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ProductOptionSetFacade(com.salesmanager.shop.store.controller.product.facade.ProductOptionSetFacade) ProductOptionSet(com.salesmanager.core.model.catalog.product.attribute.ProductOptionSet) ReadableProductType(com.salesmanager.shop.model.catalog.product.type.ReadableProductType) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) ProductOptionSetService(com.salesmanager.core.business.services.catalog.product.attribute.ProductOptionSetService) ServiceException(com.salesmanager.core.business.exception.ServiceException) Language(com.salesmanager.core.model.reference.language.Language) List(java.util.List) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) Validate(org.apache.commons.lang3.Validate) ReadableProductOptionSetMapper(com.salesmanager.shop.mapper.catalog.ReadableProductOptionSetMapper) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Service(org.springframework.stereotype.Service) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) PersistableProductOptionSet(com.salesmanager.shop.model.catalog.product.attribute.optionset.PersistableProductOptionSet) PersistableProductOptionSetMapper(com.salesmanager.shop.mapper.catalog.PersistableProductOptionSetMapper) ReadableProductOptionSet(com.salesmanager.shop.model.catalog.product.attribute.optionset.ReadableProductOptionSet) ProductTypeFacade(com.salesmanager.shop.store.controller.product.facade.ProductTypeFacade) 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) ReadableProductType(com.salesmanager.shop.model.catalog.product.type.ReadableProductType) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException)

Example 9 with ProductOptionSet

use of com.salesmanager.core.model.catalog.product.attribute.ProductOptionSet 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

ProductOptionSet (com.salesmanager.core.model.catalog.product.attribute.ProductOptionSet)9 PersistableProductOptionSet (com.salesmanager.shop.model.catalog.product.attribute.optionset.PersistableProductOptionSet)8 ReadableProductOptionSet (com.salesmanager.shop.model.catalog.product.attribute.optionset.ReadableProductOptionSet)7 ServiceException (com.salesmanager.core.business.exception.ServiceException)6 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)5 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)5 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)3 Language (com.salesmanager.core.model.reference.language.Language)3 OperationNotAllowedException (com.salesmanager.shop.store.api.exception.OperationNotAllowedException)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 Validate (org.apache.commons.lang3.Validate)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 ProductOptionSetService (com.salesmanager.core.business.services.catalog.product.attribute.ProductOptionSetService)2 ProductOptionValue (com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue)2 PersistableProductOptionSetMapper (com.salesmanager.shop.mapper.catalog.PersistableProductOptionSetMapper)2 ReadableProductOptionSetMapper (com.salesmanager.shop.mapper.catalog.ReadableProductOptionSetMapper)2 ReadableProductType (com.salesmanager.shop.model.catalog.product.type.ReadableProductType)2 ProductOptionSetFacade (com.salesmanager.shop.store.controller.product.facade.ProductOptionSetFacade)2 ProductTypeFacade (com.salesmanager.shop.store.controller.product.facade.ProductTypeFacade)2