Search in sources :

Example 11 with Language

use of com.salesmanager.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.

the class CustomerAccountController method updateCustomerAddress.

@PreAuthorize("hasRole('AUTH_CUSTOMER')")
@RequestMapping(value = "/updateAddress.html", method = { RequestMethod.GET, RequestMethod.POST })
public String updateCustomerAddress(@Valid @ModelAttribute("address") Address address, BindingResult bindingResult, final Model model, final HttpServletRequest request, @RequestParam(value = "billingAddress", required = false) Boolean billingAddress) throws Exception {
    MerchantStore store = getSessionAttribute(Constants.MERCHANT_STORE, request);
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    Customer customer = null;
    if (auth != null && request.isUserInRole("AUTH_CUSTOMER")) {
        customer = customerFacade.getCustomerByUserName(auth.getName(), store);
    }
    StringBuilder template = new StringBuilder().append(ControllerConstants.Tiles.Customer.EditAddress).append(".").append(store.getStoreTemplate());
    if (customer == null) {
        return "redirect:/" + Constants.SHOP_URI;
    }
    model.addAttribute("address", address);
    model.addAttribute("customerId", customer.getId());
    if (bindingResult.hasErrors()) {
        LOGGER.info("found {} error(s) while validating  customer address ", bindingResult.getErrorCount());
        return template.toString();
    }
    Language language = getSessionAttribute(Constants.LANGUAGE, request);
    customerFacade.updateAddress(customer.getId(), store, address, language);
    Customer c = customerService.getById(customer.getId());
    super.setSessionAttribute(Constants.CUSTOMER, c, request);
    model.addAttribute("success", "success");
    return template.toString();
}
Also used : Language(com.salesmanager.core.model.reference.language.Language) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) Customer(com.salesmanager.core.model.customer.Customer) Authentication(org.springframework.security.core.Authentication) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with Language

use of com.salesmanager.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.

the class CustomerAccountController method displayCustomerBillingAddress.

@PreAuthorize("hasRole('AUTH_CUSTOMER')")
// @Secured("AUTH_CUSTOMER")
@RequestMapping(value = "/billing.html", method = RequestMethod.GET)
public String displayCustomerBillingAddress(Model model, HttpServletRequest request, HttpServletResponse response) throws Exception {
    MerchantStore store = getSessionAttribute(Constants.MERCHANT_STORE, request);
    Language language = getSessionAttribute(Constants.LANGUAGE, request);
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    Customer customer = null;
    if (auth != null && request.isUserInRole("AUTH_CUSTOMER")) {
        customer = customerFacade.getCustomerByUserName(auth.getName(), store);
    }
    if (customer == null) {
        return "redirect:/" + Constants.SHOP_URI;
    }
    CustomerEntity customerEntity = customerFacade.getCustomerDataByUserName(customer.getNick(), store, language);
    if (customer != null) {
        model.addAttribute("customer", customerEntity);
    }
    /**
     * template *
     */
    StringBuilder template = new StringBuilder().append(ControllerConstants.Tiles.Customer.Billing).append(".").append(store.getStoreTemplate());
    return template.toString();
}
Also used : Language(com.salesmanager.core.model.reference.language.Language) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) Customer(com.salesmanager.core.model.customer.Customer) Authentication(org.springframework.security.core.Authentication) CustomerEntity(com.salesmanager.shop.model.customer.CustomerEntity) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with Language

use of com.salesmanager.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.

the class CustomerOrdersController method orderDetails.

@PreAuthorize("hasRole('AUTH_CUSTOMER')")
@RequestMapping(value = "/order.html", method = { RequestMethod.GET, RequestMethod.POST })
public String orderDetails(final Model model, final HttpServletRequest request, @RequestParam(value = "orderId", required = true) final String orderId) throws Exception {
    MerchantStore store = getSessionAttribute(Constants.MERCHANT_STORE, request);
    Language language = (Language) request.getAttribute(Constants.LANGUAGE);
    if (StringUtils.isBlank(orderId)) {
        LOGGER.error("Order Id can not be null or empty");
    }
    LOGGER.info("Fetching order details for Id " + orderId);
    // get order id
    Long lOrderId = null;
    try {
        lOrderId = Long.parseLong(orderId);
    } catch (NumberFormatException nfe) {
        LOGGER.error("Cannot parse orderId to long " + orderId);
        return "redirect:/" + Constants.SHOP_URI;
    }
    // check if order belongs to customer logged in
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    Customer customer = null;
    if (auth != null && request.isUserInRole("AUTH_CUSTOMER")) {
        customer = customerFacade.getCustomerByUserName(auth.getName(), store);
    }
    if (customer == null) {
        return "redirect:/" + Constants.SHOP_URI;
    }
    ReadableOrder order = orderFacade.getReadableOrder(lOrderId, store, customer.getDefaultLanguage());
    model.addAttribute("order", order);
    // check if any downloads exist for this order
    List<OrderProductDownload> orderProductDownloads = orderProdctDownloadService.getByOrderId(order.getId());
    if (CollectionUtils.isNotEmpty(orderProductDownloads)) {
        ReadableOrderProductDownloadPopulator populator = new ReadableOrderProductDownloadPopulator();
        List<ReadableOrderProductDownload> downloads = new ArrayList<ReadableOrderProductDownload>();
        for (OrderProductDownload download : orderProductDownloads) {
            ReadableOrderProductDownload view = new ReadableOrderProductDownload();
            populator.populate(download, view, store, language);
            downloads.add(view);
        }
        model.addAttribute("downloads", downloads);
    }
    StringBuilder template = new StringBuilder().append(ControllerConstants.Tiles.Customer.customerOrder).append(".").append(store.getStoreTemplate());
    return template.toString();
}
Also used : ReadableOrderProductDownloadPopulator(com.salesmanager.shop.populator.order.ReadableOrderProductDownloadPopulator) Customer(com.salesmanager.core.model.customer.Customer) ReadableOrderProductDownload(com.salesmanager.shop.model.order.ReadableOrderProductDownload) ArrayList(java.util.ArrayList) ReadableOrder(com.salesmanager.shop.model.order.v0.ReadableOrder) Language(com.salesmanager.core.model.reference.language.Language) Authentication(org.springframework.security.core.Authentication) OrderProductDownload(com.salesmanager.core.model.order.orderproduct.OrderProductDownload) ReadableOrderProductDownload(com.salesmanager.shop.model.order.ReadableOrderProductDownload) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with Language

use of com.salesmanager.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.

the class LandingController method displayLanding.

@RequestMapping(value = { Constants.SHOP_URI + "/home.html", Constants.SHOP_URI + "/", Constants.SHOP_URI }, method = RequestMethod.GET)
public String displayLanding(Model model, HttpServletRequest request, HttpServletResponse response, Locale locale) throws Exception {
    Language language = (Language) request.getAttribute(Constants.LANGUAGE);
    MerchantStore store = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
    request.setAttribute(Constants.LINK_CODE, HOME_LINK_CODE);
    Content content = contentService.getByCode(LANDING_PAGE, store, language);
    /**
     * Rebuild breadcrumb *
     */
    BreadcrumbItem item = new BreadcrumbItem();
    item.setItemType(BreadcrumbItemType.HOME);
    item.setLabel(messages.getMessage(Constants.HOME_MENU_KEY, locale));
    item.setUrl(Constants.HOME_URL);
    Breadcrumb breadCrumb = new Breadcrumb();
    breadCrumb.setLanguage(language);
    List<BreadcrumbItem> items = new ArrayList<BreadcrumbItem>();
    items.add(item);
    breadCrumb.setBreadCrumbs(items);
    request.getSession().setAttribute(Constants.BREADCRUMB, breadCrumb);
    request.setAttribute(Constants.BREADCRUMB, breadCrumb);
    if (content != null) {
        ContentDescription description = content.getDescription();
        model.addAttribute("page", description);
        PageInformation pageInformation = new PageInformation();
        pageInformation.setPageTitle(description.getName());
        pageInformation.setPageDescription(description.getMetatagDescription());
        pageInformation.setPageKeywords(description.getMetatagKeywords());
        request.setAttribute(Constants.REQUEST_PAGE_INFORMATION, pageInformation);
    }
    ReadableProductPopulator populator = new ReadableProductPopulator();
    populator.setPricingService(pricingService);
    populator.setimageUtils(imageUtils);
    // featured items
    List<ProductRelationship> relationships = productRelationshipService.getByType(store, ProductRelationshipType.FEATURED_ITEM, language);
    List<ReadableProduct> featuredItems = new ArrayList<ReadableProduct>();
    Date today = new Date();
    for (ProductRelationship relationship : relationships) {
        Product product = relationship.getRelatedProduct();
        if (product.isAvailable() && DateUtil.dateBeforeEqualsDate(product.getDateAvailable(), today)) {
            ReadableProduct proxyProduct = populator.populate(product, new ReadableProduct(), store, language);
            featuredItems.add(proxyProduct);
        }
    }
    String tmpl = store.getStoreTemplate();
    if (StringUtils.isBlank(tmpl)) {
        tmpl = "generic";
    }
    model.addAttribute("featuredItems", featuredItems);
    /**
     * template *
     */
    StringBuilder template = new StringBuilder().append("landing.").append(tmpl);
    return template.toString();
}
Also used : BreadcrumbItem(com.salesmanager.shop.model.shop.BreadcrumbItem) ArrayList(java.util.ArrayList) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) Breadcrumb(com.salesmanager.shop.model.shop.Breadcrumb) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Date(java.util.Date) Language(com.salesmanager.core.model.reference.language.Language) PageInformation(com.salesmanager.shop.model.shop.PageInformation) ReadableProductPopulator(com.salesmanager.shop.populator.catalog.ReadableProductPopulator) ProductRelationship(com.salesmanager.core.model.catalog.product.relationship.ProductRelationship) Content(com.salesmanager.core.model.content.Content) ContentDescription(com.salesmanager.core.model.content.ContentDescription) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with Language

use of com.salesmanager.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.

the class CustomerLoginController method logon.

private AjaxResponse logon(String userName, String password, String storeCode, HttpServletRequest request, HttpServletResponse response) throws Exception {
    AjaxResponse jsonObject = new AjaxResponse();
    try {
        LOG.debug("Authenticating user " + userName);
        // user goes to shop filter first so store and language are set
        MerchantStore store = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
        Language language = (Language) request.getAttribute("LANGUAGE");
        // check if username is from the appropriate store
        Customer customerModel = customerFacade.getCustomerByUserName(userName, store);
        if (customerModel == null) {
            jsonObject.setStatus(AjaxResponse.RESPONSE_STATUS_FAIURE);
            return jsonObject;
        }
        if (!customerModel.getMerchantStore().getCode().equals(storeCode)) {
            jsonObject.setStatus(AjaxResponse.RESPONSE_STATUS_FAIURE);
            return jsonObject;
        }
        customerFacade.authenticate(customerModel, userName, password);
        // set customer in the http session
        super.setSessionAttribute(Constants.CUSTOMER, customerModel, request);
        jsonObject.setStatus(AjaxResponse.RESPONSE_STATUS_SUCCESS);
        jsonObject.addEntry(Constants.RESPONSE_KEY_USERNAME, customerModel.getNick());
        LOG.info("Fetching and merging Shopping Cart data");
        String sessionShoppingCartCode = (String) request.getSession().getAttribute(Constants.SHOPPING_CART);
        if (!StringUtils.isBlank(sessionShoppingCartCode)) {
            ShoppingCart shoppingCart = customerFacade.mergeCart(customerModel, sessionShoppingCartCode, store, language);
            if (shoppingCart != null) {
                ShoppingCartData shoppingCartData = this.populateShoppingCartData(shoppingCart, store, language);
                if (shoppingCartData != null) {
                    jsonObject.addEntry(Constants.SHOPPING_CART, shoppingCartData.getCode());
                    request.getSession().setAttribute(Constants.SHOPPING_CART, shoppingCartData.getCode());
                    // set cart in the cookie
                    Cookie c = new Cookie(Constants.COOKIE_NAME_CART, shoppingCartData.getCode());
                    c.setMaxAge(60 * 24 * 3600);
                    c.setPath(Constants.SLASH);
                    response.addCookie(c);
                } else {
                    // DELETE COOKIE
                    Cookie c = new Cookie(Constants.COOKIE_NAME_CART, "");
                    c.setMaxAge(0);
                    c.setPath(Constants.SLASH);
                    response.addCookie(c);
                }
            }
        } else {
            ShoppingCart cartModel = shoppingCartService.getShoppingCart(customerModel);
            if (cartModel != null) {
                jsonObject.addEntry(Constants.SHOPPING_CART, cartModel.getShoppingCartCode());
                request.getSession().setAttribute(Constants.SHOPPING_CART, cartModel.getShoppingCartCode());
                Cookie c = new Cookie(Constants.COOKIE_NAME_CART, cartModel.getShoppingCartCode());
                c.setMaxAge(60 * 24 * 3600);
                c.setPath(Constants.SLASH);
                response.addCookie(c);
            }
        }
        StringBuilder cookieValue = new StringBuilder();
        cookieValue.append(store.getCode()).append("_").append(customerModel.getNick());
        // set username in the cookie
        Cookie c = new Cookie(Constants.COOKIE_NAME_USER, cookieValue.toString());
        c.setMaxAge(60 * 24 * 3600);
        c.setPath(Constants.SLASH);
        response.addCookie(c);
    } catch (AuthenticationException ex) {
        jsonObject.setStatus(AjaxResponse.RESPONSE_STATUS_FAIURE);
    } catch (Exception e) {
        jsonObject.setStatus(AjaxResponse.RESPONSE_STATUS_FAIURE);
    }
    return jsonObject;
}
Also used : Cookie(javax.servlet.http.Cookie) Language(com.salesmanager.core.model.reference.language.Language) ShoppingCart(com.salesmanager.core.model.shoppingcart.ShoppingCart) Customer(com.salesmanager.core.model.customer.Customer) SecuredCustomer(com.salesmanager.shop.model.customer.SecuredCustomer) AuthenticationException(org.springframework.security.core.AuthenticationException) AjaxResponse(com.salesmanager.core.business.utils.ajax.AjaxResponse) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ShoppingCartData(com.salesmanager.shop.model.shoppingcart.ShoppingCartData) AuthenticationException(org.springframework.security.core.AuthenticationException) ConversionException(com.salesmanager.core.business.exception.ConversionException)

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