use of com.salesmanager.shop.model.catalog.product.ReadableProductReview in project shopizer by shopizer-ecommerce.
the class ProductFacadeImpl method getProductReviews.
@Override
public List<ReadableProductReview> getProductReviews(Product product, MerchantStore store, Language language) throws Exception {
List<ProductReview> reviews = productReviewService.getByProduct(product);
ReadableProductReviewPopulator populator = new ReadableProductReviewPopulator();
List<ReadableProductReview> productReviews = new ArrayList<ReadableProductReview>();
for (ProductReview review : reviews) {
ReadableProductReview readableReview = new ReadableProductReview();
populator.populate(review, readableReview, store, language);
productReviews.add(readableReview);
}
return productReviews;
}
use of com.salesmanager.shop.model.catalog.product.ReadableProductReview in project shopizer by shopizer-ecommerce.
the class CustomerProductReviewController method displayProductReview.
@PreAuthorize("hasRole('AUTH_CUSTOMER')")
@RequestMapping(value = "/review.html", method = RequestMethod.GET)
public String displayProductReview(@RequestParam Long productId, Model model, HttpServletRequest request, HttpServletResponse response) throws Exception {
MerchantStore store = getSessionAttribute(Constants.MERCHANT_STORE, request);
Language language = super.getLanguage(request);
// get product
Product product = productService.getById(productId);
if (product == null) {
return "redirect:" + Constants.SHOP_URI;
}
if (product.getMerchantStore().getId().intValue() != store.getId().intValue()) {
return "redirect:" + Constants.SHOP_URI;
}
// create readable product
ReadableProduct readableProduct = new ReadableProduct();
ReadableProductPopulator readableProductPopulator = new ReadableProductPopulator();
readableProductPopulator.setPricingService(pricingService);
readableProductPopulator.setimageUtils(imageUtils);
readableProductPopulator.populate(product, readableProduct, store, language);
model.addAttribute("product", readableProduct);
Customer customer = customerFacade.getCustomerByUserName(request.getRemoteUser(), store);
List<ProductReview> reviews = productReviewService.getByProduct(product, language);
for (ProductReview r : reviews) {
if (r.getCustomer().getId().longValue() == customer.getId().longValue()) {
ReadableProductReviewPopulator reviewPopulator = new ReadableProductReviewPopulator();
ReadableProductReview rev = new ReadableProductReview();
reviewPopulator.populate(r, rev, store, language);
model.addAttribute("customerReview", rev);
break;
}
}
ProductReview review = new ProductReview();
review.setCustomer(customer);
review.setProduct(product);
ReadableProductReview productReview = new ReadableProductReview();
ReadableProductReviewPopulator reviewPopulator = new ReadableProductReviewPopulator();
reviewPopulator.populate(review, productReview, store, language);
model.addAttribute("review", productReview);
model.addAttribute("reviews", reviews);
/**
* template *
*/
StringBuilder template = new StringBuilder().append(ControllerConstants.Tiles.Customer.review).append(".").append(store.getStoreTemplate());
return template.toString();
}
use of com.salesmanager.shop.model.catalog.product.ReadableProductReview in project shopizer by shopizer-ecommerce.
the class ProductCommonFacadeImpl method getProductReviews.
@Override
public List<ReadableProductReview> getProductReviews(Product product, MerchantStore store, Language language) throws Exception {
List<ProductReview> reviews = productReviewService.getByProduct(product);
ReadableProductReviewPopulator populator = new ReadableProductReviewPopulator();
List<ReadableProductReview> productReviews = new ArrayList<ReadableProductReview>();
for (ProductReview review : reviews) {
ReadableProductReview readableReview = new ReadableProductReview();
populator.populate(review, readableReview, store, language);
productReviews.add(readableReview);
}
return productReviews;
}
use of com.salesmanager.shop.model.catalog.product.ReadableProductReview in project shopizer by shopizer-ecommerce.
the class ProductReviewApi method getAll.
@RequestMapping(value = "/products/{id}/reviews", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
public List<ReadableProductReview> getAll(@PathVariable final Long id, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletResponse response) {
try {
// product exist
Product product = productService.getById(id);
if (product == null) {
response.sendError(404, "Product id " + id + " does not exists");
return null;
}
List<ReadableProductReview> reviews = productCommonFacade.getProductReviews(product, merchantStore, language);
return reviews;
} catch (Exception e) {
LOGGER.error("Error while getting product reviews", e);
try {
response.sendError(503, "Error while getting product reviews" + e.getMessage());
} catch (Exception ignore) {
}
return null;
}
}
use of com.salesmanager.shop.model.catalog.product.ReadableProductReview in project shopizer by shopizer-ecommerce.
the class ShopProductController method display.
@SuppressWarnings("unchecked")
public String display(final String reference, final String friendlyUrl, Model model, HttpServletRequest request, HttpServletResponse response, Locale locale) throws Exception {
MerchantStore store = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
Language language = (Language) request.getAttribute("LANGUAGE");
Product product = productService.getBySeUrl(store, friendlyUrl, locale);
if (product == null) {
return PageBuilderUtils.build404(store);
}
ReadableProductPopulator populator = new ReadableProductPopulator();
populator.setPricingService(pricingService);
populator.setimageUtils(imageUtils);
ReadableProduct productProxy = populator.populate(product, new ReadableProduct(), store, language);
// meta information
PageInformation pageInformation = new PageInformation();
pageInformation.setPageDescription(productProxy.getDescription().getMetaDescription());
pageInformation.setPageKeywords(productProxy.getDescription().getKeyWords());
pageInformation.setPageTitle(productProxy.getDescription().getTitle());
pageInformation.setPageUrl(productProxy.getDescription().getFriendlyUrl());
if (productProxy.getImage() != null) {
MerchantStore merchantStore = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
StringBuilder imageUrl = new StringBuilder(filePathUtils.buildStoreForwardedUri(merchantStore, request));
imageUrl.append(productProxy.getImage().getImageUrl());
pageInformation.setPageImageUrl(imageUrl.toString());
}
request.setAttribute(Constants.REQUEST_PAGE_INFORMATION, pageInformation);
Breadcrumb breadCrumb = breadcrumbsUtils.buildProductBreadcrumb(reference, productProxy, store, language, request.getContextPath());
request.getSession().setAttribute(Constants.BREADCRUMB, breadCrumb);
request.setAttribute(Constants.BREADCRUMB, breadCrumb);
StringBuilder relatedItemsCacheKey = new StringBuilder();
relatedItemsCacheKey.append(store.getId()).append("_").append(Constants.RELATEDITEMS_CACHE_KEY).append("-").append(language.getCode());
StringBuilder relatedItemsMissed = new StringBuilder();
relatedItemsMissed.append(relatedItemsCacheKey.toString()).append(Constants.MISSED_CACHE_KEY);
Map<Long, List<ReadableProduct>> relatedItemsMap = null;
List<ReadableProduct> relatedItems = null;
if (store.isUseCache()) {
// get from the cache
relatedItemsMap = (Map<Long, List<ReadableProduct>>) cache.getFromCache(relatedItemsCacheKey.toString());
if (relatedItemsMap == null) {
// get from missed cache
// Boolean missedContent = (Boolean)cache.getFromCache(relatedItemsMissed.toString());
// if(missedContent==null) {
relatedItems = relatedItems(store, product, language);
if (relatedItems != null) {
relatedItemsMap = new HashMap<Long, List<ReadableProduct>>();
relatedItemsMap.put(product.getId(), relatedItems);
cache.putInCache(relatedItemsMap, relatedItemsCacheKey.toString());
} else {
// cache.putInCache(new Boolean(true), relatedItemsMissed.toString());
}
// }
} else {
relatedItems = relatedItemsMap.get(product.getId());
}
} else {
relatedItems = relatedItems(store, product, language);
}
model.addAttribute("relatedProducts", relatedItems);
Set<ProductAttribute> attributes = product.getAttributes();
// split read only and options
Map<Long, Attribute> readOnlyAttributes = null;
Map<Long, Attribute> selectableOptions = null;
if (!CollectionUtils.isEmpty(attributes)) {
for (ProductAttribute attribute : attributes) {
Attribute attr = null;
AttributeValue attrValue = new AttributeValue();
ProductOptionValue optionValue = attribute.getProductOptionValue();
if (attribute.getAttributeDisplayOnly() == true) {
// read only attribute
if (readOnlyAttributes == null) {
readOnlyAttributes = new TreeMap<Long, Attribute>();
}
attr = readOnlyAttributes.get(attribute.getProductOption().getId());
if (attr == null) {
attr = createAttribute(attribute, language);
}
if (attr != null) {
readOnlyAttributes.put(attribute.getProductOption().getId(), attr);
attr.setReadOnlyValue(attrValue);
}
} else {
// selectable option
if (selectableOptions == null) {
selectableOptions = new TreeMap<Long, Attribute>();
}
attr = selectableOptions.get(attribute.getProductOption().getId());
if (attr == null) {
attr = createAttribute(attribute, language);
}
if (attr != null) {
selectableOptions.put(attribute.getProductOption().getId(), attr);
}
}
attrValue.setDefaultAttribute(attribute.getAttributeDefault());
// id of the attribute
attrValue.setId(attribute.getId());
attrValue.setLanguage(language.getCode());
if (attribute.getProductAttributePrice() != null && attribute.getProductAttributePrice().doubleValue() > 0) {
String formatedPrice = pricingService.getDisplayAmount(attribute.getProductAttributePrice(), store);
attrValue.setPrice(formatedPrice);
}
if (!StringUtils.isBlank(attribute.getProductOptionValue().getProductOptionValueImage())) {
attrValue.setImage(imageUtils.buildProductPropertyImageUtils(store, attribute.getProductOptionValue().getProductOptionValueImage()));
}
attrValue.setSortOrder(0);
if (attribute.getProductOptionSortOrder() != null) {
attrValue.setSortOrder(attribute.getProductOptionSortOrder().intValue());
}
List<ProductOptionValueDescription> descriptions = optionValue.getDescriptionsSettoList();
ProductOptionValueDescription description = null;
if (descriptions != null && descriptions.size() > 0) {
description = descriptions.get(0);
if (descriptions.size() > 1) {
for (ProductOptionValueDescription optionValueDescription : descriptions) {
if (optionValueDescription.getLanguage().getId().intValue() == language.getId().intValue()) {
description = optionValueDescription;
break;
}
}
}
}
attrValue.setName(description.getName());
attrValue.setDescription(description.getDescription());
List<AttributeValue> attrs = attr.getValues();
if (attrs == null) {
attrs = new ArrayList<AttributeValue>();
attr.setValues(attrs);
}
attrs.add(attrValue);
}
}
List<ProductReview> reviews = productReviewService.getByProduct(product, language);
if (!CollectionUtils.isEmpty(reviews)) {
List<ReadableProductReview> revs = new ArrayList<ReadableProductReview>();
ReadableProductReviewPopulator reviewPopulator = new ReadableProductReviewPopulator();
for (ProductReview review : reviews) {
ReadableProductReview rev = new ReadableProductReview();
reviewPopulator.populate(review, rev, store, language);
revs.add(rev);
}
model.addAttribute("reviews", revs);
}
List<Attribute> attributesList = null;
if (readOnlyAttributes != null) {
attributesList = new ArrayList<Attribute>(readOnlyAttributes.values());
}
List<Attribute> optionsList = null;
if (selectableOptions != null) {
optionsList = new ArrayList<Attribute>(selectableOptions.values());
// order attributes by sort order
for (Attribute attr : optionsList) {
Collections.sort(attr.getValues(), new Comparator<AttributeValue>() {
public int compare(AttributeValue o1, AttributeValue o2) {
if (o1.getSortOrder() == o2.getSortOrder())
return 0;
return o1.getSortOrder() < o2.getSortOrder() ? -1 : 1;
}
});
}
}
model.addAttribute("attributes", attributesList);
model.addAttribute("options", optionsList);
model.addAttribute("product", productProxy);
/**
* template *
*/
StringBuilder template = new StringBuilder().append(ControllerConstants.Tiles.Product.product).append(".").append(store.getStoreTemplate());
return template.toString();
}
Aggregations