Search in sources :

Example 1 with ReadableProductInstance

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

the class ProductFacadeV2Impl method getProductBySeUrl.

@Override
public ReadableProduct getProductBySeUrl(MerchantStore store, String friendlyUrl, Language language) throws Exception {
    Product product = productService.getBySeUrl(store, friendlyUrl, LocaleUtils.getLocale(language));
    if (product == null) {
        throw new ResourceNotFoundException("Product [" + friendlyUrl + "] not found for merchant [" + store.getCode() + "]");
    }
    ReadableProduct readableProduct = readableProductMapper.convert(product, store, language);
    // get all instances for this product group by option
    // limit to 15 searches
    List<ProductInstance> instances = productInstanceService.getByProductId(store, product, language);
    // the above get all possible images
    List<ReadableProductInstance> readableInstances = instances.stream().map(p -> this.productInstance(p, store, language)).collect(Collectors.toList());
    readableProduct.setVariants(readableInstances);
    return readableProduct;
}
Also used : ProductService(com.salesmanager.core.business.services.catalog.product.ProductService) ReadableProductInstance(com.salesmanager.shop.model.catalog.product.product.instance.ReadableProductInstance) Autowired(org.springframework.beans.factory.annotation.Autowired) ProductFacade(com.salesmanager.shop.store.controller.product.facade.ProductFacade) StringUtils(org.apache.commons.lang3.StringUtils) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Language(com.salesmanager.core.model.reference.language.Language) ReadableFinalPricePopulator(com.salesmanager.shop.populator.catalog.ReadableFinalPricePopulator) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) FinalPrice(com.salesmanager.core.model.catalog.product.price.FinalPrice) ProductInstanceService(com.salesmanager.core.business.services.catalog.product.instance.ProductInstanceService) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Service(org.springframework.stereotype.Service) Qualifier(org.springframework.beans.factory.annotation.Qualifier) PricingService(com.salesmanager.core.business.services.catalog.product.PricingService) CategoryService(com.salesmanager.core.business.services.catalog.category.CategoryService) ReadableProductPrice(com.salesmanager.shop.model.catalog.product.ReadableProductPrice) ProductAttributeService(com.salesmanager.core.business.services.catalog.product.attribute.ProductAttributeService) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) Product(com.salesmanager.core.model.catalog.product.Product) ProductCriteria(com.salesmanager.core.model.catalog.product.ProductCriteria) ProductPriceRequest(com.salesmanager.shop.model.catalog.product.ProductPriceRequest) ProductRelationshipService(com.salesmanager.core.business.services.catalog.product.relationship.ProductRelationshipService) ImageFilePath(com.salesmanager.shop.utils.ImageFilePath) ProductAvailabilityService(com.salesmanager.core.business.services.catalog.product.availability.ProductAvailabilityService) Page(org.springframework.data.domain.Page) ProductInstance(com.salesmanager.core.model.catalog.product.instance.ProductInstance) Collectors(java.util.stream.Collectors) Profile(org.springframework.context.annotation.Profile) List(java.util.List) LocaleUtils(com.salesmanager.shop.utils.LocaleUtils) Validate(org.apache.commons.lang3.Validate) ProductRelationship(com.salesmanager.core.model.catalog.product.relationship.ProductRelationship) ReadableProductPopulator(com.salesmanager.shop.populator.catalog.ReadableProductPopulator) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ProductRelationshipType(com.salesmanager.core.model.catalog.product.relationship.ProductRelationshipType) ReadableProductMapper(com.salesmanager.shop.mapper.catalog.ReadableProductMapper) ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) Comparator(java.util.Comparator) ReadableProductList(com.salesmanager.shop.model.catalog.product.ReadableProductList) ReadableProductInstanceMapper(com.salesmanager.shop.mapper.catalog.product.ReadableProductInstanceMapper) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) ReadableProductInstance(com.salesmanager.shop.model.catalog.product.product.instance.ReadableProductInstance) ProductInstance(com.salesmanager.core.model.catalog.product.instance.ProductInstance) ReadableProductInstance(com.salesmanager.shop.model.catalog.product.product.instance.ReadableProductInstance)

Example 2 with ReadableProductInstance

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

the class ProductFacadeV2Impl method getProductByCode.

@Override
public ReadableProduct getProductByCode(MerchantStore store, String uniqueCode, Language language) {
    Product product = productService.getByCode(uniqueCode, language);
    if (product == null) {
        throw new ResourceNotFoundException("Product [" + uniqueCode + "] not found for merchant [" + store.getCode() + "]");
    }
    if (product.getMerchantStore().getId() != store.getId()) {
        throw new ResourceNotFoundException("Product [" + uniqueCode + "] not found for merchant [" + store.getCode() + "]");
    }
    ReadableProduct readableProduct = readableProductMapper.convert(product, store, language);
    // get all instances for this product group by option
    // limit to 15 searches
    List<ProductInstance> instances = productInstanceService.getByProductId(store, product, language);
    // the above get all possible images
    List<ReadableProductInstance> readableInstances = instances.stream().map(p -> this.productInstance(p, store, language)).collect(Collectors.toList());
    readableProduct.setVariants(readableInstances);
    return readableProduct;
}
Also used : ProductService(com.salesmanager.core.business.services.catalog.product.ProductService) ReadableProductInstance(com.salesmanager.shop.model.catalog.product.product.instance.ReadableProductInstance) Autowired(org.springframework.beans.factory.annotation.Autowired) ProductFacade(com.salesmanager.shop.store.controller.product.facade.ProductFacade) StringUtils(org.apache.commons.lang3.StringUtils) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Language(com.salesmanager.core.model.reference.language.Language) ReadableFinalPricePopulator(com.salesmanager.shop.populator.catalog.ReadableFinalPricePopulator) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) FinalPrice(com.salesmanager.core.model.catalog.product.price.FinalPrice) ProductInstanceService(com.salesmanager.core.business.services.catalog.product.instance.ProductInstanceService) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Service(org.springframework.stereotype.Service) Qualifier(org.springframework.beans.factory.annotation.Qualifier) PricingService(com.salesmanager.core.business.services.catalog.product.PricingService) CategoryService(com.salesmanager.core.business.services.catalog.category.CategoryService) ReadableProductPrice(com.salesmanager.shop.model.catalog.product.ReadableProductPrice) ProductAttributeService(com.salesmanager.core.business.services.catalog.product.attribute.ProductAttributeService) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) Product(com.salesmanager.core.model.catalog.product.Product) ProductCriteria(com.salesmanager.core.model.catalog.product.ProductCriteria) ProductPriceRequest(com.salesmanager.shop.model.catalog.product.ProductPriceRequest) ProductRelationshipService(com.salesmanager.core.business.services.catalog.product.relationship.ProductRelationshipService) ImageFilePath(com.salesmanager.shop.utils.ImageFilePath) ProductAvailabilityService(com.salesmanager.core.business.services.catalog.product.availability.ProductAvailabilityService) Page(org.springframework.data.domain.Page) ProductInstance(com.salesmanager.core.model.catalog.product.instance.ProductInstance) Collectors(java.util.stream.Collectors) Profile(org.springframework.context.annotation.Profile) List(java.util.List) LocaleUtils(com.salesmanager.shop.utils.LocaleUtils) Validate(org.apache.commons.lang3.Validate) ProductRelationship(com.salesmanager.core.model.catalog.product.relationship.ProductRelationship) ReadableProductPopulator(com.salesmanager.shop.populator.catalog.ReadableProductPopulator) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ProductRelationshipType(com.salesmanager.core.model.catalog.product.relationship.ProductRelationshipType) ReadableProductMapper(com.salesmanager.shop.mapper.catalog.ReadableProductMapper) ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) Comparator(java.util.Comparator) ReadableProductList(com.salesmanager.shop.model.catalog.product.ReadableProductList) ReadableProductInstanceMapper(com.salesmanager.shop.mapper.catalog.product.ReadableProductInstanceMapper) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) ReadableProductInstance(com.salesmanager.shop.model.catalog.product.product.instance.ReadableProductInstance) ProductInstance(com.salesmanager.core.model.catalog.product.instance.ProductInstance) ReadableProductInstance(com.salesmanager.shop.model.catalog.product.product.instance.ReadableProductInstance)

Example 3 with ReadableProductInstance

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

the class ProductInstanceFacadeImpl method get.

@Override
public ReadableProductInstance get(Long instanceId, Long productId, MerchantStore store, Language language) {
    Optional<ProductInstance> productInstance = this.getProductInstance(instanceId, productId, store);
    if (productInstance.isEmpty()) {
        throw new ResourceNotFoundException("Product instance + [" + instanceId + "] not found for store [" + store.getCode() + "]");
    }
    ProductInstance model = productInstance.get();
    return readableProductInstanceMapper.convert(model, store, language);
}
Also used : ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ReadableProductInstance(com.salesmanager.shop.model.catalog.product.product.instance.ReadableProductInstance) ProductInstance(com.salesmanager.core.model.catalog.product.instance.ProductInstance) PersistableProductInstance(com.salesmanager.shop.model.catalog.product.product.instance.PersistableProductInstance)

Example 4 with ReadableProductInstance

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

the class ProductInstanceFacadeImpl method list.

@Override
public ReadableEntityList<ReadableProductInstance> list(Long productId, MerchantStore store, Language language, int page, int count) {
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(productId, "Product id cannot be null");
    Product product = productFacade.getProduct(productId, store);
    if (product == null) {
        throw new ResourceNotFoundException("Product with id [" + productId + "] not found for store [" + store.getCode() + "]");
    }
    Page<ProductInstance> instances = productInstanceService.getByProductId(store, product, language, page, count);
    List<ReadableProductInstance> readableInstances = instances.stream().map(rp -> this.readableProductInstanceMapper.convert(rp, store, language)).collect(Collectors.toList());
    return createReadableList(instances, readableInstances);
}
Also used : ReadableEntityUtil.createReadableList(com.salesmanager.shop.util.ReadableEntityUtil.createReadableList) Arrays(java.util.Arrays) ReadableProductInstance(com.salesmanager.shop.model.catalog.product.product.instance.ReadableProductInstance) Autowired(org.springframework.beans.factory.annotation.Autowired) ProductFacade(com.salesmanager.shop.store.controller.product.facade.ProductFacade) ProductInstanceFacade(com.salesmanager.shop.store.controller.product.facade.ProductInstanceFacade) ServiceException(com.salesmanager.core.business.exception.ServiceException) Language(com.salesmanager.core.model.reference.language.Language) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ProductVariationService(com.salesmanager.core.business.services.catalog.product.variation.ProductVariationService) ProductInstanceService(com.salesmanager.core.business.services.catalog.product.instance.ProductInstanceService) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) ProductVariation(com.salesmanager.core.model.catalog.product.variation.ProductVariation) ConstraintException(com.salesmanager.shop.store.api.exception.ConstraintException) PersistableProductInstanceMapper(com.salesmanager.shop.mapper.catalog.product.PersistableProductInstanceMapper) Page(org.springframework.data.domain.Page) ProductInstance(com.salesmanager.core.model.catalog.product.instance.ProductInstance) Collectors(java.util.stream.Collectors) ProductCommonFacade(com.salesmanager.shop.store.controller.product.facade.ProductCommonFacade) List(java.util.List) Component(org.springframework.stereotype.Component) Validate(org.apache.commons.lang3.Validate) PersistableProductInstance(com.salesmanager.shop.model.catalog.product.product.instance.PersistableProductInstance) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) Optional(java.util.Optional) ReadableProductInstanceMapper(com.salesmanager.shop.mapper.catalog.product.ReadableProductInstanceMapper) ReadableEntityList(com.salesmanager.shop.model.entity.ReadableEntityList) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) 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) ProductInstance(com.salesmanager.core.model.catalog.product.instance.ProductInstance) PersistableProductInstance(com.salesmanager.shop.model.catalog.product.product.instance.PersistableProductInstance) ReadableProductInstance(com.salesmanager.shop.model.catalog.product.product.instance.ReadableProductInstance)

Example 5 with ReadableProductInstance

use of com.salesmanager.shop.model.catalog.product.product.instance.ReadableProductInstance 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)

Aggregations

ProductInstance (com.salesmanager.core.model.catalog.product.instance.ProductInstance)5 ReadableProductInstance (com.salesmanager.shop.model.catalog.product.product.instance.ReadableProductInstance)5 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)5 Product (com.salesmanager.core.model.catalog.product.Product)4 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)4 Language (com.salesmanager.core.model.reference.language.Language)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 ProductInstanceService (com.salesmanager.core.business.services.catalog.product.instance.ProductInstanceService)3 ProductAvailability (com.salesmanager.core.model.catalog.product.availability.ProductAvailability)3 ReadableProductInstanceMapper (com.salesmanager.shop.mapper.catalog.product.ReadableProductInstanceMapper)3 ReadableProduct (com.salesmanager.shop.model.catalog.product.ReadableProduct)3 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)3 ProductFacade (com.salesmanager.shop.store.controller.product.facade.ProductFacade)3 ImageFilePath (com.salesmanager.shop.utils.ImageFilePath)3 HashSet (java.util.HashSet)3 Inject (javax.inject.Inject)3 Validate (org.apache.commons.lang3.Validate)3 Qualifier (org.springframework.beans.factory.annotation.Qualifier)3