Search in sources :

Example 1 with PageInformation

use of com.salesmanager.shop.model.shop.PageInformation in project shopizer by shopizer-ecommerce.

the class ListItemsController method displayListingPage.

@RequestMapping("/shop/listing/{url}.html")
public String displayListingPage(@PathVariable String url, Model model, HttpServletRequest request, HttpServletResponse response, Locale locale) throws Exception {
    MerchantStore store = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
    Language language = (Language) request.getAttribute("LANGUAGE");
    // Manufacturer manufacturer = manufacturerService.getByUrl(store, language, url); // this needs to be checked
    Manufacturer manufacturer = null;
    if (manufacturer == null) {
        LOGGER.error("No manufacturer found for url " + url);
        // redirect on page not found
        return PageBuilderUtils.build404(store);
    }
    ReadableManufacturer readableManufacturer = new ReadableManufacturer();
    ReadableManufacturerPopulator populator = new ReadableManufacturerPopulator();
    readableManufacturer = populator.populate(manufacturer, readableManufacturer, store, language);
    // meta information
    PageInformation pageInformation = new PageInformation();
    pageInformation.setPageDescription(readableManufacturer.getDescription().getMetaDescription());
    pageInformation.setPageKeywords(readableManufacturer.getDescription().getKeyWords());
    pageInformation.setPageTitle(readableManufacturer.getDescription().getTitle());
    pageInformation.setPageUrl(readableManufacturer.getDescription().getFriendlyUrl());
    model.addAttribute("manufacturer", readableManufacturer);
    /**
     * template *
     */
    StringBuilder template = new StringBuilder().append(ControllerConstants.Tiles.Items.items_manufacturer).append(".").append(store.getStoreTemplate());
    return template.toString();
}
Also used : ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) Language(com.salesmanager.core.model.reference.language.Language) PageInformation(com.salesmanager.shop.model.shop.PageInformation) ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) Manufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer) ReadableManufacturerPopulator(com.salesmanager.shop.populator.manufacturer.ReadableManufacturerPopulator) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with PageInformation

use of com.salesmanager.shop.model.shop.PageInformation 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 3 with PageInformation

use of com.salesmanager.shop.model.shop.PageInformation 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();
}
Also used : Language(com.salesmanager.core.model.reference.language.Language) PageInformation(com.salesmanager.shop.model.shop.PageInformation) Customer(com.salesmanager.core.model.customer.Customer) 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)

Example 4 with PageInformation

use of com.salesmanager.shop.model.shop.PageInformation 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 5 with PageInformation

use of com.salesmanager.shop.model.shop.PageInformation in project shopizer by shopizer-ecommerce.

the class StoreFilter method preHandle.

public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
    request.setCharacterEncoding("UTF-8");
    /**
     * if url contains /services exit from here !
     */
    if (request.getRequestURL().toString().toLowerCase().contains(SERVICES_URL_PATTERN) || request.getRequestURL().toString().toLowerCase().contains(REFERENCE_URL_PATTERN)) {
        return true;
    }
    try {
        /**
         * merchant store *
         */
        MerchantStore store = (MerchantStore) request.getSession().getAttribute(Constants.MERCHANT_STORE);
        String storeCode = request.getParameter(STORE_REQUEST_PARAMETER);
        // remove link set from controllers for declaring active - inactive
        // links
        request.removeAttribute(Constants.LINK_CODE);
        if (!StringUtils.isBlank(storeCode)) {
            if (store != null) {
                if (!store.getCode().equals(storeCode)) {
                    store = setMerchantStoreInSession(request, storeCode);
                }
            } else {
                // when url sm-shop/shop is being loaded for first time
                // store is null
                store = setMerchantStoreInSession(request, storeCode);
            }
        }
        if (store == null) {
            store = setMerchantStoreInSession(request, MerchantStore.DEFAULT_STORE);
        }
        if (StringUtils.isBlank(store.getStoreTemplate())) {
            store.setStoreTemplate(Constants.DEFAULT_TEMPLATE);
        }
        request.setAttribute(Constants.MERCHANT_STORE, store);
        /*
			//remote ip address
			String remoteAddress = "";
			try {
				
				if (request != null) {
					remoteAddress = request.getHeader("X-Forwarded-For");
					if (remoteAddress == null || "".equals(remoteAddress)) {
						remoteAddress = request.getRemoteAddr();
					}
				}
				remoteAddress = remoteAddress != null && remoteAddress.contains(",") ? remoteAddress.split(",")[0] : remoteAddress;
				LOGGER.info("remote ip addres {}", remoteAddress);
			} catch (Exception e) {
				LOGGER.error("Error while getting user remote address");
			}
			*/
        String ipAddress = GeoLocationUtils.getClientIpAddress(request);
        UserContext userContext = UserContext.create();
        userContext.setIpAddress(ipAddress);
        /**
         * customer *
         */
        Customer customer = (Customer) request.getSession().getAttribute(Constants.CUSTOMER);
        if (customer != null) {
            if (customer.getMerchantStore().getId().intValue() != store.getId().intValue()) {
                request.getSession().removeAttribute(Constants.CUSTOMER);
            }
            if (!customer.isAnonymous()) {
                if (!request.isUserInRole("AUTH_CUSTOMER")) {
                    request.removeAttribute(Constants.CUSTOMER);
                }
            }
            Authentication auth = SecurityContextHolder.getContext().getAuthentication();
            request.setAttribute(Constants.CUSTOMER, customer);
        }
        if (customer == null) {
            Authentication auth = SecurityContextHolder.getContext().getAuthentication();
            if (auth != null && request.isUserInRole("AUTH_CUSTOMER")) {
                customer = customerService.getByNick(auth.getName());
                if (customer != null) {
                    request.setAttribute(Constants.CUSTOMER, customer);
                }
            }
        }
        AnonymousCustomer anonymousCustomer = (AnonymousCustomer) request.getSession().getAttribute(Constants.ANONYMOUS_CUSTOMER);
        if (anonymousCustomer == null) {
            Address address = null;
            try {
                if (!StringUtils.isBlank(ipAddress)) {
                    com.salesmanager.core.model.common.Address geoAddress = customerService.getCustomerAddress(store, ipAddress);
                    if (geoAddress != null) {
                        address = new Address();
                        address.setCountry(geoAddress.getCountry());
                        address.setCity(geoAddress.getCity());
                        address.setZone(geoAddress.getZone());
                    /**
                     * no postal code *
                     */
                    // address.setPostalCode(geoAddress.getPostalCode());
                    }
                }
            } catch (Exception ce) {
                LOGGER.error("Cannot get geo ip component ", ce);
            }
            if (address == null) {
                address = new Address();
                address.setCountry(store.getCountry().getIsoCode());
                if (store.getZone() != null) {
                    address.setZone(store.getZone().getCode());
                } else {
                    address.setStateProvince(store.getStorestateprovince());
                }
            /**
             * no postal code *
             */
            // address.setPostalCode(store.getStorepostalcode());
            }
            anonymousCustomer = new AnonymousCustomer();
            anonymousCustomer.setBilling(address);
            request.getSession().setAttribute(Constants.ANONYMOUS_CUSTOMER, anonymousCustomer);
        } else {
            request.setAttribute(Constants.ANONYMOUS_CUSTOMER, anonymousCustomer);
        }
        /**
         * language & locale *
         */
        Language language = languageUtils.getRequestLanguage(request, response);
        request.setAttribute(Constants.LANGUAGE, language);
        Locale locale = languageService.toLocale(language, store);
        request.setAttribute(Constants.LOCALE, locale);
        // Locale locale = LocaleContextHolder.getLocale();
        LocaleContextHolder.setLocale(locale);
        /**
         * Breadcrumbs *
         */
        setBreadcrumb(request, locale);
        /**
         * Get global objects Themes are built on a similar way displaying
         * Header, Body and Footer Header and Footer are displayed on each
         * page Some themes also contain side bars which may include similar
         * emements
         *
         * Elements from Header : - CMS links - Customer - Mini shopping
         * cart - Store name / logo - Top categories - Search
         *
         * Elements from Footer : - CMS links - Store address - Global
         * payment information - Global shipping information
         */
        // get from the cache first
        /**
         * The cache for each object contains 2 objects, a Cache and a
         * Missed-Cache Get objects from the cache If not null use those
         * objects If null, get entry from missed-cache If missed-cache not
         * null then nothing exist If missed-cache null, add missed-cache
         * entry and load from the database If objects from database not
         * null store in cache
         */
        /**
         ***** CMS Objects *******
         */
        this.getContentObjects(store, language, request);
        /**
         ***** CMS Page names *********
         */
        this.getContentPageNames(store, language, request);
        /**
         ***** Top Categories *******
         */
        // this.getTopCategories(store, language, request);
        this.setTopCategories(store, language, request);
        /**
         ***** Default metatags ******
         */
        /**
         * Title Description Keywords
         */
        PageInformation pageInformation = new PageInformation();
        pageInformation.setPageTitle(store.getStorename());
        pageInformation.setPageDescription(store.getStorename());
        pageInformation.setPageKeywords(store.getStorename());
        @SuppressWarnings("unchecked") Map<String, ContentDescription> contents = (Map<String, ContentDescription>) request.getAttribute(Constants.REQUEST_CONTENT_OBJECTS);
        if (contents != null) {
            // for(String key : contents.keySet()) {
            // List<ContentDescription> contentsList = contents.get(key);
            // for(Content content : contentsList) {
            // if(key.equals(Constants.CONTENT_LANDING_PAGE)) {
            // List<ContentDescription> descriptions =
            // content.getDescriptions();
            ContentDescription contentDescription = contents.get(Constants.CONTENT_LANDING_PAGE);
            if (contentDescription != null) {
                // for(ContentDescription contentDescription : descriptions)
                // {
                // if(contentDescription.getLanguage().getCode().equals(language.getCode()))
                // {
                pageInformation.setPageTitle(contentDescription.getName());
                pageInformation.setPageDescription(contentDescription.getMetatagDescription());
                pageInformation.setPageKeywords(contentDescription.getMetatagKeywords());
            // }
            }
        // }
        // }
        // }
        }
        request.setAttribute(Constants.REQUEST_PAGE_INFORMATION, pageInformation);
        /**
         ***** Configuration objects ******
         */
        /**
         * SHOP configuration type Should contain - Different configuration
         * flags - Google analytics - Facebook page - Twitter handle - Show
         * customer login - ...
         */
        this.getMerchantConfigurations(store, request);
        /**
         ***** Shopping Cart ********
         */
        String shoppingCarCode = (String) request.getSession().getAttribute(Constants.SHOPPING_CART);
        if (shoppingCarCode != null) {
            request.setAttribute(Constants.REQUEST_SHOPPING_CART, shoppingCarCode);
        }
    } catch (Exception e) {
        LOGGER.error("Error in StoreFilter", e);
    }
    return true;
}
Also used : Address(com.salesmanager.shop.model.customer.address.Address) AnonymousCustomer(com.salesmanager.shop.model.customer.AnonymousCustomer) Customer(com.salesmanager.core.model.customer.Customer) UserContext(com.salesmanager.core.model.common.UserContext) AnonymousCustomer(com.salesmanager.shop.model.customer.AnonymousCustomer) Language(com.salesmanager.core.model.reference.language.Language) PageInformation(com.salesmanager.shop.model.shop.PageInformation) Authentication(org.springframework.security.core.Authentication) ContentDescription(com.salesmanager.core.model.content.ContentDescription) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)9 PageInformation (com.salesmanager.shop.model.shop.PageInformation)9 Language (com.salesmanager.core.model.reference.language.Language)8 ArrayList (java.util.ArrayList)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 Product (com.salesmanager.core.model.catalog.product.Product)4 ContentDescription (com.salesmanager.core.model.content.ContentDescription)4 Content (com.salesmanager.core.model.content.Content)3 Customer (com.salesmanager.core.model.customer.Customer)3 Breadcrumb (com.salesmanager.shop.model.shop.Breadcrumb)3 ReadableManufacturer (com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer)2 ReadableProduct (com.salesmanager.shop.model.catalog.product.ReadableProduct)2 ShoppingCartData (com.salesmanager.shop.model.shoppingcart.ShoppingCartData)2 ShoppingCartItem (com.salesmanager.shop.model.shoppingcart.ShoppingCartItem)2 ReadableProductPopulator (com.salesmanager.shop.populator.catalog.ReadableProductPopulator)2 Category (com.salesmanager.core.model.catalog.category.Category)1 ProductAttribute (com.salesmanager.core.model.catalog.product.attribute.ProductAttribute)1 ProductOptionValue (com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue)1 ProductOptionValueDescription (com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription)1 Manufacturer (com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer)1