10 Replies Latest reply: May 10, 2012 7:17 AM by Grando RSS

    Sort products by price

    Grando
      Hi,

      I have to sort a list of products by price (lowest and highest price).
      I read something about query docSort and modes, but I couldn't understand it.

      Someone can help me?

      Thanks a lot
        • 1. Re: Sort products by price
          Gurvinder
          You have to set the sorting in your QueryRequest to specify how you want to sort the results.
          Eg:
          setSorting(QueryRequest.Sorting.PROPERTY);
          setDocSort(QueryRequest.DocSort.FLOATPROP);
          setDocSortOrder(QueryRequest.DocSortOrder.ASCENDING);
          setDocSortProp("price");

          This will make your QueryRequest sort the search results by price ascending.
          DocSort will tell what type of property it is.
          DocSortOrder will tell which way you want to sort it, ascending or descending.
          DocSortProp will tell which property the sorting will work on.

          The docSort works on mode.
          You ll find a list of modes in the ATGSearchQuery documentation.
          The above example i gave of docSort works in conjunction with DocSortProp.

          A sorting by relevance would look something like below :

          setDocSort(QueryRequest.DocSort.RELEVANCE);
          setDocSortOrder(QueryRequest.DocSortOrder.DESCENDING);


          Thanks
          • 2. Re: Sort products by price
            Grando
            Hi,

            I did what you said, here is my code:
                 <c:set var="sortMorePrice" value="sortMorePrice" />
                 <option value="${sortMorePrice}" ${optionSelected==sortMorePrice ? 'selected="selected"' : ''}>
                      <fmt:message key="common.sortMorePrice" />
                 </option>
                 <c:if test="${isATGFacetSearch}">
                      <dsp:include page="sortGadget.jsp">
                           <dsp:param name="isATGFacetSearch" param="isATGFacetSearch" />
                           <dsp:param name="sortParam" value="price" />
                           <dsp:param name="sortTitle" value="common.sortMorePrice" />
                           <dsp:param name="sortProperties" value="floatprop" />
                           <dsp:param name="sortOrder" value="descending" />
                           <dsp:param name="sortId" value="${sortMorePrice}" />
                      </dsp:include>
                 </c:if>
            But it isn't works. I get no errors, but the sort by price is not working.

            Any help?

            Thanks
            • 3. Re: Sort products by price
              927261
              Can you paste your search request xml being generated.
              • 4. Re: Sort products by price
                Grando
                Here my request:
                /atg/dynamo/servlet/pipeline/RequestScopeManager/RequestScope-38/atg/commerce/search/catalog/QueryFormHandler     QueryString: q_docSort=price&q_docSortOrder=descending&q_pageNum=&viewAll=&q_pageSize=12&categoryId=catTableLamps&q_question=
                And here is my answer:
                /atg/dynamo/servlet/pipeline/RequestScopeManager/RequestScope-38/atg/commerce/search/catalog/QueryFormHandler     pSearchResponse:<answer printer="Java" contentID="91147d21-4ec5-497f-9653-0fa51f99e79e" id="0004760011" time="1336137588628" sorting="property" sortProp="string:$repositoryId:1" docSetSort="none" mode="and" strategy="normal" refineMax="35" refineMin="1" refineMinVal="2" refineTop="100" refineDebug="false" autospell="true" highlight="false" minScore="0" pageNum="0" pageSize="12" maxRelatedSets="0" docSortOrder="descending" docSortCase="true" docSortPropVal="first" responseCount="16" groupCount="16" docCand="16" docMax="16" docMin="16" ansCand="0" ansMax="0" ansMin="0" ansPool="0">
                I am using priceLists in my products.
                To order bvy AZ and ZA it is ok, but by price don't work.

                Any suggestions?

                Thanks
                • 5. Re: Sort products by price
                  Gurvinder
                  Can you go to /atg/search/routing/SearchEngineService
                  and click on Total Command Count under your search environment.

                  This will show up the search request and response.

                  Paste the complete request for your search.


                  Thanks
                  • 6. Re: Sort products by price
                    Grando
                    Here is the request code:
                    <query sorting="property" sortProp="string:$repositoryId:1" pageSize="12" refineConfig="GLOBAL" refineConfigMapProp="ancestorCategories.catalogSpecificId" refineCount="group" refineMax="35" refineTop="100" refineMin="1" refineMinVal="2" refineDebug="false" mode="and" docSortOrder="ascending" docProps="$repositoryId,$repository.repositoryName,$itemDescriptor.itemDescriptorName,$repositoryId" relQuestSettings="/activeSolutionZones=*;" responseNumberSettings="perDoc1,perProp1,doc100,prop100" respform="comp" multiPartition="false" rid="0004880001" time="1336242932695" env="commerce" lm="true" sv="true" ms="true" cache="true"><startCategory>/Meta/ancestorCategories.catalogSpecificId/catTableLamps_masterCatalog</startCategory> <variables><var name="$startToday">1336186800</var> <var name="$currentSite">storeSiteUS</var> <var name="$endToday">1336273199</var> </variables> <parserOptions><language>portuguese (brazil)</language> <propertyMapping>price,childSKUs.price@salePrices,childSKUs.price@listPrices</propertyMapping> </parserOptions> <documentSets> <and><set subdirs="true">/Meta/ancestorCategories.catalogSpecificId/catTableLamps_masterCatalog</set> <or><strprop name="ancestorCategories.$repositoryId" op="equal">rootCategory</strprop> <strprop name="ancestorCategories.$repositoryId" op="equal">homeStoreRootCategory</strprop> </or> <or><prop name="startDate" op="equal" type="date">0</prop> <prop name="startDate" op="lesseq" type="integer">1336262400</prop> </or> <or><prop name="endDate" op="equal" type="date">0</prop> <prop name="endDate" op="greatereq" type="integer">1336176000</prop> </or> <language>portuguese (brazil)</language> </and> </documentSets> <siteConstraint><or><prop name="$siteId" type="string">storeSiteUS</prop> <not><prop name="$siteId" type="string"></prop> </not> </or> </siteConstraint> </query> 
                    I tried to get price using childSKUs.price@salePrices instead of use price, but it doesn't work.

                    Thanks

                    Edited by: Grando on 05/05/2012 11:36
                    • 7. Re: Sort products by price
                      Gurvinder
                      i dont see a docSort and docSortProp being set in the request.
                      • 8. Re: Sort products by price
                        Grando
                        Yes, and this is the problem.

                        When I sort by A-Z the properties are set: docSort="strprop" docSortProp="displayName",
                        but when I sort by price, it seems like the properties isn't being set properly.

                        My code that set the properties is this:
                        <c:if test="${isATGFacetSearch}">
                             <dsp:include page="sortGadget.jsp">
                                  <dsp:param name="isATGFacetSearch" param="isATGFacetSearch" />
                                  <dsp:param name="sortParam" value="price" />
                                  <dsp:param name="sortTitle" value="common.sortMorePrice" />
                                  <dsp:param name="sortProperties" param="floatprop"/>
                                  <dsp:param name="sortOrder" value="descending" />
                                  <dsp:param name="sortId" value="${sortMorePrice}" />
                             </dsp:include>
                        </c:if>
                        I don't know why the properties aren't being set.

                        Thanks for any help
                        • 9. Re: Sort products by price
                          Gurvinder
                          Can you show how you are setting the params of the FormHandler inside sortGadget.jsp
                          • 10. Re: Sort products by price
                            Grando
                            Hi,

                            Now I am able to sort by price. The problem was a param that wasn't being passed.

                            Thanks for all help