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 ShoppingCategoryController method getSubCategories.
private List<ReadableCategory> getSubCategories(MerchantStore store, Category category, Map<Long, Long> productCount, Language language, Locale locale) throws Exception {
// sub categories
List<Category> subCategories = categoryService.listByParent(category, language);
ReadableCategoryPopulator populator = new ReadableCategoryPopulator();
List<ReadableCategory> subCategoryProxies = new ArrayList<ReadableCategory>();
for (Category sub : subCategories) {
ReadableCategory cProxy = populator.populate(sub, new ReadableCategory(), store, language);
if (productCount != null) {
Long total = productCount.get(cProxy.getId());
if (total != null) {
cProxy.setProductCount(total.intValue());
}
}
subCategoryProxies.add(cProxy);
}
return subCategoryProxies;
}
use of com.salesmanager.shop.model.catalog.category.ReadableCategory in project shopizer by shopizer-ecommerce.
the class StoreFilter method setTopCategories.
@SuppressWarnings("unchecked")
private void setTopCategories(MerchantStore store, Language language, HttpServletRequest request) throws Exception {
StringBuilder categoriesKey = new StringBuilder();
categoriesKey.append(store.getId()).append("_").append(Constants.CATEGORIES_CACHE_KEY).append("-").append(language.getCode());
StringBuilder categoriesKeyMissed = new StringBuilder();
categoriesKeyMissed.append(categoriesKey.toString()).append(Constants.MISSED_CACHE_KEY);
// language code - List of category
Map<String, List<ReadableCategory>> objects = null;
List<ReadableCategory> loadedCategories = null;
if (store.isUseCache()) {
objects = (Map<String, List<ReadableCategory>>) webApplicationCache.getFromCache(categoriesKey.toString());
if (objects == null) {
// load categories
ReadableCategoryList categoryList = categoryFacade.getCategoryHierarchy(store, null, 0, language, null, 0, // null
200);
loadedCategories = categoryList.getCategories();
// filter out invisible category
loadedCategories.stream().filter(cat -> cat.isVisible() == true).collect(Collectors.toList());
objects = new ConcurrentHashMap<String, List<ReadableCategory>>();
objects.put(language.getCode(), loadedCategories);
webApplicationCache.putInCache(categoriesKey.toString(), objects);
} else {
loadedCategories = objects.get(language.getCode());
}
} else {
ReadableCategoryList categoryList = categoryFacade.getCategoryHierarchy(store, null, 0, language, null, 0, // null // filter
200);
loadedCategories = categoryList.getCategories();
}
if (loadedCategories != null) {
request.setAttribute(Constants.REQUEST_TOP_CATEGORIES, loadedCategories);
}
}
use of com.salesmanager.shop.model.catalog.category.ReadableCategory in project shopizer by shopizer-ecommerce.
the class CategoryManagementAPIIntegrationTest method putCategory.
@Test
public void putCategory() throws Exception {
// create
PersistableCategory newCategory = new PersistableCategory();
newCategory.setCode("angular");
newCategory.setSortOrder(1);
newCategory.setVisible(true);
newCategory.setDepth(4);
CategoryDescription description = new CategoryDescription();
description.setLanguage("en");
description.setName("angular");
description.setFriendlyUrl("angular");
description.setTitle("angular");
List<CategoryDescription> descriptions = new ArrayList<>();
descriptions.add(description);
newCategory.setDescriptions(descriptions);
final ObjectWriter writer = new ObjectMapper().writer().withDefaultPrettyPrinter();
final String json = writer.writeValueAsString(newCategory);
final HttpEntity<String> entity = new HttpEntity<>(json, getHeader());
// create category
final ResponseEntity response = testRestTemplate.postForEntity("/api/v1/private/category", entity, PersistableCategory.class);
final PersistableCategory cat = (PersistableCategory) response.getBody();
assertThat(response.getStatusCode(), is(CREATED));
assertNotNull(cat.getId());
HttpEntity<String> httpEntity = new HttpEntity<>(getHeader());
final ResponseEntity<ReadableCategory> readableQuery = testRestTemplate.exchange(String.format("/api/v1/category/" + cat.getId()), HttpMethod.GET, httpEntity, ReadableCategory.class);
assertThat(readableQuery.getStatusCode(), is(OK));
ReadableCategory readableCategory = readableQuery.getBody();
newCategory = new PersistableCategory();
newCategory.setCode("angular");
newCategory.setVisible(true);
newCategory.setDepth(4);
newCategory.setSortOrder(2);
description = new CategoryDescription();
description.setLanguage("en");
description.setName("angular");
description.setFriendlyUrl("angular");
description.setTitle("angular");
descriptions = new ArrayList<>();
descriptions.add(description);
newCategory.setDescriptions(descriptions);
HttpEntity<PersistableCategory> requestUpdate = new HttpEntity<>(newCategory, getHeader());
ResponseEntity resp = testRestTemplate.exchange("/api/v1/private/category/" + cat.getId(), HttpMethod.PUT, requestUpdate, Void.class);
assertThat(resp.getStatusCode(), is(OK));
// update
}
use of com.salesmanager.shop.model.catalog.category.ReadableCategory in project shopizer by shopizer-ecommerce.
the class ReadableCategoryPopulator method populate.
@Override
public ReadableCategory populate(final Category source, final ReadableCategory target, final MerchantStore store, final Language language) throws ConversionException {
Validate.notNull(source, "Category must not be null");
target.setLineage(source.getLineage());
if (source.getDescriptions() != null && source.getDescriptions().size() > 0) {
CategoryDescription description = source.getDescription();
if (source.getDescriptions().size() > 1) {
for (final CategoryDescription desc : source.getDescriptions()) {
if (desc.getLanguage().getCode().equals(language.getCode())) {
description = desc;
break;
}
}
}
if (description != null) {
final com.salesmanager.shop.model.catalog.category.CategoryDescription desc = new com.salesmanager.shop.model.catalog.category.CategoryDescription();
desc.setFriendlyUrl(description.getSeUrl());
desc.setName(description.getName());
desc.setId(source.getId());
desc.setDescription(description.getDescription());
desc.setKeyWords(description.getMetatagKeywords());
desc.setHighlights(description.getCategoryHighlight());
desc.setTitle(description.getMetatagTitle());
desc.setMetaDescription(description.getMetatagDescription());
target.setDescription(desc);
}
}
if (source.getParent() != null) {
final com.salesmanager.shop.model.catalog.category.Category parent = new com.salesmanager.shop.model.catalog.category.Category();
parent.setCode(source.getParent().getCode());
parent.setId(source.getParent().getId());
target.setParent(parent);
}
target.setCode(source.getCode());
target.setId(source.getId());
if (source.getDepth() != null) {
target.setDepth(source.getDepth());
}
target.setSortOrder(source.getSortOrder());
target.setVisible(source.isVisible());
target.setFeatured(source.isFeatured());
return target;
}
Aggregations