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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Fix string mutation bug in Google Merchant feed title generation (#13484)
Frederik Kragh Nicolajsen4309fa3ab986
diff --git a/core/app/services/spree/data_feeds/google/required_attributes.rb b/core/app/services/spree/data_feeds/google/required_attributes.rbindex d5cdfb085e..d8700883fa 100644--- a/core/app/services/spree/data_feeds/google/required_attributes.rb+++ b/core/app/services/spree/data_feeds/google/required_attributes.rb@@ -26,11 +26,11 @@ module Spreedef format_title(product, variant)# Title of a variant is created by joining title of a product and variant's option_values, as they are# what differentiates it from other variants.- title = product.name+ parts = [product.name]variant.option_values.find_each do |option_value|- title << " - #{option_value.name}"+ parts << option_value.nameend- title+ parts.join(' - ')enddef get_description(product, variant)diff --git a/core/spec/services/spree/data_feeds/google/required_attributes_spec.rb b/core/spec/services/spree/data_feeds/google/required_attributes_spec.rbnew file mode 100644index 0000000000..713bc4696d--- /dev/null+++ b/core/spec/services/spree/data_feeds/google/required_attributes_spec.rb@@ -0,0 +1,27 @@+require 'spec_helper'++module Spree+ describe DataFeeds::Google::RequiredAttributes do+ subject { described_class.new }++ let(:store) { @default_store }+ let(:product) { create(:product, name: 'Test Product', stores: [store]) }++ describe '#call' do+ it 'does not mutate product name when generating titles for multiple variants' do+ option_type = create(:option_type)+ option_a = create(:option_value, name: 'option-a', option_type: option_type)+ option_b = create(:option_value, name: 'option-b', option_type: option_type)++ variant_a = create(:with_image_variant, product: product, option_values: [option_a])+ variant_b = create(:with_image_variant, product: product, option_values: [option_b])++ result_a = subject.call(product: product, variant: variant_a, store: store)+ result_b = subject.call(product: product, variant: variant_b, store: store)++ expect(result_a.value[:information]['title']).not_to include('option-b')+ expect(result_b.value[:information]['title']).not_to include('option-a')+ end+ end+ end+end