Search in sources :

Example 1 with ReadableInventory

use of com.salesmanager.shop.model.catalog.product.inventory.ReadableInventory 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 2 with ReadableInventory

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

the class ProductInventoryFacadeImpl method getInventory.

@Override
public ReadableEntityList<ReadableInventory> getInventory(Long productId, MerchantStore store, String child, Language language, int page, int count) {
    Product product = getProductById(productId);
    validateProductHasSameStore(store, product);
    Page<ProductAvailability> availabilities = productAvailabilityService.listByProduct(product, store, child, page, count);
    List<ReadableInventory> inventories = availabilities.stream().map(pa -> readableInventoryMapper.convert(pa, store, language)).collect(Collectors.toList());
    return createReadableList(availabilities, inventories);
}
Also used : ProductService(com.salesmanager.core.business.services.catalog.product.ProductService) ReadableEntityUtil.createReadableList(com.salesmanager.shop.util.ReadableEntityUtil.createReadableList) Autowired(org.springframework.beans.factory.annotation.Autowired) ProductInventoryFacade(com.salesmanager.shop.store.controller.product.facade.ProductInventoryFacade) ServiceException(com.salesmanager.core.business.exception.ServiceException) Language(com.salesmanager.core.model.reference.language.Language) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Service(org.springframework.stereotype.Service) MerchantStoreService(com.salesmanager.core.business.services.merchant.MerchantStoreService) Product(com.salesmanager.core.model.catalog.product.Product) PersistableInventory(com.salesmanager.shop.model.catalog.product.inventory.PersistableInventory) ReadableInventoryMapper(com.salesmanager.shop.mapper.inventory.ReadableInventoryMapper) ProductAvailabilityService(com.salesmanager.core.business.services.catalog.product.availability.ProductAvailabilityService) Page(org.springframework.data.domain.Page) Profile(org.springframework.context.annotation.Profile) Collectors(java.util.stream.Collectors) ReadableInventory(com.salesmanager.shop.model.catalog.product.inventory.ReadableInventory) Objects(java.util.Objects) List(java.util.List) Validate(org.apache.commons.lang3.Validate) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) Optional(java.util.Optional) ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) PersistableInventoryMapper(com.salesmanager.shop.mapper.inventory.PersistableInventoryMapper) ReadableEntityList(com.salesmanager.shop.model.entity.ReadableEntityList) ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) ReadableInventory(com.salesmanager.shop.model.catalog.product.inventory.ReadableInventory) Product(com.salesmanager.core.model.catalog.product.Product)

Aggregations

Product (com.salesmanager.core.model.catalog.product.Product)2 ProductAvailability (com.salesmanager.core.model.catalog.product.availability.ProductAvailability)2 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)2 Language (com.salesmanager.core.model.reference.language.Language)2 ReadableInventoryMapper (com.salesmanager.shop.mapper.inventory.ReadableInventoryMapper)2 ReadableInventory (com.salesmanager.shop.model.catalog.product.inventory.ReadableInventory)2 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 ServiceException (com.salesmanager.core.business.exception.ServiceException)1 ProductService (com.salesmanager.core.business.services.catalog.product.ProductService)1 ProductAvailabilityService (com.salesmanager.core.business.services.catalog.product.availability.ProductAvailabilityService)1 MerchantStoreService (com.salesmanager.core.business.services.merchant.MerchantStoreService)1 ProductInstance (com.salesmanager.core.model.catalog.product.instance.ProductInstance)1 ProductInstanceImage (com.salesmanager.core.model.catalog.product.instance.ProductInstanceImage)1 FileContentType (com.salesmanager.core.model.content.FileContentType)1 Mapper (com.salesmanager.shop.mapper.Mapper)1 ReadableProductVariationMapper (com.salesmanager.shop.mapper.catalog.ReadableProductVariationMapper)1 PersistableInventoryMapper (com.salesmanager.shop.mapper.inventory.PersistableInventoryMapper)1