use of com.salesmanager.shop.model.catalog.category.ReadableCategory 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;
}
use of com.salesmanager.shop.model.catalog.category.ReadableCategory in project shopizer by shopizer-ecommerce.
the class ReadableCategoryMapper method convert.
@Override
public ReadableCategory convert(Category source, MerchantStore store, Language language) {
if (Objects.isNull(language)) {
ReadableCategoryFull target = new ReadableCategoryFull();
List<com.salesmanager.shop.model.catalog.category.CategoryDescription> descriptions = source.getDescriptions().stream().map(this::convertDescription).collect(Collectors.toList());
target.setDescriptions(descriptions);
fillReadableCategory(target, source);
return target;
} else {
ReadableCategory target = new ReadableCategory();
Optional<com.salesmanager.shop.model.catalog.category.CategoryDescription> description = source.getDescriptions().stream().filter(d -> language.getId().equals(d.getLanguage().getId())).map(this::convertDescription).findAny();
description.ifPresent(target::setDescription);
fillReadableCategory(target, source);
return target;
}
}
use of com.salesmanager.shop.model.catalog.category.ReadableCategory in project shopizer by shopizer-ecommerce.
the class SearchFacadeImpl method convertCategoryToReadableCategory.
private ReadableCategory convertCategoryToReadableCategory(MerchantStore merchantStore, Language language, Map<String, Long> productCategoryCount, Category category) {
ReadableCategoryPopulator populator = new ReadableCategoryPopulator();
try {
ReadableCategory categoryProxy = populator.populate(category, new ReadableCategory(), merchantStore, language);
Long total = productCategoryCount.get(categoryProxy.getCode());
if (total != null) {
categoryProxy.setProductCount(total.intValue());
}
return categoryProxy;
} catch (ConversionException e) {
throw new ConversionRuntimeException(e);
}
}
use of com.salesmanager.shop.model.catalog.category.ReadableCategory in project shopizer by shopizer-ecommerce.
the class SearchFacadeImpl method convertToSearchProductList.
@Override
public SearchProductList convertToSearchProductList(SearchResponse searchResponse, MerchantStore merchantStore, int start, int count, Language language) {
SearchProductList returnList = new SearchProductList();
List<SearchEntry> entries = searchResponse.getEntries();
if (CollectionUtils.isNotEmpty(entries)) {
List<Long> ids = entries.stream().map(SearchEntry::getIndexProduct).map(IndexProduct::getId).map(Long::parseLong).collect(Collectors.toList());
ProductCriteria searchCriteria = new ProductCriteria();
searchCriteria.setMaxCount(count);
searchCriteria.setStartIndex(start);
searchCriteria.setProductIds(ids);
searchCriteria.setAvailable(true);
ProductList productList = productService.listByStore(merchantStore, language, searchCriteria);
List<ReadableProduct> readableProducts = productList.getProducts().stream().map(product -> convertProductToReadableProduct(product, merchantStore, language)).collect(Collectors.toList());
returnList.getProducts().addAll(readableProducts);
returnList.setProductCount(productList.getProducts().size());
}
// Facets
Map<String, List<SearchFacet>> facets = Optional.ofNullable(searchResponse.getFacets()).orElse(Collections.emptyMap());
List<ReadableCategory> categoryProxies = getCategoryFacets(merchantStore, language, facets);
returnList.setCategoryFacets(categoryProxies);
List<SearchFacet> manufacturersFacets = facets.entrySet().stream().filter(e -> MANUFACTURER_FACET_NAME.equals(e.getKey())).findFirst().map(Entry::getValue).orElse(Collections.emptyList());
if (CollectionUtils.isNotEmpty(manufacturersFacets)) {
// TODO add manufacturer facets
}
return returnList;
}
use of com.salesmanager.shop.model.catalog.category.ReadableCategory in project shopizer by shopizer-ecommerce.
the class CategoryFacadeImpl method getCategoryByFriendlyUrl.
@Override
public ReadableCategory getCategoryByFriendlyUrl(MerchantStore store, String friendlyUrl, Language language) throws Exception {
Validate.notNull(friendlyUrl, "Category search friendly URL must not be null");
ReadableCategoryPopulator categoryPopulator = new ReadableCategoryPopulator();
ReadableCategory readableCategory = new ReadableCategory();
Category category = categoryService.getBySeUrl(store, friendlyUrl);
categoryPopulator.populate(category, readableCategory, store, language);
return readableCategory;
}
Aggregations