diff --git a/app/assets/javascripts/alchemy/solidus/admin/variant_select.js b/app/assets/javascripts/alchemy/solidus/admin/variant_select.js index 160452a..acbdc73 100644 --- a/app/assets/javascripts/alchemy/solidus/admin/variant_select.js +++ b/app/assets/javascripts/alchemy/solidus/admin/variant_select.js @@ -1,32 +1,55 @@ //= require alchemy/solidus/admin/select2_config -$.fn.alchemyVariantSelect = function(options) { - var config = Alchemy.Solidus.getSelect2Config(options) +$.fn.alchemyVariantSelect = function (options) { + const config = Alchemy.Solidus.getSelect2Config(options) - this.select2($.extend(true, config, { - ajax: { - data: function(term, page) { - return { - q: $.extend({ - product_name_or_sku_cont: term - }, options.query_params), - page: page - } + function formatSelection(variant) { + return variant.options_text + ? `${variant.name} - ${variant.options_text}` + : variant.name + } + + function formatResult(variant, _el, query) { + const matchTerm = new RegExp(query.term, "gi") + const formatMatch = (match) => `${match}` + const name = variant.name.replace(matchTerm, formatMatch) + const sku = variant.sku.replace(matchTerm, formatMatch) + return ` +