Search in sources :

Example 1 with ReadableProductAttributeEntity

use of com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductAttributeEntity 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 ReadableProductAttributeEntity

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

the class ProductOptionFacadeImpl method getAttribute.

@Override
public ReadableProductAttributeEntity getAttribute(Long productId, Long attributeId, MerchantStore store, Language language) {
    ProductAttribute attr = productAttributeService.getById(attributeId);
    if (attr == null) {
        throw new ResourceNotFoundException("ProductAttribute not found for [" + attributeId + "] and store [" + store.getCode() + "]");
    }
    if (attr.getProduct().getId().longValue() != productId) {
        throw new ResourceNotFoundException("ProductAttribute not found for [" + attributeId + "] and product [" + productId + "]");
    }
    if (attr.getProduct().getMerchantStore().getId().intValue() != store.getId().intValue()) {
        throw new ResourceNotFoundException("ProductAttribute not found for [" + attributeId + "] and product [" + productId + "] and store [" + store.getCode() + "]");
    }
    ReadableProductAttributeEntity readable = readableProductAttributeMapper.convert(attr, store, language);
    return readable;
}
Also used : 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)

Example 3 with ReadableProductAttributeEntity

use of com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductAttributeEntity 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 4 with ReadableProductAttributeEntity

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

the class ProductAttributeOptionApi method createAttribute.

@ResponseStatus(HttpStatus.CREATED)
@RequestMapping(value = { "/private/product/{id}/attribute" }, method = RequestMethod.POST)
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
@ResponseBody
public Entity createAttribute(@PathVariable Long id, @Valid @RequestBody PersistableProductAttribute attribute, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request, HttpServletResponse response) {
    ReadableProductAttributeEntity attributeEntity = productOptionFacade.saveAttribute(id, attribute, merchantStore, language);
    Entity entity = new Entity();
    entity.setId(attributeEntity.getId());
    return entity;
}
Also used : ReadableProductOptionValueEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionValueEntity) Entity(com.salesmanager.shop.model.entity.Entity) PersistableProductOptionEntity(com.salesmanager.shop.model.catalog.product.attribute.api.PersistableProductOptionEntity) CodeEntity(com.salesmanager.shop.model.entity.CodeEntity) ReadableProductAttributeEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductAttributeEntity) ResponseEntity(org.springframework.http.ResponseEntity) ReadableProductOptionEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionEntity) ReadableProductAttributeEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductAttributeEntity) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 with ReadableProductAttributeEntity

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

the class ProductOptionFacadeImpl method getAttributesList.

@Override
public ReadableProductAttributeList getAttributesList(Long productId, MerchantStore store, Language language, int page, int count) {
    try {
        Product product = this.product(productId, store);
        ReadableProductAttributeList attrList = new ReadableProductAttributeList();
        Page<ProductAttribute> attr = null;
        if (language != null) {
            // all entry
            // attributes = productAttributeService.getByProductId(store, product, language);
            attr = productAttributeService.getByProductId(store, product, language, page, count);
            attrList.setRecordsTotal(attr.getTotalElements());
            attrList.setNumber(attr.getSize());
            attrList.setTotalPages(attr.getTotalPages());
        } else {
            attr = productAttributeService.getByProductId(store, product, page, count);
            attrList.setRecordsTotal(attr.getTotalElements());
            attrList.setNumber(attr.getSize());
            attrList.setTotalPages(attr.getTotalPages());
        }
        List<ReadableProductAttributeEntity> values = attr.getContent().stream().map(attribute -> readableProductAttributeMapper.convert(attribute, store, language)).collect(Collectors.toList());
        attrList.setAttributes(values);
        return attrList;
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Error while getting attributes", e);
    }
}
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) ReadableProductAttributeList(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductAttributeList) 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) ReadableProductAttributeEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductAttributeEntity) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Aggregations

ReadableProductAttributeEntity (com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductAttributeEntity)6 ProductAttribute (com.salesmanager.core.model.catalog.product.attribute.ProductAttribute)4 PersistableProductAttribute (com.salesmanager.shop.model.catalog.product.attribute.PersistableProductAttribute)4 ReadableProductOptionEntity (com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionEntity)4 ReadableProductOptionValueEntity (com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionValueEntity)4 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)4 ServiceException (com.salesmanager.core.business.exception.ServiceException)3 PersistableProductOptionEntity (com.salesmanager.shop.model.catalog.product.attribute.api.PersistableProductOptionEntity)3 CodeEntity (com.salesmanager.shop.model.entity.CodeEntity)3 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)3 ProductService (com.salesmanager.core.business.services.catalog.product.ProductService)2 ProductAttributeService (com.salesmanager.core.business.services.catalog.product.attribute.ProductAttributeService)2 ProductOptionService (com.salesmanager.core.business.services.catalog.product.attribute.ProductOptionService)2 ProductOptionValueService (com.salesmanager.core.business.services.catalog.product.attribute.ProductOptionValueService)2 ContentService (com.salesmanager.core.business.services.content.ContentService)2 Product (com.salesmanager.core.model.catalog.product.Product)2 ProductOption (com.salesmanager.core.model.catalog.product.attribute.ProductOption)2 ProductOptionValue (com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue)2 FileContentType (com.salesmanager.core.model.content.FileContentType)2 InputContentFile (com.salesmanager.core.model.content.InputContentFile)2