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.

Small tweaks.

Matthew Kennedy2fe6c4a7f178
diff --git a/core/app/models/spree/menu.rb b/core/app/models/spree/menu.rb
index b8e67e6966..fc17bdea95 100644
--- a/core/app/models/spree/menu.rb
+++ b/core/app/models/spree/menu.rb
@@ -3,6 +3,7 @@ module Spree
has_many :menu_items, dependent: :destroy
has_and_belongs_to_many :stores
+ before_save :paremeterize_unique_code
after_create :set_root
after_save :set_root_menu_item_name
@@ -16,10 +17,12 @@ module Spree
private
- def set_root
- code_name = name.parameterize
+ def paremeterize_unique_code
+ self.unique_code = unique_code.parameterize
+ end
- self.root ||= MenuItem.create!(menu_id: id, name: name, item_type: 'Container', code: "#{code_name}-root")
+ def set_root
+ self.root ||= MenuItem.create!(menu_id: id, name: name, item_type: 'Container', code: "#{name}-root")
end
def set_root_menu_item_name
diff --git a/core/app/models/spree/menu_item.rb b/core/app/models/spree/menu_item.rb
index 5cf8079457..715176113b 100644
--- a/core/app/models/spree/menu_item.rb
+++ b/core/app/models/spree/menu_item.rb
@@ -5,9 +5,8 @@ module Spree
acts_as_nested_set dependent: :destroy
- before_save :reset_link_attributes
- before_save :check_for_image
- before_save :build_path
+ before_save :reset_link_attributes, :check_for_image,
+ :build_path, :paremeterize_code
has_one_attached :image_asset
@@ -83,7 +82,13 @@ module Spree
def check_for_root
if menu.try(:root).present? && parent_id.nil?
- errors.add(:root_conflict, 'This Menu already has a root item')
+ errors.add(:root_conflict, Spree.t(:this_menu_already_has_a_root_item))
+ end
+ end
+
+ def paremeterize_code
+ if code
+ self.code = code.parameterize
end
end
end
diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml
index 48ee35e3a7..bcd4ca2cf3 100644
--- a/core/config/locales/en.yml
+++ b/core/config/locales/en.yml
@@ -1745,6 +1745,7 @@ en:
message: If you have received this email, then your email settings are correct.
subject: Test Mail
test_mode: Test Mode
+ this_menu_already_has_a_root_item: This Menu already has a root item
thank_you_for_your_order: Thank you for your business. Please print out a copy of this confirmation page for your records.
there_are_no_items_for_this_order: There are no items for this order. Please add an item to the order to continue.
there_were_problems_with_the_following_fields: There were problems with the following fields