use of com.salesmanager.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.
the class ProductFacadeImpl method getProductPrice.
@Override
public ReadableProductPrice getProductPrice(Long id, ProductPriceRequest priceRequest, MerchantStore store, Language language) {
Validate.notNull(id, "Product id cannot be null");
Validate.notNull(priceRequest, "Product price request cannot be null");
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(language, "Language cannot be null");
try {
Product model = productService.findOne(id, store);
// TODO check if null
List<Long> attrinutesIds = priceRequest.getOptions().stream().map(p -> p.getId()).collect(Collectors.toList());
List<ProductAttribute> attributes = productAttributeService.getByAttributeIds(store, model, attrinutesIds);
for (ProductAttribute attribute : attributes) {
if (attribute.getProduct().getId().longValue() != id.longValue()) {
// throw unauthorized
throw new OperationNotAllowedException("Attribute with id [" + attribute.getId() + "] is not attached to product id [" + id + "]");
}
}
FinalPrice price;
price = pricingService.calculateProductPrice(model, attributes);
ReadableProductPrice readablePrice = new ReadableProductPrice();
ReadableFinalPricePopulator populator = new ReadableFinalPricePopulator();
populator.setPricingService(pricingService);
return populator.populate(price, readablePrice, store, language);
} catch (Exception e) {
throw new ServiceRuntimeException("An error occured while getting product price", e);
}
}
use of com.salesmanager.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.
the class CategoryFacadeImpl method getCategoryHierarchy.
@Override
public ReadableCategoryList getCategoryHierarchy(MerchantStore store, ListCriteria criteria, int depth, Language language, List<String> filter, int page, int count) {
Validate.notNull(store, "MerchantStore can not be null");
// get parent store
try {
MerchantStore parent = merchantStoreService.getParent(store.getCode());
List<Category> categories = null;
ReadableCategoryList returnList = new ReadableCategoryList();
if (!CollectionUtils.isEmpty(filter) && filter.contains(FEATURED_CATEGORY)) {
categories = categoryService.getListByDepthFilterByFeatured(parent, depth, language);
returnList.setRecordsTotal(categories.size());
returnList.setNumber(categories.size());
returnList.setTotalPages(1);
} else {
org.springframework.data.domain.Page<Category> pageable = categoryService.getListByDepth(parent, language, criteria != null ? criteria.getName() : null, depth, page, count);
categories = pageable.getContent();
returnList.setRecordsTotal(pageable.getTotalElements());
returnList.setTotalPages(pageable.getTotalPages());
returnList.setNumber(categories.size());
}
List<ReadableCategory> readableCategories = null;
if (filter != null && filter.contains(VISIBLE_CATEGORY)) {
readableCategories = categories.stream().filter(Category::isVisible).map(cat -> categoryReadableCategoryConverter.convert(cat, store, language)).collect(Collectors.toList());
} else {
readableCategories = categories.stream().map(cat -> categoryReadableCategoryConverter.convert(cat, store, language)).collect(Collectors.toList());
}
Map<Long, ReadableCategory> readableCategoryMap = readableCategories.stream().collect(Collectors.toMap(ReadableCategory::getId, Function.identity()));
readableCategories.stream().filter(cat -> Objects.nonNull(cat.getParent())).filter(cat -> readableCategoryMap.containsKey(cat.getParent().getId())).forEach(readableCategory -> {
ReadableCategory parentCategory = readableCategoryMap.get(readableCategory.getParent().getId());
if (parentCategory != null) {
parentCategory.getChildren().add(readableCategory);
}
});
List<ReadableCategory> filteredList = readableCategoryMap.values().stream().collect(Collectors.toList());
// execute only if not admin filtered
if (filter == null || (filter != null && !filter.contains(ADMIN_CATEGORY))) {
filteredList = readableCategoryMap.values().stream().filter(cat -> cat.getDepth() == 0).sorted(Comparator.comparing(ReadableCategory::getSortOrder)).collect(Collectors.toList());
returnList.setNumber(filteredList.size());
}
returnList.setCategories(filteredList);
return returnList;
} catch (ServiceException e) {
throw new ServiceRuntimeException(e);
}
}
use of com.salesmanager.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.
the class ContentFacadeImpl method convertContentToReadableContentBox.
private ReadableContentBox convertContentToReadableContentBox(MerchantStore store, Language language, Content content) {
if (language != null) {
ReadableContentBox box = new ReadableContentBox();
this.setDescription(content, box, language);
box.setCode(content.getCode());
box.setId(content.getId());
box.setVisible(content.isVisible());
return box;
} else {
ReadableContentBoxFull box = new ReadableContentBoxFull();
List<com.salesmanager.shop.model.content.common.ContentDescription> descriptions = content.getDescriptions().stream().map(d -> this.contentDescription(d)).collect(Collectors.toList());
this.setDescription(content, box, store.getDefaultLanguage());
box.setDescriptions(descriptions);
box.setCode(content.getCode());
box.setId(content.getId());
box.setVisible(content.isVisible());
return box;
}
// TODO revise this
// String staticImageFilePath = imageUtils.buildStaticImageUtils(store,
// content.getCode() + ".jpg");
// box.setImage(staticImageFilePath);
}
use of com.salesmanager.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.
the class ContentFacadeImpl method convertContentToReadableContentPage.
private ReadableContentPage convertContentToReadableContentPage(MerchantStore store, Language language, Content content) {
if (language != null) {
ReadableContentPage page = new ReadableContentPage();
Optional<ContentDescription> contentDescription = findAppropriateContentDescription(content.getDescriptions(), language);
if (contentDescription.isPresent()) {
com.salesmanager.shop.model.content.common.ContentDescription desc = this.contentDescription(contentDescription.get());
page.setDescription(desc);
}
page.setCode(content.getCode());
page.setId(content.getId());
page.setVisible(content.isVisible());
return page;
} else {
ReadableContentPageFull page = new ReadableContentPageFull();
List<com.salesmanager.shop.model.content.common.ContentDescription> descriptions = content.getDescriptions().stream().map(d -> this.contentDescription(d)).collect(Collectors.toList());
page.setDescriptions(descriptions);
page.setCode(content.getCode());
page.setId(content.getId());
page.setVisible(content.isVisible());
return page;
}
}
use of com.salesmanager.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.
the class ContentFacadeImpl method buildDescriptions.
/*
* private List<ContentDescription> createContentDescription(
* PersistableContentPage content) throws ServiceException {
* Validate.notNull(contentModel, "Content cannot be null");
*
* List<ContentDescription> descriptions = new
* ArrayList<ContentDescription>(); for (NamedEntity objectContent :
* content.getDescriptions()) { Language lang =
* languageService.getByCode(objectContent.getLanguage());
* ContentDescription contentDescription = new ContentDescription(); if
* (contentModel != null) {
* setContentDescriptionToContentModel(contentModel, contentDescription,
* lang); } contentDescription.setLanguage(lang);
* contentDescription.setMetatagDescription(objectContent.getMetaDescription
* ()); contentDescription.setTitle(objectContent.getTitle());
* contentDescription.setName(objectContent.getName());
* contentDescription.setSeUrl(objectContent.getFriendlyUrl());
* contentDescription.setDescription(objectContent.getDescription());
* contentDescription.setMetatagTitle(objectContent.getTitle());
* descriptions.add(contentDescription); } return descriptions; }
*/
private List<ContentDescription> buildDescriptions(Content contentModel, List<com.salesmanager.shop.model.content.common.ContentDescription> persistableDescriptions) throws Exception {
List<ContentDescription> descriptions = new ArrayList<ContentDescription>();
for (com.salesmanager.shop.model.content.common.ContentDescription objectContent : persistableDescriptions) {
Language lang = languageService.getByCode(objectContent.getLanguage());
Validate.notNull(lang, "language cannot be null");
ContentDescription contentDescription = null;
if (!CollectionUtils.isEmpty(contentModel.getDescriptions())) {
for (ContentDescription descriptionModel : contentModel.getDescriptions()) {
if (descriptionModel.getLanguage().getCode().equals(lang.getCode())) {
contentDescription = descriptionModel;
break;
}
}
}
if (contentDescription == null) {
contentDescription = new ContentDescription();
}
// if (contentModel != null) {
// setContentDescriptionToContentModel(contentModel, contentDescription, lang);
// }
contentDescription.setMetatagDescription(objectContent.getMetaDescription());
contentDescription.setTitle(objectContent.getTitle());
contentDescription.setName(objectContent.getName());
contentDescription.setSeUrl(objectContent.getFriendlyUrl());
contentDescription.setDescription(objectContent.getDescription());
contentDescription.setMetatagTitle(objectContent.getTitle());
contentDescription.setContent(contentModel);
contentDescription.setLanguage(lang);
descriptions.add(contentDescription);
// contentDescription.setId(objectContent.getId());
/**
* contentDescription.setMetatagDescription(objectContent.getMetaDescription());
* contentDescription.setTitle(objectContent.getTitle());
* contentDescription.setName(objectContent.getName());
* contentDescription.setSeUrl(objectContent.getFriendlyUrl());
* contentDescription.setDescription(objectContent.getDescription());
* contentDescription.setMetatagTitle(objectContent.getTitle());
* descriptions.add(contentDescription);
*/
}
return descriptions;
}
Aggregations