Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

List only current store taxons for prototype form

Szymon Iwacz30933feac962
diff --git a/backend/app/views/spree/admin/prototypes/_form.html.erb b/backend/app/views/spree/admin/prototypes/_form.html.erb
index edf8a3349f..6cded9bbf8 100644
--- a/backend/app/views/spree/admin/prototypes/_form.html.erb
+++ b/backend/app/views/spree/admin/prototypes/_form.html.erb
@@ -22,7 +22,7 @@
<div id='taxons' data-hook>
<%= f.field_container :taxon_ids, class: ['form-group'] do %>
<%= f.label :taxon_ids, Spree.t(:taxons) %><br>
- <%= f.select :taxon_ids, Spree::Taxon.all.map { |t| [t.name, t.id] }, {}, { multiple: true, class: "select2" } %>
+ <%= f.select :taxon_ids, current_store.taxons.pluck(:name, :id), {}, { multiple: true, class: "select2" } %>
<% end %>
</div>
</div>
diff --git a/backend/spec/features/admin/products/prototypes_spec.rb b/backend/spec/features/admin/products/prototypes_spec.rb
index fedd39d48d..7a800ce499 100644
--- a/backend/spec/features/admin/products/prototypes_spec.rb
+++ b/backend/spec/features/admin/products/prototypes_spec.rb
@@ -62,6 +62,36 @@ describe 'Prototypes', type: :feature, js: true do
expect(page).to have_content('successfully updated!')
expect(page).to have_content('Shirt 99')
end
+
+ context 'selecting taxons' do
+ let(:prototype_name) { 'shirts' }
+ let!(:store1) { Spree::Store.default }
+ let!(:taxonomy1) { create(:taxonomy, name: 'Shirts', store: store1) }
+ let!(:store2) { create(:store) }
+ let!(:taxonomy2) { create(:taxonomy, name: 'Bags', store: store2) }
+
+ it 'should be able to select only current store taxons' do
+ visit spree.admin_path
+ click_link 'Products'
+ click_link 'Prototypes'
+
+ click_link 'new_prototype_link'
+ within('.content-header') do
+ expect(page).to have_content('New Prototype')
+ end
+ fill_in 'prototype_name', with: prototype_name
+
+ select2_open label: 'Taxons'
+ expect(page).to have_content('Shirts')
+ expect(page).not_to have_content('Bags')
+ select2_select 'Shirts', from: 'Taxons'
+
+ click_button 'Create'
+
+ expect(page).to have_content('successfully created!')
+ expect(Spree::Prototype.find_by(name: prototype_name).taxons).to match_array([taxonomy1.root])
+ end
+ end
end
context 'editing a prototype' do