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.

Autostrip whitespace from Product's names and Variant's SKUs (#11623)

Damian Legawiec9fbbb3fa6b42
diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb
index 656b81ac1a..83f361afcf 100644
--- a/core/app/models/spree/product.rb
+++ b/core/app/models/spree/product.rb
@@ -39,6 +39,7 @@ module Spree
friendly_id :slug_candidates, use: :history
acts_as_paranoid
+ auto_strip_attributes :name
# we need to have this callback before any dependent: :destroy associations
# https://github.com/rails/rails/issues/3458
diff --git a/core/app/models/spree/variant.rb b/core/app/models/spree/variant.rb
index 2d8323bbb6..48990bf221 100644
--- a/core/app/models/spree/variant.rb
+++ b/core/app/models/spree/variant.rb
@@ -17,6 +17,8 @@ module Spree
delegate :name, :name=, :description, :slug, :available_on, :make_active_at, :shipping_category_id,
:meta_description, :meta_keywords, :shipping_category, to: :product
+ auto_strip_attributes :sku, nullify: false
+
# we need to have this callback before any dependent: :destroy associations
# https://github.com/rails/rails/issues/3458
before_destroy :ensure_not_in_complete_orders
@@ -170,7 +172,7 @@ module Spree
def options=(options = {})
options.each do |option|
- skip if option[:name].blank? || option[:value].blank?
+ next if option[:name].blank? || option[:value].blank?
set_option_value(option[:name], option[:value])
end