Search in sources :

Example 21 with Language

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();
}
Also used : Language(com.salesmanager.core.model.reference.language.Language) Customer(com.salesmanager.core.model.customer.Customer) PageInformation(com.salesmanager.shop.model.shop.PageInformation) ArrayList(java.util.ArrayList) Product(com.salesmanager.core.model.catalog.product.Product) ShoppingCartItem(com.salesmanager.shop.model.shoppingcart.ShoppingCartItem) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ShoppingCartData(com.salesmanager.shop.model.shoppingcart.ShoppingCartData) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 22 with Language

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;
}
Also used : Language(com.salesmanager.core.model.reference.language.Language) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ShoppingCartData(com.salesmanager.shop.model.shoppingcart.ShoppingCartData) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 23 with Language

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;
}
Also used : Language(com.salesmanager.core.model.reference.language.Language) Customer(com.salesmanager.core.model.customer.Customer) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ShoppingCartData(com.salesmanager.shop.model.shoppingcart.ShoppingCartData) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 24 with Language

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;
}
Also used : ContentType(com.salesmanager.core.model.content.ContentType) Language(com.salesmanager.core.model.reference.language.Language) ContentDescription(com.salesmanager.core.model.content.ContentDescription) ReadableCategoryList(com.salesmanager.shop.model.catalog.category.ReadableCategoryList) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 25 with Language

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;
}
Also used : ContentType(com.salesmanager.core.model.content.ContentType) Language(com.salesmanager.core.model.reference.language.Language) Content(com.salesmanager.core.model.content.Content) ContentDescription(com.salesmanager.core.model.content.ContentDescription) ReadableCategoryList(com.salesmanager.shop.model.catalog.category.ReadableCategoryList) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

Language (com.salesmanager.core.model.reference.language.Language)148 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)115 ArrayList (java.util.ArrayList)58 List (java.util.List)56 ServiceException (com.salesmanager.core.business.exception.ServiceException)55 Collectors (java.util.stream.Collectors)50 Product (com.salesmanager.core.model.catalog.product.Product)45 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)44 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)42 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)38 Autowired (org.springframework.beans.factory.annotation.Autowired)35 ConversionException (com.salesmanager.core.business.exception.ConversionException)30 Category (com.salesmanager.core.model.catalog.category.Category)30 Validate (org.apache.commons.lang3.Validate)29 Customer (com.salesmanager.core.model.customer.Customer)28 Optional (java.util.Optional)28 Inject (javax.inject.Inject)28 Service (org.springframework.stereotype.Service)28 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)27 ImageFilePath (com.salesmanager.shop.utils.ImageFilePath)25