第 1 步:导入 impex 以启用价格排序选项
如果您推荐任何 OOTB 商店 (apparelstore),您可以在 Impex 中看到价格排序 (price-asc) 选项。我在下面突出显示了 Impex。
第 2 步:对匿名用户隐藏
在匿名用户的情况下不要呈现价格排序。正如我在下面提到的,您可以借助 JSTL 条件来检查。
请注意:以下代码仅供参考,我没有测试过
orderFormPagination.tag
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>
<c:set var="isLoggedInUser" value="false" />
<sec:authorize ifNotGranted="ROLE_ANONYMOUS">
<c:set var="isLoggedInUser" value="true" />
</sec:authorize>
<select id="sortOptions${top ? '1' : '2'}" name="sort" class="form-control">
<option disabled><spring:theme
code="${themeMsgKey}.sortTitle" /></option>
<c:forEach items="${searchPageData.sorts}" var="sort">
<c:if test="${isLoggedInUser || (!isLoggedInUser && !fn:startsWith(sort.code, 'price'))}">
<option value="${sort.code}"
${sort.selected? 'selected="selected"' : ''}>
<c:choose>
<c:when test="${not empty sort.name}">
${sort.name}
</c:when>
<c:otherwise>
<spring:theme code="${themeMsgKey}.sort.${sort.code}" />
</c:otherwise>
</c:choose>
</option>
</c:if>
</c:forEach>
</select>
Impex
定义 SolrIndexedProperty
INSERT_UPDATE SolrIndexedProperty ; solrIndexedType(identifier)[unique=true] ; name[unique=true] ; type(code) ; sortableType(code) ; currency[default=false] ; localized[default=false] ; multiValue[default=false] ; useForSpellchecking[default=false] ; useForAutocomplete[default=false] ; fieldValueProvider ; ftsPhraseQuery[default=false] ; ftsPhraseQueryBoost ; ftsQuery[default=false] ; ftsQueryBoost ; ftsFuzzyQuery[default=false] ; ftsFuzzyQueryBoost ; ftsWildcardQuery[default=false] ; ftsWildcardQueryType(code)[default=POSTFIX] ; ftsWildcardQueryBoost ; ftsWildcardQueryMinTermLength
; $solrIndexedType ; name ; text ; sortabletext ; ; true ; ; true ; true ; ; true ; 100 ; true ; 50 ; true ; 25 ; ; ; ;
; $solrIndexedType ; priceValue ; double ; ; true ; ; ; ; ; productPriceValueProvider ; ; ; ; ; ; ; ; ; ;
定义可用的排序
INSERT_UPDATE SolrSort ; &sortRefID ; indexedType(identifier)[unique=true] ; code[unique=true] ; useBoost
; sortRef3 ; $solrIndexedType ; name-asc ; false
; sortRef4 ; $solrIndexedType ; name-desc ; false
; sortRef5 ; $solrIndexedType ; price-asc ; false
; sortRef6 ; $solrIndexedType ; price-desc ; false
定义排序字段
INSERT_UPDATE SolrSortField ; sort(indexedType(identifier),code)[unique=true] ; fieldName[unique=true] ; ascending[unique=true]
; $solrIndexedType:name-asc ; name ; true
; $solrIndexedType:name-desc ; name ; false
; $solrIndexedType:price-asc ; priceValue ; true
; $solrIndexedType:price-desc ; priceValue ; false
更新索引类型产品中的排序选项
INSERT_UPDATE SolrIndexedType ; identifier[unique=true] ; type(code) ; variant ; sorts(&sortRefID)
; $solrIndexedType ; Product ; false ; sortRef3,sortRef4,sortRef5,sortRef6