Search in sources :

Example 6 with ProductOptionValue

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

the class PersistableProductVariationMapper method merge.

@Override
public ProductVariation merge(PersistableProductVariation source, ProductVariation destination, MerchantStore store, Language language) {
    Validate.notNull(destination, "ProductVariation cannot be null");
    destination.setId(source.getId());
    destination.setCode(source.getCode());
    destination.setMerchantStore(store);
    ProductOption option = productOptionService.getById(store, source.getOption());
    if (option == null) {
        throw new ConversionRuntimeException("ProductOption [" + source.getOption() + "] does not exists");
    }
    destination.setProductOption(option);
    ProductOptionValue optionValue = productOptionValueService.getById(store, source.getOptionValue());
    if (optionValue == null) {
        throw new ConversionRuntimeException("ProductOptionValue [" + source.getOptionValue() + "] does not exists");
    }
    destination.setProductOptionValue(optionValue);
    return destination;
}
Also used : ProductOption(com.salesmanager.core.model.catalog.product.attribute.ProductOption) ProductOptionValue(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException)

Example 7 with ProductOptionValue

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

the class ProductOptionValueServiceImpl method delete.

public void delete(ProductOptionValue entity) throws ServiceException {
    // remove all attributes having this option
    List<ProductAttribute> attributes = productAttributeService.getByOptionValueId(entity.getMerchantStore(), entity.getId());
    for (ProductAttribute attribute : attributes) {
        productAttributeService.delete(attribute);
    }
    ProductOptionValue option = getById(entity.getId());
    // remove option
    super.delete(option);
}
Also used : ProductOptionValue(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute)

Example 8 with ProductOptionValue

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

the class ProductOptionFacadeImpl method optionValues.

@Override
public ReadableProductOptionValueList optionValues(MerchantStore store, Language language, String name, int page, int count) {
    Validate.notNull(store, "MerchantStore should not be null");
    Page<ProductOptionValue> options = productOptionValueService.getByMerchant(store, null, name, page, count);
    ReadableProductOptionValueList valueList = new ReadableProductOptionValueList();
    valueList.setTotalPages(options.getTotalPages());
    valueList.setRecordsTotal(options.getTotalElements());
    valueList.setNumber(options.getNumber());
    List<ReadableProductOptionValueEntity> values = options.getContent().stream().map(option -> readableOptionValueMapper.convert(option, store, null)).collect(Collectors.toList());
    valueList.setOptionValues(values);
    return valueList;
}
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) ProductOptionValue(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue) PersistableProductOptionValue(com.salesmanager.shop.model.catalog.product.attribute.PersistableProductOptionValue) ReadableProductOptionValueEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionValueEntity) ReadableProductOptionValueList(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionValueList)

Example 9 with ProductOptionValue

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

the class ProductOptionFacadeImpl method optionValueExists.

@Override
public boolean optionValueExists(String code, MerchantStore store) {
    Validate.notNull(code, "Option value code must not be null");
    Validate.notNull(store, "Store code must not be null");
    boolean exists = false;
    ProductOptionValue optionValue = productOptionValueService.getByCode(store, code);
    if (optionValue != null) {
        exists = true;
    }
    return exists;
}
Also used : ProductOptionValue(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue) PersistableProductOptionValue(com.salesmanager.shop.model.catalog.product.attribute.PersistableProductOptionValue)

Example 10 with ProductOptionValue

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

the class ProductOptionFacadeImpl method addOptionValueImage.

@Override
public void addOptionValueImage(MultipartFile image, Long optionValueId, MerchantStore store, Language language) {
    Validate.notNull(optionValueId, "OptionValueId must not be null");
    Validate.notNull(image, "Image must not be null");
    // get option value
    ProductOptionValue value = productOptionValueService.getById(store, optionValueId);
    if (value == null) {
        throw new ResourceNotFoundException("Product option value [" + optionValueId + "] not found");
    }
    try {
        String imageName = image.getOriginalFilename();
        InputStream inputStream = image.getInputStream();
        InputContentFile cmsContentImage = new InputContentFile();
        cmsContentImage.setFileName(imageName);
        cmsContentImage.setMimeType(image.getContentType());
        cmsContentImage.setFile(inputStream);
        contentService.addOptionImage(store.getCode(), cmsContentImage);
        value.setProductOptionValueImage(imageName);
        productOptionValueService.saveOrUpdate(value);
    } catch (Exception e) {
        throw new ServiceRuntimeException("Exception while adding option value image", e);
    }
    return;
}
Also used : ProductOptionValue(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue) PersistableProductOptionValue(com.salesmanager.shop.model.catalog.product.attribute.PersistableProductOptionValue) InputContentFile(com.salesmanager.core.model.content.InputContentFile) InputStream(java.io.InputStream) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Aggregations

ProductOptionValue (com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue)21 ProductAttribute (com.salesmanager.core.model.catalog.product.attribute.ProductAttribute)10 ProductOption (com.salesmanager.core.model.catalog.product.attribute.ProductOption)10 ProductOptionValueDescription (com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription)10 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)9 Language (com.salesmanager.core.model.reference.language.Language)9 ProductOptionDescription (com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription)8 PersistableProductOptionValue (com.salesmanager.shop.model.catalog.product.attribute.PersistableProductOptionValue)8 Product (com.salesmanager.core.model.catalog.product.Product)7 ServiceException (com.salesmanager.core.business.exception.ServiceException)6 ConversionRuntimeException (com.salesmanager.shop.store.api.exception.ConversionRuntimeException)5 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)5 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Category (com.salesmanager.core.model.catalog.category.Category)4 ProductAvailability (com.salesmanager.core.model.catalog.product.availability.ProductAvailability)4 ProductDescription (com.salesmanager.core.model.catalog.product.description.ProductDescription)4 ProductPrice (com.salesmanager.core.model.catalog.product.price.ProductPrice)4 ProductPriceDescription (com.salesmanager.core.model.catalog.product.price.ProductPriceDescription)4