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 Google feed excluding simple products without option variants (#13618)

Damian Legawiec66667b6c41a1
diff --git a/backend/engines/core/app/models/spree/variant.rb b/backend/engines/core/app/models/spree/variant.rb
index 5407014e6a..fc9f871df0 100644
--- a/backend/engines/core/app/models/spree/variant.rb
+++ b/backend/engines/core/app/models/spree/variant.rb
@@ -95,12 +95,9 @@ module Spree
scope :in_stock_or_backorderable, -> { in_stock.or(backorderable) }
scope :eligible, lambda {
- where(is_master: false).or(
- where(
- product_id: Spree::Variant.
- select(:product_id).
- group(:product_id).
- having("COUNT(#{Spree::Variant.table_name}.id) = 1")
+ joins(:product).where(
+ arel_table[:is_master].eq(false).or(
+ Spree::Product.arel_table[:variant_count].eq(0)
)
)
}
diff --git a/backend/engines/core/app/services/spree/data_feeds/google/rss.rb b/backend/engines/core/app/services/spree/data_feeds/google/rss.rb
index b7eaacb047..d7aa2a9c83 100644
--- a/backend/engines/core/app/services/spree/data_feeds/google/rss.rb
+++ b/backend/engines/core/app/services/spree/data_feeds/google/rss.rb
@@ -18,7 +18,9 @@ module Spree
result = products_list.call(store)
if result.success?
result.value[:products].find_each do |product|
- product.variants.active.find_each do |variant|
+ product.variants_including_master.active.find_each do |variant|
+ next if variant.is_master? && product.has_variants?
+
add_variant_information_to_xml(xml, product, variant)
end
end
diff --git a/backend/engines/core/spec/services/spree/data_feeds/google/rss_spec.rb b/backend/engines/core/spec/services/spree/data_feeds/google/rss_spec.rb
index 5c6b91ab0a..e412f8ae8f 100644
--- a/backend/engines/core/spec/services/spree/data_feeds/google/rss_spec.rb
+++ b/backend/engines/core/spec/services/spree/data_feeds/google/rss_spec.rb
@@ -92,6 +92,24 @@ module Spree
end
end
+ context 'product with only master variant' do
+ let(:product) { create(:product, stores: [store]) }
+ let!(:variant) { nil }
+
+ before do
+ product.master.images << create(:image)
+ allow(subject).to receive(:store).and_return(store)
+ end
+
+ it 'includes master variant in feed' do
+ expect(result.value[:file]).to include("<g:id>#{product.master.id}</g:id>")
+ end
+
+ it 'includes product name as title' do
+ expect(result.value[:file]).to include("<g:title>#{product.name}</g:title>")
+ end
+ end
+
context 'optional item attributes are generated correctly' do
let(:product) { create(:product_with_properties, stores: [store]) }