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;
}
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);
}
Aggregations