<%#encoding: UTF-8%>
// variant autocompletion

$(document).ready(function() {
  window.variantTemplate = Handlebars.compile($('#variant_autocomplete_template').text());
})

formatVariantResult = function(variant) {
  if (variant["images"][0] != undefined && variant["images"][0].image != undefined) {
    variant.image = variant.images[0].image.mini_url
  }
  return variantTemplate({ variant: variant })
}

$.fn.variantAutocomplete = function() {
  this.parent().children(".options_placeholder").attr('id', this.parent().data('index'))
  this.select2({
    placeholder: "Select a variant",
    minimumInputLength: 4,
    ajax: {
      url: Spree.routes.variants_search,
      datatype: 'json',
      data: function(term, page) {
        return {
          q: {
            "product_name_or_sku": term
          }
        }
      },
      results: function (data, page) {
        return { results: data }
      }
    },
    formatResult: formatVariantResult,
    formatSelection: function (variant) {
      $(this.element).parent().children('.options_placeholder').html(variant.options_text)
      return variant.name;
    }
  })
}

<%#encoding: UTF-8%>
// variant autocompletion

$(document).ready(function() {
  window.variantTemplate = Handlebars.compile($('#variant_autocomplete_template').text());
})

formatVariantResult = function(variant) {
  if (variant["images"][0] != undefined && variant["images"][0].image != undefined) {
    variant.image = variant.images[0].image.mini_url
  }
  return variantTemplate({ variant: variant })
}

$.fn.variantAutocomplete = function() {
  this.parent().children(".options_placeholder").attr('id', this.parent().data('index'))
  this.select2({
    placeholder: "Select a variant",
    minimumInputLength: 4,
    ajax: {
      url: Spree.routes.variants_search,
      datatype: 'json',
      data: function(term, page) {
        return {
          q: {
            "products_name_or_sku": term
          }
        }
      },
      results: function (data, page) {
        return { results: data }
      }
    },
    formatResult: formatVariantResult,
    formatSelection: function (variant) {
      $(this.element).parent().children('.options_placeholder').html(variant.options_text)
      return variant.name;
    }
  })
}

Correct products_name_or_sku key in variant autocomplete
Correct products_name_or_sku key in variant autocomplete
