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.

Trims product property value before saving it

Robert Nowakowski4374abff0213
diff --git a/core/app/models/spree/product_property.rb b/core/app/models/spree/product_property.rb
index 10584ed4a1..681bdb4ce2 100644
--- a/core/app/models/spree/product_property.rb
+++ b/core/app/models/spree/product_property.rb
@@ -17,11 +17,19 @@ module Spree
# virtual attributes for use with AJAX completion stuff
delegate :name, :presentation, to: :property, prefix: true, allow_nil: true
+ before_save :trim_value
+
def property_name=(name)
if name.present?
# don't use `find_by :name` to workaround globalize/globalize#423 bug
self.property = Property.where(name: name).first_or_create(presentation: name)
end
end
+
+ def trim_value
+ return if value.nil?
+
+ value.strip!
+ end
end
end