Search in sources :

Example 1 with ReadableImage

use of com.salesmanager.shop.model.catalog.product.ReadableImage in project shopizer by shopizer-ecommerce.

the class ReadableProductDefinitionMapper method merge.

@Override
public ReadableProductDefinition merge(Product source, ReadableProductDefinition destination, MerchantStore store, Language language) {
    Validate.notNull(source, "Product cannot be null");
    Validate.notNull(destination, "Product destination cannot be null");
    ReadableProductDefinition returnDestination = destination;
    if (language == null) {
        returnDestination = new ReadableProductDefinitionFull();
    }
    List<com.salesmanager.shop.model.catalog.product.ProductDescription> fulldescriptions = new ArrayList<com.salesmanager.shop.model.catalog.product.ProductDescription>();
    returnDestination.setIdentifier(source.getSku());
    returnDestination.setId(source.getId());
    returnDestination.setVisible(source.isAvailable());
    returnDestination.setDateAvailable(DateUtil.formatDate(source.getDateAvailable()));
    ProductDescription description = null;
    if (source.getDescriptions() != null && source.getDescriptions().size() > 0) {
        for (ProductDescription desc : source.getDescriptions()) {
            if (language != null && desc.getLanguage() != null && desc.getLanguage().getId().intValue() == language.getId().intValue()) {
                description = desc;
                break;
            } else {
                fulldescriptions.add(populateDescription(desc));
            }
        }
    }
    if (description != null) {
        com.salesmanager.shop.model.catalog.product.ProductDescription tragetDescription = populateDescription(description);
        returnDestination.setDescription(tragetDescription);
    }
    if (source.getManufacturer() != null) {
        ReadableManufacturer manufacturer = readableManufacturerMapper.convert(source.getManufacturer(), store, language);
        returnDestination.setManufacturer(manufacturer);
    }
    if (!CollectionUtils.isEmpty(source.getCategories())) {
        List<ReadableCategory> categoryList = new ArrayList<ReadableCategory>();
        for (Category category : source.getCategories()) {
            ReadableCategory readableCategory = readableCategoryMapper.convert(category, store, language);
            categoryList.add(readableCategory);
        }
        returnDestination.setCategories(categoryList);
    }
    ProductSpecification specifications = new ProductSpecification();
    specifications.setHeight(source.getProductHeight());
    specifications.setLength(source.getProductLength());
    specifications.setWeight(source.getProductWeight());
    specifications.setWidth(source.getProductWidth());
    if (!StringUtils.isBlank(store.getSeizeunitcode())) {
        specifications.setDimensionUnitOfMeasure(DimensionUnitOfMeasure.valueOf(store.getSeizeunitcode().toLowerCase()));
    }
    if (!StringUtils.isBlank(store.getWeightunitcode())) {
        specifications.setWeightUnitOfMeasure(WeightUnitOfMeasure.valueOf(store.getWeightunitcode().toLowerCase()));
    }
    returnDestination.setProductSpecifications(specifications);
    if (source.getType() != null) {
        ReadableProductType readableType = readableProductTypeMapper.convert(source.getType(), store, language);
        returnDestination.setType(readableType);
    }
    returnDestination.setSortOrder(source.getSortOrder());
    // images
    Set<ProductImage> images = source.getImages();
    if (CollectionUtils.isNotEmpty(images)) {
        List<ReadableImage> imageList = images.stream().map(i -> this.convertImage(source, i, store)).collect(Collectors.toList());
        returnDestination.setImages(imageList);
    }
    // quantity
    ProductAvailability availability = null;
    for (ProductAvailability a : source.getAvailabilities()) {
        availability = a;
        returnDestination.setCanBePurchased(availability.getProductStatus());
        returnDestination.setQuantity(availability.getProductQuantity() == null ? 1 : availability.getProductQuantity());
    }
    FinalPrice price = null;
    try {
        price = pricingService.calculateProductPrice(source);
    } catch (ServiceException e) {
        throw new ConversionRuntimeException("Unable to get product price", e);
    }
    if (price != null) {
        returnDestination.setPrice(price.getStringPrice());
    }
    if (returnDestination instanceof ReadableProductDefinitionFull) {
        ((ReadableProductDefinitionFull) returnDestination).setDescriptions(fulldescriptions);
    }
    return returnDestination;
}
Also used : DateUtil(com.salesmanager.shop.utils.DateUtil) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) ServiceException(com.salesmanager.core.business.exception.ServiceException) Language(com.salesmanager.core.model.reference.language.Language) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) FinalPrice(com.salesmanager.core.model.catalog.product.price.FinalPrice) ReadableImage(com.salesmanager.shop.model.catalog.product.ReadableImage) ReadableProductDefinition(com.salesmanager.shop.model.catalog.product.product.definition.ReadableProductDefinition) DimensionUnitOfMeasure(com.salesmanager.shop.model.references.DimensionUnitOfMeasure) Qualifier(org.springframework.beans.factory.annotation.Qualifier) PricingService(com.salesmanager.core.business.services.catalog.product.PricingService) ReadableProductDefinitionFull(com.salesmanager.shop.model.catalog.product.product.definition.ReadableProductDefinitionFull) Mapper(com.salesmanager.shop.mapper.Mapper) Product(com.salesmanager.core.model.catalog.product.Product) ReadableProductType(com.salesmanager.shop.model.catalog.product.type.ReadableProductType) Set(java.util.Set) ImageFilePath(com.salesmanager.shop.utils.ImageFilePath) Collectors(java.util.stream.Collectors) Category(com.salesmanager.core.model.catalog.category.Category) ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) List(java.util.List) Component(org.springframework.stereotype.Component) Validate(org.apache.commons.lang3.Validate) ProductImage(com.salesmanager.core.model.catalog.product.image.ProductImage) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) ProductSpecification(com.salesmanager.shop.model.catalog.product.ProductSpecification) ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) ProductDescription(com.salesmanager.core.model.catalog.product.description.ProductDescription) WeightUnitOfMeasure(com.salesmanager.shop.model.references.WeightUnitOfMeasure) Category(com.salesmanager.core.model.catalog.category.Category) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) ProductImage(com.salesmanager.core.model.catalog.product.image.ProductImage) ArrayList(java.util.ArrayList) ReadableImage(com.salesmanager.shop.model.catalog.product.ReadableImage) ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) FinalPrice(com.salesmanager.core.model.catalog.product.price.FinalPrice) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) ReadableProductDefinition(com.salesmanager.shop.model.catalog.product.product.definition.ReadableProductDefinition) ProductSpecification(com.salesmanager.shop.model.catalog.product.ProductSpecification) ReadableProductDefinitionFull(com.salesmanager.shop.model.catalog.product.product.definition.ReadableProductDefinitionFull) ServiceException(com.salesmanager.core.business.exception.ServiceException) ProductDescription(com.salesmanager.core.model.catalog.product.description.ProductDescription) ReadableProductType(com.salesmanager.shop.model.catalog.product.type.ReadableProductType)

Example 2 with ReadableImage

use of com.salesmanager.shop.model.catalog.product.ReadableImage in project shopizer by shopizer-ecommerce.

the class ReadableProductDefinitionMapper method merge.

@Override
public ReadableProductDefinition merge(Product source, ReadableProductDefinition destination, MerchantStore store, Language language) {
    Validate.notNull(source, "Product cannot be null");
    Validate.notNull(destination, "Product destination cannot be null");
    ReadableProductDefinition returnDestination = destination;
    if (language == null) {
        returnDestination = new ReadableProductDefinitionFull();
    }
    List<com.salesmanager.shop.model.catalog.product.ProductDescription> fulldescriptions = new ArrayList<com.salesmanager.shop.model.catalog.product.ProductDescription>();
    returnDestination.setIdentifier(source.getSku());
    returnDestination.setId(source.getId());
    returnDestination.setVisible(source.isAvailable());
    returnDestination.setDateAvailable(DateUtil.formatDate(source.getDateAvailable()));
    ProductDescription description = null;
    if (source.getDescriptions() != null && source.getDescriptions().size() > 0) {
        for (ProductDescription desc : source.getDescriptions()) {
            if (language != null && desc.getLanguage() != null && desc.getLanguage().getId().intValue() == language.getId().intValue()) {
                description = desc;
                break;
            } else {
                fulldescriptions.add(populateDescription(desc));
            }
        }
    }
    if (description != null) {
        com.salesmanager.shop.model.catalog.product.ProductDescription tragetDescription = populateDescription(description);
        returnDestination.setDescription(tragetDescription);
    }
    if (source.getManufacturer() != null) {
        ReadableManufacturer manufacturer = readableManufacturerMapper.convert(source.getManufacturer(), store, language);
        returnDestination.setManufacturer(manufacturer);
    }
    if (!CollectionUtils.isEmpty(source.getCategories())) {
        List<ReadableCategory> categoryList = new ArrayList<ReadableCategory>();
        for (Category category : source.getCategories()) {
            ReadableCategory readableCategory = readableCategoryMapper.convert(category, store, language);
            categoryList.add(readableCategory);
        }
        returnDestination.setCategories(categoryList);
    }
    ProductSpecification specifications = new ProductSpecification();
    specifications.setHeight(source.getProductHeight());
    specifications.setLength(source.getProductLength());
    specifications.setWeight(source.getProductWeight());
    specifications.setWidth(source.getProductWidth());
    if (!StringUtils.isBlank(store.getSeizeunitcode())) {
        specifications.setDimensionUnitOfMeasure(DimensionUnitOfMeasure.valueOf(store.getSeizeunitcode().toLowerCase()));
    }
    if (!StringUtils.isBlank(store.getWeightunitcode())) {
        specifications.setWeightUnitOfMeasure(WeightUnitOfMeasure.valueOf(store.getWeightunitcode().toLowerCase()));
    }
    returnDestination.setProductSpecifications(specifications);
    if (source.getType() != null) {
        ReadableProductType readableType = readableProductTypeMapper.convert(source.getType(), store, language);
        returnDestination.setType(readableType);
    }
    returnDestination.setSortOrder(source.getSortOrder());
    // images
    Set<ProductImage> images = source.getImages();
    if (CollectionUtils.isNotEmpty(images)) {
        List<ReadableImage> imageList = images.stream().map(i -> this.convertImage(source, i, store)).collect(Collectors.toList());
        returnDestination.setImages(imageList);
    }
    // quantity
    ProductAvailability availability = null;
    for (ProductAvailability a : source.getAvailabilities()) {
        availability = a;
        returnDestination.setCanBePurchased(availability.getProductStatus());
        returnDestination.setQuantity(availability.getProductQuantity() == null ? 1 : availability.getProductQuantity());
    }
    FinalPrice price = null;
    try {
        price = pricingService.calculateProductPrice(source);
    } catch (ServiceException e) {
        throw new ConversionRuntimeException("Unable to get product price", e);
    }
    if (price != null) {
        returnDestination.setPrice(price.getStringPrice());
    }
    if (returnDestination instanceof ReadableProductDefinitionFull) {
        ((ReadableProductDefinitionFull) returnDestination).setDescriptions(fulldescriptions);
    }
    return returnDestination;
}
Also used : DateUtil(com.salesmanager.shop.utils.DateUtil) Autowired(org.springframework.beans.factory.annotation.Autowired) ReadableCategoryMapper(com.salesmanager.shop.mapper.catalog.ReadableCategoryMapper) StringUtils(org.apache.commons.lang3.StringUtils) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) ServiceException(com.salesmanager.core.business.exception.ServiceException) Language(com.salesmanager.core.model.reference.language.Language) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) FinalPrice(com.salesmanager.core.model.catalog.product.price.FinalPrice) ReadableImage(com.salesmanager.shop.model.catalog.product.ReadableImage) ReadableProductDefinition(com.salesmanager.shop.model.catalog.product.product.definition.ReadableProductDefinition) DimensionUnitOfMeasure(com.salesmanager.shop.model.references.DimensionUnitOfMeasure) Qualifier(org.springframework.beans.factory.annotation.Qualifier) PricingService(com.salesmanager.core.business.services.catalog.product.PricingService) ReadableProductDefinitionFull(com.salesmanager.shop.model.catalog.product.product.definition.ReadableProductDefinitionFull) Mapper(com.salesmanager.shop.mapper.Mapper) Product(com.salesmanager.core.model.catalog.product.Product) ReadableManufacturerMapper(com.salesmanager.shop.mapper.catalog.ReadableManufacturerMapper) ReadableProductType(com.salesmanager.shop.model.catalog.product.type.ReadableProductType) Set(java.util.Set) ImageFilePath(com.salesmanager.shop.utils.ImageFilePath) Collectors(java.util.stream.Collectors) Category(com.salesmanager.core.model.catalog.category.Category) ReadableProductTypeMapper(com.salesmanager.shop.mapper.catalog.ReadableProductTypeMapper) ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) List(java.util.List) Component(org.springframework.stereotype.Component) Validate(org.apache.commons.lang3.Validate) ProductImage(com.salesmanager.core.model.catalog.product.image.ProductImage) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) ProductSpecification(com.salesmanager.shop.model.catalog.product.ProductSpecification) ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) ProductDescription(com.salesmanager.core.model.catalog.product.description.ProductDescription) WeightUnitOfMeasure(com.salesmanager.shop.model.references.WeightUnitOfMeasure) Category(com.salesmanager.core.model.catalog.category.Category) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) ProductImage(com.salesmanager.core.model.catalog.product.image.ProductImage) ArrayList(java.util.ArrayList) ReadableImage(com.salesmanager.shop.model.catalog.product.ReadableImage) ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) FinalPrice(com.salesmanager.core.model.catalog.product.price.FinalPrice) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) ReadableProductDefinition(com.salesmanager.shop.model.catalog.product.product.definition.ReadableProductDefinition) ProductSpecification(com.salesmanager.shop.model.catalog.product.ProductSpecification) ReadableProductDefinitionFull(com.salesmanager.shop.model.catalog.product.product.definition.ReadableProductDefinitionFull) ServiceException(com.salesmanager.core.business.exception.ServiceException) ProductDescription(com.salesmanager.core.model.catalog.product.description.ProductDescription) ReadableProductType(com.salesmanager.shop.model.catalog.product.type.ReadableProductType)

Example 3 with ReadableImage

use of com.salesmanager.shop.model.catalog.product.ReadableImage in project shopizer by shopizer-ecommerce.

the class ReadableProductDefinitionMapper method convertImage.

private ReadableImage convertImage(Product product, ProductImage image, MerchantStore store) {
    ReadableImage prdImage = new ReadableImage();
    prdImage.setImageName(image.getProductImage());
    prdImage.setDefaultImage(image.isDefaultImage());
    StringBuilder imgPath = new StringBuilder();
    imgPath.append(imageUtils.getContextPath()).append(imageUtils.buildProductImageUtils(store, product.getSku(), image.getProductImage()));
    prdImage.setImageUrl(imgPath.toString());
    prdImage.setId(image.getId());
    prdImage.setImageType(image.getImageType());
    if (image.getProductImageUrl() != null) {
        prdImage.setExternalUrl(image.getProductImageUrl());
    }
    if (image.getImageType() == 1 && image.getProductImageUrl() != null) {
        // video
        prdImage.setVideoUrl(image.getProductImageUrl());
    }
    if (prdImage.isDefaultImage()) {
        prdImage.setDefaultImage(true);
    }
    return prdImage;
}
Also used : ReadableImage(com.salesmanager.shop.model.catalog.product.ReadableImage)

Example 4 with ReadableImage

use of com.salesmanager.shop.model.catalog.product.ReadableImage in project shopizer by shopizer-ecommerce.

the class ReadableProductInstanceMapper method merge.

@Override
public ReadableProductInstance merge(ProductInstance source, ReadableProductInstance destination, MerchantStore store, Language language) {
    Validate.notNull(source, "Product instance cannot be null");
    Validate.notNull(source.getProduct(), "Product cannot be null");
    if (destination == null) {
        destination = new ReadableProductInstance();
    }
    destination.setSortOrder(source.getSortOrder() != null ? source.getSortOrder().intValue() : 0);
    destination.setAvailable(source.isAvailable());
    destination.setDateAvailable(DateUtil.formatDate(source.getDateAvailable()));
    destination.setId(source.getId());
    destination.setDefaultSelection(source.isDefaultSelection());
    destination.setProductId(source.getProduct().getId());
    destination.setSku(source.getSku());
    destination.setSortOrder(source.getSortOrder());
    destination.setCode(source.getCode());
    // get product
    Product baseProduct = source.getProduct();
    if (baseProduct == null) {
        throw new ResourceNotFoundException("Product instances do not include the parent product [" + destination.getSku() + "]");
    }
    destination.setProductShipeable(baseProduct.isProductShipeable());
    // destination.setStore(null);
    destination.setStore(store.getCode());
    destination.setVariant(readableProductVariationMapper.convert(source.getVariant(), store, language));
    destination.setVariantValue(readableProductVariationMapper.convert(source.getVariantValue(), store, language));
    if (source.getProductInstanceGroup() != null) {
        Set<String> nameSet = new HashSet<>();
        List<ReadableImage> instanceImages = source.getProductInstanceGroup().getImages().stream().map(i -> this.image(i, store, language)).filter(e -> nameSet.add(e.getImageUrl())).collect(Collectors.toList());
        destination.setImages(instanceImages);
    }
    if (!CollectionUtils.isEmpty(source.getAvailabilities())) {
        List<ReadableInventory> inventories = source.getAvailabilities().stream().map(i -> readableInventoryMapper.convert(i, store, language)).collect(Collectors.toList());
        destination.setInventory(inventories);
    }
    return destination;
}
Also used : ReadableProductInstance(com.salesmanager.shop.model.catalog.product.product.instance.ReadableProductInstance) DateUtil(com.salesmanager.shop.utils.DateUtil) Autowired(org.springframework.beans.factory.annotation.Autowired) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Language(com.salesmanager.core.model.reference.language.Language) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ReadableImage(com.salesmanager.shop.model.catalog.product.ReadableImage) CollectionUtils(org.apache.commons.collections.CollectionUtils) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ReadableProductVariationMapper(com.salesmanager.shop.mapper.catalog.ReadableProductVariationMapper) FileContentType(com.salesmanager.core.model.content.FileContentType) Mapper(com.salesmanager.shop.mapper.Mapper) Validate(org.jsoup.helper.Validate) Product(com.salesmanager.core.model.catalog.product.Product) Set(java.util.Set) ReadableInventoryMapper(com.salesmanager.shop.mapper.inventory.ReadableInventoryMapper) ImageFilePath(com.salesmanager.shop.utils.ImageFilePath) ProductInstance(com.salesmanager.core.model.catalog.product.instance.ProductInstance) Collectors(java.util.stream.Collectors) ReadableInventory(com.salesmanager.shop.model.catalog.product.inventory.ReadableInventory) List(java.util.List) Component(org.springframework.stereotype.Component) ProductInstanceImage(com.salesmanager.core.model.catalog.product.instance.ProductInstanceImage) ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) ReadableImage(com.salesmanager.shop.model.catalog.product.ReadableImage) ReadableInventory(com.salesmanager.shop.model.catalog.product.inventory.ReadableInventory) Product(com.salesmanager.core.model.catalog.product.Product) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ReadableProductInstance(com.salesmanager.shop.model.catalog.product.product.instance.ReadableProductInstance) HashSet(java.util.HashSet)

Example 5 with ReadableImage

use of com.salesmanager.shop.model.catalog.product.ReadableImage in project shopizer by shopizer-ecommerce.

the class ReadableProductInstanceMapper method image.

private ReadableImage image(ProductInstanceImage instanceImage, MerchantStore store, Language language) {
    ReadableImage img = new ReadableImage();
    img.setDefaultImage(instanceImage.isDefaultImage());
    img.setId(instanceImage.getId());
    img.setImageName(instanceImage.getProductImage());
    img.setImageUrl(imagUtils.buildCustomTypeImageUtils(store, img.getImageName(), FileContentType.INSTANCE));
    return img;
}
Also used : ReadableImage(com.salesmanager.shop.model.catalog.product.ReadableImage)

Aggregations

ReadableImage (com.salesmanager.shop.model.catalog.product.ReadableImage)12 Product (com.salesmanager.core.model.catalog.product.Product)6 ProductImage (com.salesmanager.core.model.catalog.product.image.ProductImage)6 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)6 Language (com.salesmanager.core.model.reference.language.Language)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 Set (java.util.Set)6 Collectors (java.util.stream.Collectors)6 ProductAvailability (com.salesmanager.core.model.catalog.product.availability.ProductAvailability)5 ProductDescription (com.salesmanager.core.model.catalog.product.description.ProductDescription)5 FinalPrice (com.salesmanager.core.model.catalog.product.price.FinalPrice)5 ProductSpecification (com.salesmanager.shop.model.catalog.product.ProductSpecification)5 DateUtil (com.salesmanager.shop.utils.DateUtil)5 ImageFilePath (com.salesmanager.shop.utils.ImageFilePath)5 CollectionUtils (org.apache.commons.collections4.CollectionUtils)5 PricingService (com.salesmanager.core.business.services.catalog.product.PricingService)4 Category (com.salesmanager.core.model.catalog.category.Category)4 ReadableCategory (com.salesmanager.shop.model.catalog.category.ReadableCategory)4 ReadableManufacturer (com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer)4