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.

Fix taxons' columns in the products export (#12359)

Damian Kaczmarczykdb88cd41e4c8
diff --git a/admin/app/controllers/spree/admin/exports_controller.rb b/admin/app/controllers/spree/admin/exports_controller.rb
index c96632fc2f..d6d4dd956b 100644
--- a/admin/app/controllers/spree/admin/exports_controller.rb
+++ b/admin/app/controllers/spree/admin/exports_controller.rb
@@ -1,6 +1,8 @@
module Spree
module Admin
class ExportsController < ResourceController
+ include ActiveStorage::SetCurrent # Needed for ActiveStorage to work on development env
+
new_action.before :assign_params
create.before :set_user
diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb
index 2a9a4b65b4..23f190709c 100644
--- a/core/app/models/spree/product.rb
+++ b/core/app/models/spree/product.rb
@@ -630,7 +630,9 @@ module Spree
product_properties.find { |pp| pp.property_id == property.id }&.value
]
end
- taxons_for_csv ||= taxons.reorder(depth: :desc).first(3).pluck(:pretty_name)
+ taxons_for_csv ||= taxons.manual.reorder(depth: :desc).first(3).pluck(:pretty_name)
+ taxons_for_csv.fill(nil, taxons_for_csv.size...3)
+
csv_lines = []
if has_variants?
diff --git a/core/spec/models/spree/exports/products_spec.rb b/core/spec/models/spree/exports/products_spec.rb
new file mode 100644
index 0000000000..11f1f87170
--- /dev/null
+++ b/core/spec/models/spree/exports/products_spec.rb
@@ -0,0 +1,27 @@
+require 'spec_helper'
+
+RSpec.describe Spree::Exports::Products, type: :model do
+ let(:store) { create(:store) }
+ let(:export) { described_class.new(store: store) }
+
+ describe '#scope' do
+ let!(:archived_product) { create(:product, status: 'archived', stores: [store]) }
+ let!(:test_product) { create(:product, name: 'test', stores: [store]) }
+
+ context 'when search_params is nil' do
+ it 'excludes archived products' do
+ expect(export.scope).to include(test_product)
+ expect(export.scope).not_to include(archived_product)
+ end
+ end
+
+ context 'when search_params is present' do
+ let(:export) { described_class.new(store: store, search_params: { name: 'test' }) }
+
+ it 'includes all products' do
+ expect(export.scope).to include(test_product)
+ expect(export.scope).to include(archived_product)
+ end
+ end
+ end
+end
diff --git a/core/spec/models/spree/product_spec.rb b/core/spec/models/spree/product_spec.rb
index 033cabb9ae..e2d5819fbc 100644
--- a/core/spec/models/spree/product_spec.rb
+++ b/core/spec/models/spree/product_spec.rb
@@ -1147,9 +1147,7 @@ describe Spree::Product, type: :model do
csv_line = csv_lines.first
expect(csv_line).to include(product.name)
expect(csv_line).to include(product.master.sku)
- expect(csv_line).to include('my-property')
- expect(csv_line).to include('MyValue')
- expect(csv_line).to include(taxon.pretty_name)
+ expect(csv_line.last(5)).to eq([taxon.pretty_name, nil, nil, "my-property", "MyValue"])
end
end