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 generating image urls in the products export (#12542)

Łukasz Adamczyk0600a67ddbd9
diff --git a/core/app/presenters/spree/csv/product_variant_presenter.rb b/core/app/presenters/spree/csv/product_variant_presenter.rb
index 2b7c4ed127..6a2237d791 100644
--- a/core/app/presenters/spree/csv/product_variant_presenter.rb
+++ b/core/app/presenters/spree/csv/product_variant_presenter.rb
@@ -57,6 +57,17 @@ module Spree
attr_accessor :product, :variant, :index, :properties, :taxons, :store, :currency
+ ##
+ # Generates an array representing a CSV row of product variant data.
+ #
+ # For the primary variant row (when the index is zero), product-level details such as name,
+ # slug, status, vendor and brand names, description, meta tags, and tag/label lists are included.
+ # In all cases, variant-specific attributes (e.g., id, SKU, pricing, dimensions, weight,
+ # availability dates, inventory count, digital flag, tax category, image URLs via original_url,
+ # and the first three option types and corresponding option values) are appended.
+ # Additionally, when the index is zero, associated taxons and properties are added.
+ #
+ # @return [Array] An array containing the combined product and variant CSV data.
def call
csv = [
product.id,
@@ -88,9 +99,9 @@ module Spree
variant.backorderable?,
variant.tax_category&.name,
variant.digital?,
- variant.images[0]&.attachment&.url,
- variant.images[1]&.attachment&.url,
- variant.images[2]&.attachment&.url,
+ variant.images[0]&.original_url,
+ variant.images[1]&.original_url,
+ variant.images[2]&.original_url,
option_type(0)&.name,
option_value(option_type(0)),
option_type(1)&.name,
diff --git a/core/spec/presenters/spree/csv/product_variant_presenter_spec.rb b/core/spec/presenters/spree/csv/product_variant_presenter_spec.rb
index dbd4b6ae52..64ccf15bb5 100644
--- a/core/spec/presenters/spree/csv/product_variant_presenter_spec.rb
+++ b/core/spec/presenters/spree/csv/product_variant_presenter_spec.rb
@@ -8,6 +8,8 @@ RSpec.describe Spree::CSV::ProductVariantPresenter do
let(:taxons) { [] }
let(:presenter) { described_class.new(product, variant, 0, properties, taxons, store) }
+ let!(:variant_images) { create_list(:image, 3, viewable: variant) }
+
describe '#call' do
subject { presenter.call }
@@ -41,9 +43,9 @@ RSpec.describe Spree::CSV::ProductVariantPresenter do
expect(subject[26]).to eq variant.backorderable?
expect(subject[27]).to eq variant.tax_category&.name
expect(subject[28]).to eq variant.digital?
- expect(subject[29]).to eq variant.images[0]&.attachment&.url
- expect(subject[30]).to eq variant.images[1]&.attachment&.url
- expect(subject[31]).to eq variant.images[2]&.attachment&.url
+ expect(subject[29]).to eq variant.images[0].original_url
+ expect(subject[30]).to eq variant.images[1].original_url
+ expect(subject[31]).to eq variant.images[2].original_url
end
context 'when index is not zero' do