use of com.salesmanager.core.model.reference.language.Language 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.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.
the class ShoppingCategoryController method getProducts.
private ProductList getProducts(final int start, final int max, final String store, final String language, final String category, final List<QueryFilter> filters, Model model, HttpServletRequest request, HttpServletResponse response) throws Exception {
try {
MerchantStore merchantStore = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
List<BigDecimal> prices = new ArrayList<BigDecimal>();
String ref = "";
if (request.getParameter("ref") != null) {
ref = request.getParameter("ref");
}
request.setAttribute("ref", ref);
Map<String, Language> langs = languageService.getLanguagesMap();
if (merchantStore != null) {
if (!merchantStore.getCode().equals(store)) {
// reset for the current request
merchantStore = null;
}
}
if (merchantStore == null) {
merchantStore = merchantStoreService.getByCode(store);
}
if (merchantStore == null) {
LOGGER.error("Merchant store is null for code " + store);
// TODO localized message
response.sendError(503, "Merchant store is null for code " + store);
return null;
}
// get the category by code
Category cat = categoryService.getBySeUrl(merchantStore, category);
if (cat == null) {
LOGGER.error("Category " + category + " is null");
// TODO localized message
response.sendError(503, "Category is null");
return null;
}
String lineage = new StringBuilder().append(cat.getLineage()).toString();
List<Category> categories = categoryService.getListByLineage(store, lineage);
List<Long> ids = new ArrayList<Long>();
if (categories != null && categories.size() > 0) {
for (Category c : categories) {
if (c.isVisible()) {
ids.add(c.getId());
}
}
}
ids.add(cat.getId());
Language lang = langs.get(language);
if (lang == null) {
lang = langs.get(Constants.DEFAULT_LANGUAGE);
}
ProductCriteria productCriteria = new ProductCriteria();
productCriteria.setMaxCount(max);
productCriteria.setStartIndex(start);
productCriteria.setCategoryIds(ids);
productCriteria.setAvailable(true);
if (filters != null) {
for (QueryFilter filter : filters) {
if (filter.getFilterType().name().equals(QueryFilterType.BRAND.name())) {
// the only filter implemented
productCriteria.setManufacturerId(filter.getFilterId());
}
}
}
com.salesmanager.core.model.catalog.product.ProductList products = productService.listByStore(merchantStore, lang, productCriteria);
ReadableProductPopulator populator = new ReadableProductPopulator();
populator.setPricingService(pricingService);
populator.setimageUtils(imageUtils);
ProductList productList = new ProductList();
for (Product product : products.getProducts()) {
// create new proxy product
ReadableProduct p = populator.populate(product, new ReadableProduct(), merchantStore, lang);
productList.getProducts().add(p);
prices.add(p.getPrice());
}
/**
* order products based on the specified order *
*/
Collections.sort(productList.getProducts(), new Comparator<ReadableProduct>() {
@Override
public int compare(ReadableProduct o1, ReadableProduct o2) {
int order1 = o1.getSortOrder();
int order2 = o2.getSortOrder();
return order1 - order2;
}
});
productList.setProductCount(Math.toIntExact(products.getTotalCount()));
if (CollectionUtils.isNotEmpty(prices)) {
BigDecimal minPrice = (BigDecimal) Collections.min(prices);
BigDecimal maxPrice = (BigDecimal) Collections.max(prices);
if (minPrice != null && maxPrice != null) {
productList.setMinPrice(minPrice);
productList.setMaxPrice(maxPrice);
}
}
return productList;
} catch (Exception e) {
LOGGER.error("Error while getting products", e);
response.sendError(503, "An error occured while retrieving products " + e.getMessage());
}
return null;
}
use of com.salesmanager.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.
the class ShoppingCartController method shoppingCart.
private String shoppingCart(final Model model, final HttpServletRequest request, final HttpServletResponse response, final Locale locale) throws Exception {
LOG.debug("Starting to calculate shopping cart...");
Language language = (Language) request.getAttribute(Constants.LANGUAGE);
// meta information
PageInformation pageInformation = new PageInformation();
pageInformation.setPageTitle(messages.getMessage("label.cart.placeorder", locale));
request.setAttribute(Constants.REQUEST_PAGE_INFORMATION, pageInformation);
MerchantStore store = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
Customer customer = getSessionAttribute(Constants.CUSTOMER, request);
/**
* there must be a cart in the session *
*/
String cartCode = (String) request.getSession().getAttribute(Constants.SHOPPING_CART);
if (StringUtils.isBlank(cartCode)) {
// display empty cart
StringBuilder template = new StringBuilder().append(ControllerConstants.Tiles.ShoppingCart.shoppingCart).append(".").append(store.getStoreTemplate());
return template.toString();
}
ShoppingCartData shoppingCart = shoppingCartFacade.getShoppingCartData(customer, store, cartCode, language);
if (shoppingCart == null) {
// display empty cart
StringBuilder template = new StringBuilder().append(ControllerConstants.Tiles.ShoppingCart.shoppingCart).append(".").append(store.getStoreTemplate());
return template.toString();
}
Language lang = languageUtils.getRequestLanguage(request, response);
// Filter unavailables
List<ShoppingCartItem> unavailables = new ArrayList<ShoppingCartItem>();
List<ShoppingCartItem> availables = new ArrayList<ShoppingCartItem>();
// Take out items no more available
List<ShoppingCartItem> items = shoppingCart.getShoppingCartItems();
for (ShoppingCartItem item : items) {
String code = item.getProductCode();
Product p = productService.getByCode(code, lang);
if (!p.isAvailable()) {
unavailables.add(item);
} else {
availables.add(item);
}
}
shoppingCart.setShoppingCartItems(availables);
shoppingCart.setUnavailables(unavailables);
model.addAttribute("cart", shoppingCart);
/**
* template *
*/
StringBuilder template = new StringBuilder().append(ControllerConstants.Tiles.ShoppingCart.shoppingCart).append(".").append(store.getStoreTemplate());
return template.toString();
}
use of com.salesmanager.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.
the class ShoppingCartController method removeShoppingCartItem.
/**
* Removes an item from the Shopping Cart (AJAX exposed method)
* @param request
* @param response
* @return
* @throws Exception
*/
@RequestMapping(value = { "/removeShoppingCartItem.html" }, method = { RequestMethod.GET, RequestMethod.POST })
String removeShoppingCartItem(final Long lineItemId, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
// Looks in the HttpSession to see if a customer is logged in
// get any shopping cart for this user
// ** need to check if the item has property, similar items may exist but with different properties
// String attributes = request.getParameter("attribute");//attributes id are sent as 1|2|5|
// this will help with hte removal of the appropriate item
// remove the item shoppingCartService.create
// create JSON representation of the shopping cart
// return the JSON structure in AjaxResponse
// store the shopping cart in the http session
MerchantStore store = getSessionAttribute(Constants.MERCHANT_STORE, request);
Language language = (Language) request.getAttribute(Constants.LANGUAGE);
Customer customer = getSessionAttribute(Constants.CUSTOMER, request);
/**
* there must be a cart in the session *
*/
String cartCode = (String) request.getSession().getAttribute(Constants.SHOPPING_CART);
if (StringUtils.isBlank(cartCode)) {
return "redirect:/shop";
}
ShoppingCartData shoppingCart = shoppingCartFacade.getShoppingCartData(customer, store, cartCode, language);
ShoppingCartData shoppingCartData = shoppingCartFacade.removeCartItem(lineItemId, shoppingCart.getCode(), store, language);
if (shoppingCartData == null) {
return "redirect:/shop";
}
if (CollectionUtils.isEmpty(shoppingCartData.getShoppingCartItems())) {
shoppingCartFacade.deleteShoppingCart(shoppingCartData.getId(), store);
return "redirect:/shop";
}
return Constants.REDIRECT_PREFIX + "/shop/cart/shoppingCart.html";
}
use of com.salesmanager.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.
the class ShoppingCartController method addShoppingCartItem.
/**
* Add an item to the ShoppingCart (AJAX exposed method)
* @param request
* @param response
* @return
* @throws Exception
*/
@RequestMapping(value = { "/addShoppingCartItem" }, method = RequestMethod.POST)
@ResponseBody
public ShoppingCartData addShoppingCartItem(@RequestBody final ShoppingCartItem item, final HttpServletRequest request, final HttpServletResponse response, final Locale locale) throws Exception {
ShoppingCartData shoppingCart = null;
// Look in the HttpSession to see if a customer is logged in
MerchantStore store = getSessionAttribute(Constants.MERCHANT_STORE, request);
Language language = (Language) request.getAttribute(Constants.LANGUAGE);
Customer customer = getSessionAttribute(Constants.CUSTOMER, request);
if (customer != null) {
com.salesmanager.core.model.shoppingcart.ShoppingCart customerCart = shoppingCartService.getShoppingCart(customer);
if (customerCart != null) {
// if this cart has been fulfilled create a new cart
if (customerCart.getOrderId() != null && customerCart.getOrderId().longValue() > 0) {
customerCart = shoppingCartFacade.createCartModel(null, store, customer);
// set new shopping cart code to item
item.setCode(customerCart.getShoppingCartCode());
}
shoppingCart = shoppingCartFacade.getShoppingCartData(customerCart, language);
} else {
/**
* BUG that used a previous customer cart
*/
item.setCode(null);
}
}
if (shoppingCart == null && !StringUtils.isBlank(item.getCode())) {
shoppingCart = shoppingCartFacade.getShoppingCartData(item.getCode(), store, language);
}
if (shoppingCart != null) {
if (shoppingCart.getOrderId() != null && shoppingCart.getOrderId().longValue() > 0) {
// has been ordered, can't continue to use
shoppingCart = null;
}
}
// if shoppingCart is null create a new one
if (shoppingCart == null) {
shoppingCart = new ShoppingCartData();
String code = UUID.randomUUID().toString().replaceAll("-", "");
shoppingCart.setCode(code);
item.setCode(code);
}
shoppingCart = shoppingCartFacade.addItemsToShoppingCart(shoppingCart, item, store, language, customer);
request.getSession().setAttribute(Constants.SHOPPING_CART, shoppingCart.getCode());
return shoppingCart;
}
Aggregations