From 41c90170d13280ae275de4d1f72d90904c73e870 Mon Sep 17 00:00:00 2001 From: luca-landa Date: Thu, 25 Nov 2021 16:44:22 +0100 Subject: [PATCH] Make display_price optional on admin variants list When there are variants with not fully configured prices (e.g. because they are being created) the product variants page breaks without the admin really knowing why. This allows for the variants list to be displayed anyway. --- .../app/views/spree/admin/variants/_table.html.erb | 2 +- backend/spec/features/admin/products/variant_spec.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/backend/app/views/spree/admin/variants/_table.html.erb b/backend/app/views/spree/admin/variants/_table.html.erb index 88804421631..9388f16753c 100644 --- a/backend/app/views/spree/admin/variants/_table.html.erb +++ b/backend/app/views/spree/admin/variants/_table.html.erb @@ -27,7 +27,7 @@ <% end %> <%= variant.options_text %> - <%= variant.display_price.to_html %> + <%= variant.display_price&.to_html %> <%= variant.sku %> <% if can?(:update, variant) %> diff --git a/backend/spec/features/admin/products/variant_spec.rb b/backend/spec/features/admin/products/variant_spec.rb index 4132f8d4ed9..fe6e05ae2fb 100644 --- a/backend/spec/features/admin/products/variant_spec.rb +++ b/backend/spec/features/admin/products/variant_spec.rb @@ -70,6 +70,18 @@ expect(page).to have_content(discarded_variant.sku) end end + + context 'displaying variants with unconfigured prices' do + let!(:variant) { create(:variant, sku: 'priceless_variant', product: product) } + + before { variant.prices.delete_all } + + it 'renders the listing correctly' do + visit spree.admin_product_variants_path(product) + + expect(page).to have_content('priceless_variant') + end + end end context "editing existent variant" do