예제 #1
0
  @Override
  public void doTag() throws JspException, IOException {
    final boolean enabled = Config.getBoolean(ENABLE_TEST_IDS_PROPERTY, false);
    if (enabled) {
      final PageContext pageContext = (PageContext) getJspContext();
      final JspWriter jspWriter = pageContext.getOut();

      final int nextUniqueId = getNextUniqueId(pageContext);

      jspWriter
          .append("<div id=\"")
          .append("test_")
          .append(cleanupHtmlId(getCode()))
          .append("_$")
          .append(String.valueOf(nextUniqueId))
          .append("\" style=\"display:inline\">");

      // Write the body out
      getJspBody().invoke(jspWriter);

      jspWriter.println("</div>");
    } else {
      // Just render the contents
      getJspBody().invoke(getJspContext().getOut());
    }
  }
  @Override
  public void beforeView(
      final HttpServletRequest request,
      final HttpServletResponse response,
      final ModelAndView modelAndView) {
    final boolean showDebug = Config.getBoolean(SHOW_STOREFRONT_DEBUG_INFO_PROPERTY_KEY, false);

    // Store the show debug flag in a request attribute
    request.setAttribute(SHOW_STOREFRONT_DEBUG_INFO, Boolean.valueOf(showDebug));

    if (showDebug) {
      final JaloSession currentSession = JaloSession.getCurrentSession();

      final TreeMap<String, Object> attributeMap = new TreeMap<String, Object>();
      // Build up the session attributes as a request attribute
      attributeMap.putAll(currentSession.getAttributes());
      // Add the session id as an attribute
      attributeMap.put("JaloSession ID", currentSession.getSessionID());

      request.setAttribute(JALO_SESSION_ATTRIBUTES, mapToString(attributeMap));
    }
  }
예제 #3
0
  @RequestMapping(value = "/advanced", method = RequestMethod.GET)
  public String advanceSearchResults(
      @RequestParam(value = "keywords", required = false, defaultValue = StringUtils.EMPTY)
          String keywords,
      @RequestParam(
              value = "searchResultType",
              required = false,
              defaultValue = ADVANCED_SEARCH_RESULT_TYPE_CATALOG)
          final String searchResultType,
      @RequestParam(value = "inStockOnly", required = false, defaultValue = "false")
          final boolean inStockOnly,
      @RequestParam(value = "onlyProductIds", required = false, defaultValue = "false")
          final boolean onlyProductIds,
      @RequestParam(value = "isCreateOrderForm", required = false, defaultValue = "false")
          final boolean isCreateOrderForm,
      @RequestParam(value = "q", defaultValue = StringUtils.EMPTY) String searchQuery,
      @RequestParam(value = "page", defaultValue = "0") final int page,
      @RequestParam(value = "show", defaultValue = "Page") final ShowMode showMode,
      @RequestParam(value = "sort", required = false) final String sortCode,
      final Model model)
      throws CMSItemNotFoundException {

    if (StringUtils.isNotBlank(keywords)) {
      searchQuery = keywords;
    } else {
      if (StringUtils.isNotBlank(searchQuery)) {
        keywords = StringUtils.split(searchQuery, ":")[0];
      }
    }

    // check if it is order form (either order form was selected or "Create Order Form"
    final PageableData pageableData =
        createPageableData(page, getSearchPageSize(), sortCode, showMode);
    final SearchStateData searchState =
        createSearchStateData(searchQuery, isPopulateVariants(searchResultType, isCreateOrderForm));

    final SearchPageData<ProductData> searchPageData =
        performSearch(
            searchState, pageableData, isUseFlexibleSearch(onlyProductIds, isCreateOrderForm));
    populateModel(model, searchPageData, showMode);

    String metaInfoText = null;
    if (StringUtils.isEmpty(keywords)) {
      metaInfoText =
          MetaSanitizerUtil.sanitizeDescription(
              getMessageSource()
                  .getMessage("search.advanced.meta.description.title", null, getCurrentLocale()));
    } else {
      metaInfoText = MetaSanitizerUtil.sanitizeDescription(keywords);
    }

    model.addAttribute(
        WebConstants.BREADCRUMBS_KEY,
        searchBreadcrumbBuilder.getBreadcrumbs(null, metaInfoText, false));

    final AdvancedSearchForm form = new AdvancedSearchForm();
    form.setOnlyProductIds(Boolean.valueOf(onlyProductIds));
    form.setInStockOnly(Boolean.valueOf(inStockOnly));
    form.setKeywords(keywords);
    form.setCreateOrderForm(isCreateOrderForm);

    if (isCreateOrderForm) {
      form.setSearchResultType(ADVANCED_SEARCH_RESULT_TYPE_ORDER_FORM);
      final List<String> filterSkus = splitSkusAsList(keywords);
      form.setFilterSkus(filterSkus);
      form.setCreateOrderForm(Boolean.valueOf(false));
      form.setOnlyProductIds(Boolean.valueOf(true));
    } else {
      form.setSearchResultType(searchResultType);
    }

    model.addAttribute("advancedSearchForm", form);
    model.addAttribute(
        "futureStockEnabled", Boolean.valueOf(Config.getBoolean(FUTURE_STOCK_ENABLED, false)));

    storeCmsPageInModel(model, getContentPageForLabelOrId(NO_RESULTS_ADVANCED_PAGE_ID));

    addMetaData(
        model,
        "search.meta.description.results",
        metaInfoText,
        "search.meta.description.on",
        PageType.PRODUCTSEARCH,
        "no-index,follow");

    return getViewForPage(model);
  }