Sha256: 2e51d921a38386dcccf11cbc2bf536f794ed9f8abf8ba940460cbc83fd65d21c

Contents?: true

Size: 1.32 KB

Versions: 10

Compression:

Stored size: 1.32 KB

Contents

# variant autocompletion
$(document).ready ->
  if $("#variant_autocomplete_template").length > 0
    window.variantTemplate = Handlebars.compile($("#variant_autocomplete_template").text())
    window.variantStockTemplate = Handlebars.compile($("#variant_autocomplete_stock_template").text())
    window.variantLineItemTemplate = Handlebars.compile($("#variant_line_items_autocomplete_stock_template").text())
  return

formatVariantResult = (variant) ->
  variant.image = variant.images[0].mini_url  if variant["images"][0] isnt `undefined` and variant["images"][0].mini_url isnt `undefined`
  variantTemplate variant: variant

$.fn.variantAutocomplete = ->
  @select2
    placeholder: Spree.translations.variant_placeholder
    minimumInputLength: 3
    initSelection: (element, callback) ->
      $.get Spree.routes.variants_search + "/" + element.val(), {}, (data) ->
        callback data
    ajax:
      url: Spree.url(Spree.routes.variants_api)
      datatype: "json"
      data: (term, page) ->
        q:
          product_name_or_sku_cont: term

      results: (data, page) ->
        window.variants = data["variants"]
        results: data["variants"]

    formatResult: formatVariantResult
    formatSelection: (variant) ->
      if !!variant.options_text
        variant.name + " (#{variant.options_text})"
      else
        variant.name

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
spree_backend-3.0.0.rc3 app/assets/javascripts/spree/backend/variant_autocomplete.js.coffee.erb
spree_backend-2.4.4 app/assets/javascripts/spree/backend/variant_autocomplete.js.coffee.erb
spree_backend-3.0.0.rc1 app/assets/javascripts/spree/backend/variant_autocomplete.js.coffee.erb
spree_backend-2.4.3 app/assets/javascripts/spree/backend/variant_autocomplete.js.coffee.erb
spree_backend-2.4.2 app/assets/javascripts/spree/backend/variant_autocomplete.js.coffee.erb
spree_backend-2.4.1 app/assets/javascripts/spree/backend/variant_autocomplete.js.coffee.erb
spree_backend-2.4.0 app/assets/javascripts/spree/backend/variant_autocomplete.js.coffee.erb
spree_backend-2.4.0.rc3 app/assets/javascripts/spree/backend/variant_autocomplete.js.coffee.erb
spree_backend-2.4.0.rc2 app/assets/javascripts/spree/backend/variant_autocomplete.js.coffee.erb
spree_backend-2.4.0.rc1 app/assets/javascripts/spree/backend/variant_autocomplete.js.coffee.erb