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.

Change the structure of `Spree::Tags::BulkAdd` so it is easier to decorate (#12685)

Damian Kaczmarczyk0ce41885245a
diff --git a/core/app/services/spree/tags/bulk_add.rb b/core/app/services/spree/tags/bulk_add.rb
index 6cd266fa59..c38c1b7807 100644
--- a/core/app/services/spree/tags/bulk_add.rb
+++ b/core/app/services/spree/tags/bulk_add.rb
@@ -16,7 +16,19 @@ module Spree
record_class = records.first.class
- taggings_to_upsert = records.pluck(:id).map do |record_id|
+ taggings_to_upsert = taggings_attributes(tags, records, context: context, record_class: record_class)
+
+ return if taggings_to_upsert.empty?
+
+ ActsAsTaggableOn::Tagging.insert_all(taggings_to_upsert)
+
+ record_class.where(id: records.pluck(:id)).touch_all
+ end
+
+ private
+
+ def taggings_attributes(tags, records, context:, record_class:)
+ records.pluck(:id).map do |record_id|
tags.map do |tag|
{
taggable_id: record_id,
@@ -26,12 +38,6 @@ module Spree
}
end
end.flatten.compact
-
- return if taggings_to_upsert.empty?
-
- ActsAsTaggableOn::Tagging.insert_all(taggings_to_upsert)
-
- record_class.where(id: records.pluck(:id)).touch_all
end
end
end