use of com.salesmanager.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.
the class ShoppingCartController method displayShoppingCart.
@RequestMapping(value = { "/shoppingCartByCode" }, method = { RequestMethod.GET })
public String displayShoppingCart(@ModelAttribute String shoppingCartCode, final Model model, HttpServletRequest request, HttpServletResponse response, final Locale locale) throws Exception {
MerchantStore merchantStore = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
Customer customer = getSessionAttribute(Constants.CUSTOMER, request);
Language language = (Language) request.getAttribute(Constants.LANGUAGE);
if (StringUtils.isBlank(shoppingCartCode)) {
return "redirect:/shop";
}
ShoppingCartData cart = shoppingCartFacade.getShoppingCartData(customer, merchantStore, shoppingCartCode, language);
if (cart == null) {
return "redirect:/shop";
}
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 = cart.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);
}
}
cart.setShoppingCartItems(availables);
cart.setUnavailables(unavailables);
// meta information
PageInformation pageInformation = new PageInformation();
pageInformation.setPageTitle(messages.getMessage("label.cart.placeorder", locale));
request.setAttribute(Constants.REQUEST_PAGE_INFORMATION, pageInformation);
request.getSession().setAttribute(Constants.SHOPPING_CART, cart.getCode());
model.addAttribute("cart", cart);
/**
* template *
*/
StringBuilder template = new StringBuilder().append(ControllerConstants.Tiles.ShoppingCart.shoppingCart).append(".").append(merchantStore.getStoreTemplate());
return template.toString();
}
use of com.salesmanager.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.
the class MiniCartController method removeShoppingCartItem.
@RequestMapping(value = { "/removeMiniShoppingCartItem" }, method = { RequestMethod.GET, RequestMethod.POST })
@ResponseBody
public ShoppingCartData removeShoppingCartItem(Long lineItemId, final String shoppingCartCode, HttpServletRequest request, Model model) throws Exception {
Language language = (Language) request.getAttribute(Constants.LANGUAGE);
MerchantStore merchantStore = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
ShoppingCartData cart = shoppingCartFacade.getShoppingCartData(null, merchantStore, shoppingCartCode, language);
if (cart == null) {
return null;
}
ShoppingCartData shoppingCartData = shoppingCartFacade.removeCartItem(lineItemId, cart.getCode(), merchantStore, language);
if (shoppingCartData == null) {
return null;
}
if (CollectionUtils.isEmpty(shoppingCartData.getShoppingCartItems())) {
shoppingCartFacade.deleteShoppingCart(shoppingCartData.getId(), merchantStore);
request.getSession().removeAttribute(Constants.SHOPPING_CART);
return null;
}
request.getSession().setAttribute(Constants.SHOPPING_CART, cart.getCode());
LOG.debug("removed item" + lineItemId + "from cart");
return shoppingCartData;
}
use of com.salesmanager.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.
the class MiniCartController method displayMiniCart.
@RequestMapping(value = { "/displayMiniCartByCode" }, method = { RequestMethod.GET, RequestMethod.POST })
@ResponseBody
public ShoppingCartData displayMiniCart(final String shoppingCartCode, HttpServletRequest request, Model model) {
Language language = (Language) request.getAttribute(Constants.LANGUAGE);
try {
MerchantStore merchantStore = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
Customer customer = getSessionAttribute(Constants.CUSTOMER, request);
ShoppingCartData cart = shoppingCartFacade.getShoppingCartData(customer, merchantStore, shoppingCartCode, language);
if (cart != null) {
request.getSession().setAttribute(Constants.SHOPPING_CART, cart.getCode());
} else {
// make sure there is no cart here
request.getSession().removeAttribute(Constants.SHOPPING_CART);
// create an empty cart
cart = new ShoppingCartData();
}
return cart;
} catch (Exception e) {
LOG.error("Error while getting the shopping cart", e);
}
return null;
}
use of com.salesmanager.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.
the class StoreFilter method getContentPagesNames.
private Map<String, List<ContentDescription>> getContentPagesNames(MerchantStore store, Language language) throws Exception {
Map<String, List<ContentDescription>> contents = new ConcurrentHashMap<String, List<ContentDescription>>();
// Get boxes and sections from the database
List<ContentType> contentTypes = new ArrayList<ContentType>();
contentTypes.add(ContentType.PAGE);
List<ContentDescription> contentPages = contentService.listNameByType(contentTypes, store, language);
if (contentPages != null && contentPages.size() > 0) {
// create a Map<String,List<Content>
for (ContentDescription content : contentPages) {
Language lang = language;
String key = new StringBuilder().append(store.getId()).append("_").append(Constants.CONTENT_PAGE_CACHE_KEY).append("-").append(lang.getCode()).toString();
List<ContentDescription> contentList = null;
if (contents == null || contents.size() == 0) {
contents = new HashMap<String, List<ContentDescription>>();
}
if (!contents.containsKey(key)) {
contentList = new ArrayList<ContentDescription>();
contents.put(key, contentList);
} else {
// get from key
contentList = contents.get(key);
if (contentList == null) {
LOGGER.error("Cannot find content key in cache " + key);
continue;
}
}
contentList.add(content);
}
}
return contents;
}
use of com.salesmanager.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.
the class StoreFilter method getContent.
private Map<String, List<Content>> getContent(MerchantStore store, Language language) throws Exception {
Map<String, List<Content>> contents = new ConcurrentHashMap<String, List<Content>>();
// Get boxes and sections from the database
List<ContentType> contentTypes = new ArrayList<ContentType>();
contentTypes.add(ContentType.BOX);
contentTypes.add(ContentType.SECTION);
List<Content> contentPages = contentService.listByType(contentTypes, store, language);
if (contentPages != null && contentPages.size() > 0) {
// create a Map<String,List<Content>
for (Content content : contentPages) {
if (content.isVisible()) {
List<ContentDescription> descriptions = content.getDescriptions();
for (ContentDescription contentDescription : descriptions) {
Language lang = contentDescription.getLanguage();
String key = new StringBuilder().append(store.getId()).append("_").append(Constants.CONTENT_CACHE_KEY).append("-").append(lang.getCode()).toString();
List<Content> contentList = null;
if (contents == null || contents.size() == 0) {
contents = new HashMap<String, List<Content>>();
}
if (!contents.containsKey(key)) {
contentList = new ArrayList<Content>();
contents.put(key, contentList);
} else {
// get from key
contentList = contents.get(key);
if (contentList == null) {
LOGGER.error("Cannot find content key in cache " + key);
continue;
}
}
contentList.add(content);
}
}
}
}
return contents;
}
Aggregations