2017-09-14 1 views
1

우리는 몇 주 동안이 문제로 어려움을 겪어 왔지만 여전히 해결책을 찾지 못했습니다.Shopify Liquid Search.Results - 바코드로 정렬하는 방법?

우리는 2000 개의 제품과 300 개의 공급 업체가있는 Shopify 스토어를 운영하고 있습니다. 각 공급 업체는 우리가 할당 한 "순위 번호"를 가지고 모든 단일 제품의 변형에서 "바코드"필드에 입력합니다. 그러나

{% assign foo = search.results | sort:'title' %} 

, 우리는 정렬이 구문을 사용하려고 :

목표는 우리가 Shopify는 "일종의"태그과 같이 액체를 사용하여 바코드로 검색 결과를 정렬 할 수 있도록하려는 것입니다 "바코드"에 의해 그것은

{% assign foo = search.results | sort:'barcode' %} 

우리는 모두 다음 인수로 '종류'를 사용하려고 한 결과를 반환하지 않습니다하지만 그들 중 누구도 작동하지 :

{% assign foo = search.results | sort:'product.barcode' %} 
{% assign foo = search.results | sort:'item.barcode' %} 
{% assign foo = search.results | sort:'item.variants.first.barcode' %} 
{% assign foo = search.results | sort:'items.variants.variant.barcode' %} 

등이지만 그 중 아무 것도 작동하지 않습니다. ANYONE이 variant.barcode를 사용하여 검색 결과를 정렬하는 데 사용할 인수/구문에 대해 올바른 방향으로 우리를 지적 할 수 있다면 많은 찬사를받을 것입니다 !!!!!

감사 기본 기능 you're out of luck의 측면에서

+0

이 테스트를 위해 바코드를 설정하지 않았지만'{% assign foo = search.results | 지도 : 'item'| 정렬 : '바코드'%}'? 'map' 필터는 search.results를 항목 배열로 줄이며, 정렬 필터로 정렬 가능해야합니다. –

답변

1

.

자신 만의 롤링을 사용해도 이와 같이 할 수 있습니다.

  1. 수동 종류의 공급 업체 순위하여 컬렉션
  2. 제한 자신의 검색 기능 또는
  3. 자신의 검색 기능 CREAT
  4. 하지만 현재 콜렉션에 "필터"확인을 만들어 수집 결과로 검색 및 네이티브 검색 만 남겨주세요.

나만의 검색을 만듭니다

  1. 는 코드에서 당신의 품목 결과 셀을 넣습니다. collection-product.liquid
  2. 에 콜렉션 액체가 들어 있습니다.

collection.search - results.liquid는 다음과 같이 보입니다 새 컬렉션 템플릿 (collection.search-results.liquid)를 확인합니다. 페이지 매김 크기는 기본 콜렉션의 페이지 매김 크기와 일치해야합니다.

{% layout none %} 
{% paginate collection.products by 50 %} 
<div class="search-results"> 
{% for product in collection.products %} 
    {% include 'collection-product' %} 
{% endfor %} 
</div> 
{% endpaginate %} 

이제 검색 결과가 일부 자바 스크립트가 포함 된 입력란이됩니다. 재미있는 부분. 아래 스크립트는 작업 사이트에서 가져 왔습니다. 나는 그것의 뼈를 희망적으로 더 명확하게하기 위해 그것을 다소 다듬었지만 그것은 아마도 그대로 움직이지 않을 것이다. 검색 목적으로 네이티브 커스텀 검색을하기 때문에 검색 추가에 대한 참조를 삭제했습니다.

결과를 정렬하지 않는 이유는 무엇입니까? 이 개념을 사용하여이를 수행 할 수 있지만 결과는 한 번에 한 페이지 씩 반환됩니다. 모든 결과를 사용자 지정 검색하려면 결과를 누적하고 검색이 끝나면 정렬해야합니다.검색 시간은 컬렉션의 크기와 사용자의 네트워크 속도에 따라 크게 달라집니다.

var defaultView = $(".filters-off"); // add this class to your main collection wrapper 
var facetView = $("#filter_target"); // <div id="filter_target"></div> below your main collection wrapper 

var currentRequest = 0; 
function filterCollection(term){ 
    //[[t1, t2], [t3,t4]] 
    // console.log('applying '+ JSON.stringify(facets)); 

    var anyResults = false; 
    var resultsPage=0; 
    var PAGE_SIZE = 50; 
    var productsFound = 0; 
    var collectionPath = location.pathname; 

    console.log('get from '+ collectionPath); 
    currentRequest = new Date().getTime(); 

    var viewLink = collectionPath+'?view=search-results'; // same as your layout none template 

    function applyFilter(myRequest){ 
     resultsPage++; 
     if(resultsPage > 20) return false; // arbitrary abort for too many results 
     if(resultsPage > 1) viewLink+='&page='+resultsPage; 
     return $.get(viewLink).then(function(page){ 
      if(currentRequest != myRequest){ 
       console.log('mid abort'); 
       return false; 
      } 
      var pageProducts = $("div[data-tags]", page); //some markup you added to collection-product snippet to help plucking the product elements 
      if(!pageProducts.length) return false; 

      console.log('found: '+ pageProducts.length); 

      var filteredProducts = pageProducts.filter(function(){ 
       if($(this).text().indexOf(term) != -1) return true; // search the returned text 

       if($(this).attr('data-keywords').indexOf(term) != -1) return true; 
       return false; 
      }); 
      if(filteredProducts.length){ 
       if(!anyResults){ 
        anyResults = true; 
        toggleView(true); 

       } 
       filterView.append(filteredProducts); 
       productsFound+= filteredProducts.length; 
      } 
      return (pageProducts.length == PAGE_SIZE && currentRequest == myRequest) ? applyFilter(myRequest) : false; 
     }).then(function(proceed){ 
      if(currentRequest == myRequest){ 

       if(!anyResults){ 
        toggleView(false, true); 
       } 
      } 
     }); 
    } 
    applyFilter(currentRequest); 
} 


function toggleView (showFacets, showNoGo){ 
    facetView.empty(); 
    $(".filter-progress").empty(); 
    if(showFacets) { 
     defaultView.add('.pagination').hide(); 

    }else { 

     if(!showNoGo){ 
      defaultView.add('.pagination').show(); 
     }else { 
      $(".no-facets").clone(true).appendTo(facetView).show(); // .no-facets is normally hidden chunk that allows for easy internationaliztion of "No results found" type messages 
     } 
    } 
}; 
관련 문제