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.

Update sample and add method for child index.

Matthew Kennedy388bc7cf5a06
diff --git a/core/app/models/spree/menu_item.rb b/core/app/models/spree/menu_item.rb
index 9a06ffdc8e..eb9d187bf2 100644
--- a/core/app/models/spree/menu_item.rb
+++ b/core/app/models/spree/menu_item.rb
@@ -47,6 +47,10 @@ module Spree
end
end
+ def child_index=(idx)
+ move_to_child_with_index(parent, idx.to_i) unless new_record?
+ end
+
private
def reset_link_attributes
diff --git a/sample/db/samples/menu_items.rb b/sample/db/samples/menu_items.rb
index 457271986d..3c50bc6600 100644
--- a/sample/db/samples/menu_items.rb
+++ b/sample/db/samples/menu_items.rb
@@ -77,7 +77,7 @@ offers = Spree::Taxon.find_by!(permalink: 'special-offers/30-percent-off')
# Links For: PROMOS #
#####################
PROMOS.each do |promo|
- Spree::MenuItem.where(
+ summer_promo = Spree::MenuItem.where(
name: 'New Collection',
subtitle: "Summer #{Date.today.year}",
linked_resource_type: 'Taxon',
@@ -87,7 +87,10 @@ PROMOS.each do |promo|
parent_id: promo
).first_or_create!
- Spree::MenuItem.where(
+ summer_promo.linked_resource_id = summer.id
+ summer_promo.save!
+
+ special_offer = Spree::MenuItem.where(
name: 'Special Offers',
subtitle: 'Get up to 30% OFF',
linked_resource_type: 'Taxon',
@@ -96,6 +99,9 @@ PROMOS.each do |promo|
menu_id: main_menu,
parent_id: promo
).first_or_create!
+
+ special_offer.linked_resource_id = offers.id
+ special_offer.save!
end
#################################
diff --git a/sample/lib/spree_sample.rb b/sample/lib/spree_sample.rb
index 78e3a94ad6..28841835a1 100644
--- a/sample/lib/spree_sample.rb
+++ b/sample/lib/spree_sample.rb
@@ -16,7 +16,6 @@ module SpreeSample
Spree::Sample.load_sample('tax_rates')
Spree::Sample.load_sample('taxonomies')
Spree::Sample.load_sample('promotions')
- Spree::Sample.load_sample('menus')
Spree::Sample.load_sample('products')
Spree::Sample.load_sample('taxons')
@@ -26,7 +25,6 @@ module SpreeSample
Spree::Sample.load_sample('prototypes')
Spree::Sample.load_sample('variants')
Spree::Sample.load_sample('stock')
- Spree::Sample.load_sample('menu_items')
Spree::Sample.load_sample('orders')
Spree::Sample.load_sample('adjustments')
@@ -34,6 +32,9 @@ module SpreeSample
Spree::Sample.load_sample('reimbursements')
Spree::Sample.load_sample('return_authorization_reasons')
Spree::Sample.load_sample('stores')
+
+ Spree::Sample.load_sample('menus')
+ Spree::Sample.load_sample('menu_items')
end
end
end