File tree Expand file tree Collapse file tree 3 files changed +17
-6
lines changed
app/controllers/spree/api
backend/app/assets/javascripts/spree/backend Expand file tree Collapse file tree 3 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -25,8 +25,14 @@ def destroy
2525 # we render on the view so we better update it any time a node is included
2626 # or removed from the views.
2727 def index
28- @variants = scope . includes ( include_list )
29- . ransack ( params [ :q ] ) . result
28+ @variants =
29+ if params [ :variant_search_term ]
30+ Spree ::Config . variant_search_class . new (
31+ params [ :variant_search_term ] , scope : scope
32+ ) . results . includes ( include_list )
33+ else
34+ scope . includes ( include_list ) . ransack ( params [ :q ] ) . result
35+ end
3036
3137 @variants = paginate ( @variants )
3238 respond_with ( @variants )
Original file line number Diff line number Diff line change @@ -38,7 +38,14 @@ module Spree::Api
3838 expect ( json_response [ 'pages' ] ) . to eq ( 3 )
3939 end
4040
41- it 'can query the results through a paramter' do
41+ it 'can query the results through the search class' do
42+ expected_result = create ( :variant , sku : 'FOOBAR' )
43+ get spree . api_variants_path , params : { variant_search_term : 'FOO' }
44+ expect ( json_response [ 'count' ] ) . to eq ( 1 )
45+ expect ( json_response [ 'variants' ] . first [ 'sku' ] ) . to eq expected_result . sku
46+ end
47+
48+ it 'can query the results through ransack' do
4249 expected_result = create ( :variant , sku : 'FOOBAR' )
4350 get spree . api_variants_path , params : { q : { sku_cont : 'FOO' } }
4451 expect ( json_response [ 'count' ] ) . to eq ( 1 )
Original file line number Diff line number Diff line change 3131 } ,
3232 data : function ( term , page ) {
3333 var searchData = {
34- q : {
35- product_name_or_sku_cont : term
36- } ,
34+ variant_search_term : term ,
3735 token : Spree . api_key
3836 } ;
3937 return _ . extend ( searchData , searchOptions ) ;
You can’t perform that action at this time.
0 commit comments