From 7516872bed018c12993a0f872e9b6787a809ce8f Mon Sep 17 00:00:00 2001 From: Sascha Karnatz <68833+kulturbande@users.noreply.github.com> Date: Mon, 27 May 2024 17:20:36 +0200 Subject: [PATCH 1/3] Fix variant select ingredient The Variant select didn't showed any result, because the text and frontend_display are not available on the variant entity. It is now replaced by a multiline output to make it easier to find the correct product variant. --- .../alchemy/solidus/admin/variant_select.js | 32 +++++++++++++------ .../_spree_variant_editor.html.erb | 22 ++++++++++++- 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/alchemy/solidus/admin/variant_select.js b/app/assets/javascripts/alchemy/solidus/admin/variant_select.js index 160452a..c9f573b 100644 --- a/app/assets/javascripts/alchemy/solidus/admin/variant_select.js +++ b/app/assets/javascripts/alchemy/solidus/admin/variant_select.js @@ -1,7 +1,25 @@ //= require alchemy/solidus/admin/select2_config $.fn.alchemyVariantSelect = function(options) { - var config = Alchemy.Solidus.getSelect2Config(options) + const config = Alchemy.Solidus.getSelect2Config(options) + + function formatSelection(variant) { + return variant.options_text ? `${variant.name} - ${variant.options_text}` : variant.name + } + + function formatResult(variant) { + return ` +
+
+ ${variant.name} +
+
+ ${variant.options_text} + ${variant.sku} +
+
+ ` + } this.select2($.extend(true, config, { ajax: { @@ -15,18 +33,12 @@ $.fn.alchemyVariantSelect = function(options) { }, results: function(data, page) { return { - results: data.variants.map(function(variant) { - return { - id: variant.id, - text: variant.frontend_display - } - }), + results: data.variants, more: page * data.per_page < data.total_count } } }, - formatSelection: function(variant) { - return variant.text || variant.frontend_display - } + formatSelection, + formatResult })) } diff --git a/app/views/alchemy/ingredients/_spree_variant_editor.html.erb b/app/views/alchemy/ingredients/_spree_variant_editor.html.erb index 5a4ebf4..b87d227 100644 --- a/app/views/alchemy/ingredients/_spree_variant_editor.html.erb +++ b/app/views/alchemy/ingredients/_spree_variant_editor.html.erb @@ -10,6 +10,25 @@ <% end %> <% end %> + +