Sha256: bd25f76136f2352e22e213f5d7a7d32646e4d2681436ce8442bd6bdc60ff898b

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

$.fn.productAutocomplete = function () {
  'use strict';

  this.select2({
    minimumInputLength: 1,
    multiple: true,
    initSelection: function (element, callback) {
      $.get(Spree.routes.product_search, {
        ids: element.val().split(','),
        token: Spree.api_key
      }, function (data) {
        callback(data.products);
      });
    },
    ajax: {
      url: Spree.routes.product_search,
      datatype: 'json',
      data: function (term, page) {
        return {
          q: {
            name_cont: term,
            sku_cont: term
          },
          m: 'OR',
          token: Spree.api_key
        };
      },
      results: function (data, page) {
        var products = data.products ? data.products : [];
        return {
          results: products
        };
      }
    },
    formatResult: function (product) {
      return product.name;
    },
    formatSelection: function (product) {
      return product.name;
    }
  });
};

$(document).ready(function () {
  $('.product_picker').productAutocomplete();
});

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
spree_backend-2.2.14 app/assets/javascripts/spree/backend/product_picker.js
spree_backend-2.2.13 app/assets/javascripts/spree/backend/product_picker.js
spree_backend-2.2.12 app/assets/javascripts/spree/backend/product_picker.js