Search in sources :

Example 1 with ReadableProductOptionEntity

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

the class ReadableProductAttributeMapper method merge.

@Override
public ReadableProductAttributeEntity merge(ProductAttribute source, ReadableProductAttributeEntity destination, MerchantStore store, Language language) {
    ReadableProductAttributeEntity attr = new ReadableProductAttributeEntity();
    if (destination != null) {
        attr = destination;
    }
    try {
        // attribute of the option
        attr.setId(source.getId());
        if (source.getProductAttributePrice() != null && source.getProductAttributePrice().doubleValue() > 0) {
            String formatedPrice;
            formatedPrice = pricingService.getDisplayAmount(source.getProductAttributePrice(), store);
            attr.setProductAttributePrice(formatedPrice);
            attr.setProductAttributeUnformattedPrice(pricingService.getStringAmount(source.getProductAttributePrice(), store));
        }
        attr.setProductAttributeWeight(source.getAttributeAdditionalWeight());
        attr.setAttributeDisplayOnly(source.getAttributeDisplayOnly());
        attr.setAttributeDefault(source.getAttributeDefault());
        if (!StringUtils.isBlank(source.getAttributeSortOrder())) {
            attr.setSortOrder(Integer.parseInt(source.getAttributeSortOrder()));
        }
        if (source.getProductOption() != null) {
            ReadableProductOptionEntity option = readableProductOptionMapper.convert(source.getProductOption(), store, language);
            attr.setOption(option);
        }
        if (source.getProductOptionValue() != null) {
            ReadableProductOptionValueEntity optionValue = readableProductOptionValueMapper.convert(source.getProductOptionValue(), store, language);
            attr.setOptionValue(optionValue);
        }
    } catch (Exception e) {
        throw new ConversionRuntimeException("Exception while product attribute conversion", e);
    }
    return attr;
}
Also used : ReadableProductOptionValueEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionValueEntity) ReadableProductAttributeEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductAttributeEntity) ReadableProductOptionEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionEntity) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException)

Example 2 with ReadableProductOptionEntity

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

the class ReadableProductOptionMapper method merge.

@Override
public ReadableProductOptionEntity merge(ProductOption source, ReadableProductOptionEntity destination, MerchantStore store, Language language) {
    ReadableProductOptionEntity readableProductOption = new ReadableProductOptionEntity();
    if (language == null) {
        readableProductOption = new ReadableProductOptionFull();
        List<com.salesmanager.shop.model.catalog.product.attribute.ProductOptionDescription> descriptions = new ArrayList<com.salesmanager.shop.model.catalog.product.attribute.ProductOptionDescription>();
        for (ProductOptionDescription desc : source.getDescriptions()) {
            com.salesmanager.shop.model.catalog.product.attribute.ProductOptionDescription d = this.description(desc);
            descriptions.add(d);
        }
        ((ReadableProductOptionFull) readableProductOption).setDescriptions(descriptions);
    } else {
        readableProductOption = new ReadableProductOptionEntity();
        if (!CollectionUtils.isEmpty(source.getDescriptions())) {
            for (ProductOptionDescription desc : source.getDescriptions()) {
                if (desc != null && desc.getLanguage() != null && desc.getLanguage().getId() == language.getId()) {
                    com.salesmanager.shop.model.catalog.product.attribute.ProductOptionDescription d = this.description(desc);
                    readableProductOption.setDescription(d);
                }
            }
        }
    }
    readableProductOption.setCode(source.getCode());
    readableProductOption.setId(source.getId());
    readableProductOption.setType(source.getProductOptionType());
    return readableProductOption;
}
Also used : ReadableProductOptionFull(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionFull) ArrayList(java.util.ArrayList) ProductOptionDescription(com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription) ReadableProductOptionEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionEntity)

Example 3 with ReadableProductOptionEntity

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

the class ProductOptionFacadeImpl method options.

@Override
public ReadableProductOptionList options(MerchantStore store, Language language, String name, int page, int count) {
    Validate.notNull(store, "MerchantStore should not be null");
    Page<ProductOption> options = productOptionService.getByMerchant(store, null, name, page, count);
    ReadableProductOptionList valueList = new ReadableProductOptionList();
    valueList.setTotalPages(options.getTotalPages());
    valueList.setRecordsTotal(options.getTotalElements());
    valueList.setNumber(options.getNumber());
    List<ReadableProductOptionEntity> values = options.getContent().stream().map(option -> readableMapper.convert(option, store, null)).collect(Collectors.toList());
    valueList.setOptions(values);
    return valueList;
}
Also used : ProductOption(com.salesmanager.core.model.catalog.product.attribute.ProductOption) 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) ReadableProductOptionList(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionList) ReadableProductOptionEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionEntity)

Example 4 with ReadableProductOptionEntity

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

the class ProductOptionFacadeImpl method saveOption.

@Override
public ReadableProductOptionEntity saveOption(PersistableProductOptionEntity option, MerchantStore store, Language language) {
    Validate.notNull(option, "ProductOption cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    ProductOption optionModel = new ProductOption();
    if (option.getId() != null && option.getId().longValue() > 0) {
        optionModel = productOptionService.getById(store, option.getId());
        if (optionModel == null) {
            throw new ResourceNotFoundException("ProductOption not found for if [" + option.getId() + "] and store [" + store.getCode() + "]");
        }
    }
    optionModel = persistableeMapper.merge(option, optionModel, store, language);
    try {
        productOptionService.saveOrUpdate(optionModel);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("An exception occured while saving ProductOption", e);
    }
    optionModel = productOptionService.getById(store, optionModel.getId());
    ReadableProductOptionEntity readable = readableMapper.convert(optionModel, store, language);
    return readable;
}
Also used : ProductOption(com.salesmanager.core.model.catalog.product.attribute.ProductOption) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ReadableProductOptionEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionEntity) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Aggregations

ReadableProductOptionEntity (com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionEntity)4 ServiceException (com.salesmanager.core.business.exception.ServiceException)2 ProductOption (com.salesmanager.core.model.catalog.product.attribute.ProductOption)2 ReadableProductAttributeEntity (com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductAttributeEntity)2 ReadableProductOptionValueEntity (com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionValueEntity)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 ProductAttribute (com.salesmanager.core.model.catalog.product.attribute.ProductAttribute)1 ProductOptionDescription (com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription)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