From 397bf9a8e1c2a31dc8c3160ae557ebe14019c1e2 Mon Sep 17 00:00:00 2001 From: Mayur Date: Wed, 20 Nov 2024 18:06:11 +0530 Subject: [PATCH 01/25] Added configuration to get brand from product --- core/app/models/spree/product.rb | 4 ++++ core/app/models/spree/taxon_brand_selector.rb | 22 +++++++++++++++++++ core/lib/spree/app_configuration.rb | 8 ++++++- .../models/spree/taxon_brand_selector_spec.rb | 19 ++++++++++++++++ 4 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 core/app/models/spree/taxon_brand_selector.rb create mode 100644 core/spec/models/spree/taxon_brand_selector_spec.rb diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb index 1754e939497..cb32b251f92 100644 --- a/core/app/models/spree/product.rb +++ b/core/app/models/spree/product.rb @@ -291,6 +291,10 @@ def gallery @gallery ||= Spree::Config.product_gallery_class.new(self) end + def brand + Spree::Config.brand_selector_class.new(product).call + end + private def any_variants_not_track_inventory? diff --git a/core/app/models/spree/taxon_brand_selector.rb b/core/app/models/spree/taxon_brand_selector.rb new file mode 100644 index 00000000000..4a0a0dce0bd --- /dev/null +++ b/core/app/models/spree/taxon_brand_selector.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +module Spree + class TaxonBrandSelector + BRANDS_TAXONOMY_NAME = "Brands" + + def initialize(product) + @product = product + end + + def call + product.taxons + .joins(:taxonomy) + .where(spree_taxonomies: { name: BRANDS_TAXONOMY_NAME }) + .first + end + + private + + attr_reader :product + end +end diff --git a/core/lib/spree/app_configuration.rb b/core/lib/spree/app_configuration.rb index 8b0223eeb59..fe3f8243bb0 100644 --- a/core/lib/spree/app_configuration.rb +++ b/core/lib/spree/app_configuration.rb @@ -522,6 +522,13 @@ def payment_canceller # Spree::StoreCreditPrioritizer. class_name_attribute :store_credit_prioritizer_class, default: 'Spree::StoreCreditPrioritizer' + # Allows finding brand for product. + # + # @!attribute [rw] brand_selector_class + # @return [Class] a class with the same public interfaces as + # Spree::TaxonBrandSelector. + class_name_attribute :brand_selector_class, default: 'Spree::TaxonBrandSelector' + # @!attribute [rw] taxon_image_style_default # # Defines which style to default to when style is not provided @@ -550,7 +557,6 @@ def payment_canceller # @return [Module] a module that can be included into Spree::Taxon to allow attachments # Enumerable of taxons adhering to the present_taxon_class interface class_name_attribute :taxon_attachment_module, default: "Spree::Taxon::ActiveStorageAttachment" - # Set of classes that can be promotion adjustment sources add_class_set :adjustment_promotion_source_types, default: [] diff --git a/core/spec/models/spree/taxon_brand_selector_spec.rb b/core/spec/models/spree/taxon_brand_selector_spec.rb new file mode 100644 index 00000000000..ca2ce2ad27d --- /dev/null +++ b/core/spec/models/spree/taxon_brand_selector_spec.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe Spree::TaxonBrandSelector, type: :model do + let(:taxonomy) { create(:taxonomy, name: "Brands") } + let(:taxon) { create(:taxon, taxonomy: taxonomy, name: "Brand A") } + let(:product) { create(:product, taxons: [taxon]) } + + subject { described_class.new(product) } + + describe "#call" do + context "when the product has a taxon under the 'Brands' taxonomy" do + it "returns the first taxon under 'Brands'" do + expect(subject.call).to eq(taxon) + end + end + end +end From b4d51e13f1f270eee3c473a433d3f8e3206dd89b Mon Sep 17 00:00:00 2001 From: Mayur Date: Wed, 20 Nov 2024 18:07:41 +0530 Subject: [PATCH 02/25] Removed extra space --- core/lib/spree/app_configuration.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/core/lib/spree/app_configuration.rb b/core/lib/spree/app_configuration.rb index fe3f8243bb0..631a609d18d 100644 --- a/core/lib/spree/app_configuration.rb +++ b/core/lib/spree/app_configuration.rb @@ -557,6 +557,7 @@ def payment_canceller # @return [Module] a module that can be included into Spree::Taxon to allow attachments # Enumerable of taxons adhering to the present_taxon_class interface class_name_attribute :taxon_attachment_module, default: "Spree::Taxon::ActiveStorageAttachment" + # Set of classes that can be promotion adjustment sources add_class_set :adjustment_promotion_source_types, default: [] From f8fa8310d390341dbe3bd9ab656410fce74c52ee Mon Sep 17 00:00:00 2001 From: shahmayur001 Date: Wed, 20 Nov 2024 23:53:02 +0530 Subject: [PATCH 03/25] Corrected the reference --- core/app/models/spree/product.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb index cb32b251f92..03193148ec0 100644 --- a/core/app/models/spree/product.rb +++ b/core/app/models/spree/product.rb @@ -292,7 +292,7 @@ def gallery end def brand - Spree::Config.brand_selector_class.new(product).call + Spree::Config.brand_selector_class.new(self).call end private From eeb60c9959050dd05111b18f3e4c3afaeabda22f Mon Sep 17 00:00:00 2001 From: Mayur Date: Fri, 22 Nov 2024 16:57:34 +0530 Subject: [PATCH 04/25] Added more test cases --- .../models/spree/taxon_brand_selector_spec.rb | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/core/spec/models/spree/taxon_brand_selector_spec.rb b/core/spec/models/spree/taxon_brand_selector_spec.rb index ca2ce2ad27d..7d2d4721e60 100644 --- a/core/spec/models/spree/taxon_brand_selector_spec.rb +++ b/core/spec/models/spree/taxon_brand_selector_spec.rb @@ -15,5 +15,32 @@ expect(subject.call).to eq(taxon) end end + + context "when the product has multiple taxons under the 'Brands' taxonomy" do + let(:taxon_b) { create(:taxon, taxonomy: taxonomy, name: "Brand B") } + before { product.taxons << taxon_b } + + it "returns the first taxon under 'Brands'" do + expect(subject.call).to eq(taxon) + end + end + + context "when the product does not have a taxon under the 'Brands' taxonomy" do + let(:other_taxonomy) { create(:taxonomy, name: "Categories") } + let(:other_taxon) { create(:taxon, taxonomy: other_taxonomy, name: "Category A") } + let(:product) { create(:product, taxons: [other_taxon]) } + + it "returns nil" do + expect(subject.call).to be_nil + end + end + + context "when the product has no taxons" do + let(:product) { create(:product) } + + it "returns nil" do + expect(subject.call).to be_nil + end + end end end From 02519e02f95977c161e0618c11c39b0108277810 Mon Sep 17 00:00:00 2001 From: Mayur Shah Date: Mon, 2 Dec 2024 23:24:18 +0530 Subject: [PATCH 05/25] Fixed store validation issue --- sample/db/samples/taxonomies.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sample/db/samples/taxonomies.rb b/sample/db/samples/taxonomies.rb index c3a30e0b79a..3c4614b6131 100644 --- a/sample/db/samples/taxonomies.rb +++ b/sample/db/samples/taxonomies.rb @@ -1,10 +1,11 @@ # frozen_string_literal: true +store = Spree::Store.where(code: 'sample-store').first + taxonomies = [ - { name: "Categories" }, - { name: "Brand" } + { name: "Categories", store: }, + { name: "Brands", store: } ] - taxonomies.each do |taxonomy_attrs| - Spree::Taxonomy.create!(taxonomy_attrs) + Spree::Taxonomy.find_or_create_by!(taxonomy_attrs) end From 41917374132a138c25d459081aa0fad745692784 Mon Sep 17 00:00:00 2001 From: Mayur Shah Date: Mon, 2 Dec 2024 23:26:12 +0530 Subject: [PATCH 06/25] Updated sample data for brand --- sample/db/samples/products.rb | 11 +++++++++++ sample/db/samples/taxonomies.rb | 2 +- sample/db/samples/taxons.rb | 12 +++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/sample/db/samples/products.rb b/sample/db/samples/products.rb index e2245c24b15..3a7558a5986 100644 --- a/sample/db/samples/products.rb +++ b/sample/db/samples/products.rb @@ -153,6 +153,17 @@ height: 20, width: 10, depth: 5 + }, + { + name: "Solidus laptop", + tax_category:, + shipping_category:, + price: 18.99, + eur_price: 20, + weight: 10, + height: 20, + width: 10, + depth: 5 } ] diff --git a/sample/db/samples/taxonomies.rb b/sample/db/samples/taxonomies.rb index 3c4614b6131..8ceada0cf5e 100644 --- a/sample/db/samples/taxonomies.rb +++ b/sample/db/samples/taxonomies.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -store = Spree::Store.where(code: 'sample-store').first +store = Spree::Store.find_by!(code: 'sample-store') taxonomies = [ { name: "Categories", store: }, diff --git a/sample/db/samples/taxons.rb b/sample/db/samples/taxons.rb index 8d96e53e3a8..9fa0e8560eb 100644 --- a/sample/db/samples/taxons.rb +++ b/sample/db/samples/taxons.rb @@ -4,6 +4,7 @@ Spree::Sample.load_sample("products") categories = Spree::Taxonomy.find_by!(name: "Categories") +brands = Spree::Taxonomy.find_by!(name: "Brands") products = { solidus_bottles: "Solidus Water Bottle", @@ -17,7 +18,8 @@ solidus_long_sleeve_tee: "Solidus long sleeve tee", solidus_dark_tee: "Solidus dark tee", solidus_canvas_tote: "Solidus canvas tote bag", - solidus_cap: "Solidus cap" + solidus_cap: "Solidus cap", + solidus_laptop: "Solidus laptop" } products.each do |key, name| @@ -90,6 +92,14 @@ products: [ products[:solidus_hoodie], ] + }, + { + name: "Laptop", + taxonomy: brands, + parent: "Brands", + products: [ + products[:solidus_laptop] + ] } ] From ff80b7cc2b3d27c1ddcf5d0363a77f3c048c3f6e Mon Sep 17 00:00:00 2001 From: Mayur Shah Date: Tue, 3 Dec 2024 00:49:38 +0530 Subject: [PATCH 07/25] Code improvement --- sample/db/samples/products.rb | 11 ----------- sample/db/samples/taxons.rb | 13 ++----------- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/sample/db/samples/products.rb b/sample/db/samples/products.rb index 3a7558a5986..e2245c24b15 100644 --- a/sample/db/samples/products.rb +++ b/sample/db/samples/products.rb @@ -153,17 +153,6 @@ height: 20, width: 10, depth: 5 - }, - { - name: "Solidus laptop", - tax_category:, - shipping_category:, - price: 18.99, - eur_price: 20, - weight: 10, - height: 20, - width: 10, - depth: 5 } ] diff --git a/sample/db/samples/taxons.rb b/sample/db/samples/taxons.rb index 9fa0e8560eb..b50dc3da995 100644 --- a/sample/db/samples/taxons.rb +++ b/sample/db/samples/taxons.rb @@ -18,8 +18,7 @@ solidus_long_sleeve_tee: "Solidus long sleeve tee", solidus_dark_tee: "Solidus dark tee", solidus_canvas_tote: "Solidus canvas tote bag", - solidus_cap: "Solidus cap", - solidus_laptop: "Solidus laptop" + solidus_cap: "Solidus cap" } products.each do |key, name| @@ -87,19 +86,11 @@ }, { name: "Hoodies", - taxonomy: categories, + taxonomy: brands, parent: "Clothing", products: [ products[:solidus_hoodie], ] - }, - { - name: "Laptop", - taxonomy: brands, - parent: "Brands", - products: [ - products[:solidus_laptop] - ] } ] From aeb106d51246b378f736391f9e3bfed091d0e71a Mon Sep 17 00:00:00 2001 From: shahmayur001 Date: Wed, 20 Nov 2024 23:53:02 +0530 Subject: [PATCH 08/25] Corrected the reference --- core/app/models/spree/product.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb index cb32b251f92..03193148ec0 100644 --- a/core/app/models/spree/product.rb +++ b/core/app/models/spree/product.rb @@ -292,7 +292,7 @@ def gallery end def brand - Spree::Config.brand_selector_class.new(product).call + Spree::Config.brand_selector_class.new(self).call end private From bb4338287ee7417501d962ae7611e2683b0b0b75 Mon Sep 17 00:00:00 2001 From: Mayur Shah Date: Mon, 2 Dec 2024 23:24:18 +0530 Subject: [PATCH 09/25] Fixed store validation issue --- sample/db/samples/taxonomies.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sample/db/samples/taxonomies.rb b/sample/db/samples/taxonomies.rb index c3a30e0b79a..3c4614b6131 100644 --- a/sample/db/samples/taxonomies.rb +++ b/sample/db/samples/taxonomies.rb @@ -1,10 +1,11 @@ # frozen_string_literal: true +store = Spree::Store.where(code: 'sample-store').first + taxonomies = [ - { name: "Categories" }, - { name: "Brand" } + { name: "Categories", store: }, + { name: "Brands", store: } ] - taxonomies.each do |taxonomy_attrs| - Spree::Taxonomy.create!(taxonomy_attrs) + Spree::Taxonomy.find_or_create_by!(taxonomy_attrs) end From 80dab82fb02a000c6b532621f31b0809f6cccdff Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Fri, 15 Nov 2024 15:44:43 +0100 Subject: [PATCH 10/25] chore(github labeler): Add labels for new promotion gems We released two new gems and need the appropriate labels for the pull request reviews. --- .github/labeler.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/labeler.yml b/.github/labeler.yml index e7f0f9028d2..0b59473b94a 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -18,6 +18,16 @@ - changed-files: - any-glob-to-any-file: - "admin/**/*" +"changelog:solidus_promotions": +- any: + - changed-files: + - any-glob-to-any-file: + - "promotions/**/*" +"changelog:solidus_legacy_promotions": +- any: + - changed-files: + - any-glob-to-any-file: + - "legacy_promotions/**/*" "changelog:solidus_sample": - any: - changed-files: @@ -40,6 +50,8 @@ - "!backend/**/*" - "!api/**/*" - "!admin/**/*" + - "!promotions/**/*" + - "!legacy_promotions/**/*" - "!sample/**/*" - "!lib/**/*" - "!README.md" From a2e288f6b116e5a118c3e6ec920d98094ff7a451 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Fri, 15 Nov 2024 21:32:12 +0100 Subject: [PATCH 11/25] Feat(Admin): Dynamic routing proxies This commit allows the menu of the new admin to accomodate routes from other engines than solidus backend and solidus admin. This is needed for `solidus_promotions`, which is built as a separate Rails Engine, but it is also convenient for `solidus_paypal_commerce_platform` or even for integrating gems like AlchemyCMS lateron. Co-Authored-By: thomas@vondeyen.com --- .../components/solidus_admin/base_component.rb | 18 ++++++++++++++---- .../layout/navigation/item/component.html.erb | 4 ++-- .../layout/navigation/item/component.rb | 9 +++------ .../solidus_promotions_benefit/component.rb | 4 ---- .../promotions/index/component.rb | 4 ---- 5 files changed, 19 insertions(+), 20 deletions(-) diff --git a/admin/app/components/solidus_admin/base_component.rb b/admin/app/components/solidus_admin/base_component.rb index e41e65235cf..e3adf62c02f 100644 --- a/admin/app/components/solidus_admin/base_component.rb +++ b/admin/app/components/solidus_admin/base_component.rb @@ -38,12 +38,22 @@ def self.stimulus_id delegate :stimulus_id, to: :class - def spree - @spree ||= Spree::Core::Engine.routes.url_helpers + class << self + private + + def engines_with_routes + Rails::Engine.subclasses.map(&:instance).reject do |engine| + engine.routes.empty? + end + end end - def solidus_admin - @solidus_admin ||= SolidusAdmin::Engine.routes.url_helpers + # For each engine with routes, define a method that returns the routes proxy. + # This allows us to use the routes in the context of a component class. + engines_with_routes.each do |engine| + define_method(engine.engine_name) do + engine.routes.url_helpers + end end end end diff --git a/admin/app/components/solidus_admin/layout/navigation/item/component.html.erb b/admin/app/components/solidus_admin/layout/navigation/item/component.html.erb index d3270a08c07..575872b242b 100644 --- a/admin/app/components/solidus_admin/layout/navigation/item/component.html.erb +++ b/admin/app/components/solidus_admin/layout/navigation/item/component.html.erb @@ -1,7 +1,7 @@
  • "> " + aria-current="<%= @item.current?(self, @fullpath) ? "page" : "false" %>" class=" flex gap-3 items-center py-1 px-3 rounded @@ -20,7 +20,7 @@ <% if @item.children? %>
      "> - <%= render self.class.with_collection(@item.children, url_helpers: @url_helpers, fullpath: @fullpath) %> + <%= render self.class.with_collection(@item.children, fullpath: @fullpath) %>
    <% end %>
  • diff --git a/admin/app/components/solidus_admin/layout/navigation/item/component.rb b/admin/app/components/solidus_admin/layout/navigation/item/component.rb index 17ac8a62f74..f05c95a47bb 100644 --- a/admin/app/components/solidus_admin/layout/navigation/item/component.rb +++ b/admin/app/components/solidus_admin/layout/navigation/item/component.rb @@ -6,22 +6,19 @@ class SolidusAdmin::Layout::Navigation::Item::Component < SolidusAdmin::BaseComp # @param item [SolidusAdmin::MenuItem] # @param fullpath [String] the current path - # @param url_helpers [#solidus_admin, #spree] context for generating paths def initialize( item:, - fullpath: "#", - url_helpers: Struct.new(:spree, :solidus_admin).new(spree, solidus_admin) + fullpath: "#" ) @item = item - @url_helpers = url_helpers @fullpath = fullpath end def path - @item.path(@url_helpers) + @item.path(self) end def active? - @item.active?(@url_helpers, @fullpath) + @item.active?(self, @fullpath) end end diff --git a/promotions/lib/components/admin/solidus_admin/orders/show/adjustments/index/source/solidus_promotions_benefit/component.rb b/promotions/lib/components/admin/solidus_admin/orders/show/adjustments/index/source/solidus_promotions_benefit/component.rb index 3f24c7c478f..0ceee3408cf 100644 --- a/promotions/lib/components/admin/solidus_admin/orders/show/adjustments/index/source/solidus_promotions_benefit/component.rb +++ b/promotions/lib/components/admin/solidus_admin/orders/show/adjustments/index/source/solidus_promotions_benefit/component.rb @@ -10,8 +10,4 @@ def detail def promotion_name source.promotion.name end - - def solidus_promotions - @solidus_promotions ||= SolidusPromotions::Engine.routes.url_helpers - end end diff --git a/promotions/lib/components/admin/solidus_promotions/promotions/index/component.rb b/promotions/lib/components/admin/solidus_promotions/promotions/index/component.rb index 19cf4b79772..4d64c3164e9 100644 --- a/promotions/lib/components/admin/solidus_promotions/promotions/index/component.rb +++ b/promotions/lib/components/admin/solidus_promotions/promotions/index/component.rb @@ -101,8 +101,4 @@ def columns } ] end - - def solidus_promotions - @solidus_promotions ||= SolidusPromotions::Engine.routes.url_helpers - end end From f0e36494ada1c447fea1a0e0570ad2da903f8a9f Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Fri, 15 Nov 2024 21:43:31 +0100 Subject: [PATCH 12/25] Fix(Admin menus): Stable promotion menu items This makes sure that the promotion menus are always below the product menu item, in both new admin and the backend. It also changes the nomenclature to be "Promotions" for the legacy promotion system and "Promotions (new)" for the new promotion system. --- legacy_promotions/config/locales/en.yml | 8 +++- .../lib/solidus_legacy_promotions/engine.rb | 25 ++++++++++--- promotions/config/locales/en.yml | 8 +++- promotions/lib/solidus_promotions/engine.rb | 37 +++++++++++++++++-- .../backend/main_menu_spec.rb | 12 +++--- 5 files changed, 70 insertions(+), 20 deletions(-) diff --git a/legacy_promotions/config/locales/en.yml b/legacy_promotions/config/locales/en.yml index b83109c7def..906570b727c 100644 --- a/legacy_promotions/config/locales/en.yml +++ b/legacy_promotions/config/locales/en.yml @@ -1,4 +1,8 @@ en: + solidus_admin: + menu_item: + legacy_promotions: Promotions + legacy_promotion_categories: Promotion Categories spree: admin: promotion_status: @@ -23,8 +27,8 @@ en: general: General starts_at_placeholder: Immediately tab: - promotions: Legacy Promotions - promotion_categories: Legacy Promotion Categories + legacy_promotions: Promotions + legacy_promotion_categories: Promotion Categories back_to_promotion_categories_list: Back To Promotions Categories List back_to_promotions_list: Back To Promotions List base_amount: Base Amount diff --git a/legacy_promotions/lib/solidus_legacy_promotions/engine.rb b/legacy_promotions/lib/solidus_legacy_promotions/engine.rb index 4c34fc3252e..ba7fe49583e 100644 --- a/legacy_promotions/lib/solidus_legacy_promotions/engine.rb +++ b/legacy_promotions/lib/solidus_legacy_promotions/engine.rb @@ -9,7 +9,7 @@ class Engine < ::Rails::Engine initializer "solidus_legacy_promotions.add_backend_menu_item" do if SolidusSupport.backend_available? promotions_menu_item = Spree::BackendConfiguration::MenuItem.new( - label: :promotions, + label: :legacy_promotions, icon: Spree::Backend::Config.admin_updated_navbar ? "ri-megaphone-line" : "bullhorn", partial: "spree/admin/shared/promotion_sub_menu", condition: -> { can?(:admin, Spree::Promotion) }, @@ -17,11 +17,12 @@ class Engine < ::Rails::Engine data_hook: :admin_promotion_sub_tabs, children: [ Spree::BackendConfiguration::MenuItem.new( - label: :promotions, - condition: -> { can?(:admin, Spree::Promotion) } + label: :legacy_promotions, + condition: -> { can?(:admin, Spree::Promotion) }, + url: :admin_promotions_path ), Spree::BackendConfiguration::MenuItem.new( - label: :promotion_categories, + label: :legacy_promotion_categories, condition: -> { can?(:admin, Spree::PromotionCategory) }, url: -> { Spree::Core::Engine.routes.url_helpers.admin_promotion_categories_path }, ) @@ -42,10 +43,22 @@ class Engine < ::Rails::Engine if SolidusSupport.admin_available? SolidusAdmin::Config.configure do |config| config.menu_items << { - key: "promotions", + key: "legacy_promotions", route: -> { spree.admin_promotions_path }, icon: "megaphone-line", - position: 30 + position: 1.5, + children: [ + { + key: "legacy_promotions", + route: -> { spree.admin_promotions_path }, + position: 1 + }, + { + key: "legacy_promotion_categories", + route: -> { spree.admin_promotion_categories_path }, + position: 2 + } + ] } end end diff --git a/promotions/config/locales/en.yml b/promotions/config/locales/en.yml index 06d3f481825..d4b56d3ccb8 100644 --- a/promotions/config/locales/en.yml +++ b/promotions/config/locales/en.yml @@ -2,11 +2,15 @@ # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. en: + solidus_admin: + menu_item: + promotions: Promotions (new) + promotion_categories: Promotion Categories (new) spree: admin: tab: - solidus_promotions: Promotions - solidus_promotion_categories: Promotion Categories + promotions: Promotions (new) + promotion_categories: Promotion Categories (new) hints: solidus_promotions/promotion: expires_at: This determines when the promotion expires.
    If no value is specified, the promotion will never expire. diff --git a/promotions/lib/solidus_promotions/engine.rb b/promotions/lib/solidus_promotions/engine.rb index 4170581ec02..2225ee1cda6 100644 --- a/promotions/lib/solidus_promotions/engine.rb +++ b/promotions/lib/solidus_promotions/engine.rb @@ -60,30 +60,59 @@ class Engine < Rails::Engine end end + initializer "solidus_promotions.add_solidus_admin_menu_items", after: "spree.load_config_initializers" do + if SolidusSupport.admin_available? + SolidusAdmin::Config.configure do |config| + config.menu_items << { + key: "promotions", + route: -> { solidus_promotions.admin_promotions_path }, + icon: "megaphone-line", + position: 1.6, + children: [ + { + key: "promotions", + route: -> { solidus_promotions.admin_promotions_path }, + position: 1 + }, + { + key: "promotion_categories", + route: -> { solidus_promotions.admin_promotion_categories_path }, + position: 1 + } + ] + } + end + end + end + initializer "solidus_promotions.add_backend_menus", after: "spree.backend.environment" do if SolidusSupport.backend_available? promotions_menu_item = Spree::BackendConfiguration::MenuItem.new( - label: :solidus_promotions, + label: :promotions, icon: Spree::Backend::Config.admin_updated_navbar ? "ri-megaphone-line" : "bullhorn", condition: -> { can?(:admin, SolidusPromotions::Promotion) }, url: -> { SolidusPromotions::Engine.routes.url_helpers.admin_promotions_path }, data_hook: :admin_solidus_promotion_sub_tabs, children: [ Spree::BackendConfiguration::MenuItem.new( - label: :solidus_promotions, + label: :promotions, url: -> { SolidusPromotions::Engine.routes.url_helpers.admin_promotions_path }, condition: -> { can?(:admin, SolidusPromotions::Promotion) } ), Spree::BackendConfiguration::MenuItem.new( - label: :solidus_promotion_categories, + label: :promotion_categories, url: -> { SolidusPromotions::Engine.routes.url_helpers.admin_promotion_categories_path }, condition: -> { can?(:admin, SolidusPromotions::PromotionCategory) } ) ] ) + # We want to appear after the legacy promotions menu item if it exists, otherwise after the products menu item product_menu_item_index = Spree::Backend::Config.menu_items.find_index { |item| item.label == :products } - Spree::Backend::Config.menu_items.insert(product_menu_item_index + 1, promotions_menu_item) + legacy_promotions_menu_item = Spree::Backend::Config.menu_items.find_index { |item| item.label == :legacy_promotions } + promotions_menu_index = [product_menu_item_index, legacy_promotions_menu_item].compact.max + 1 + + Spree::Backend::Config.menu_items.insert(promotions_menu_index, promotions_menu_item) end end end diff --git a/promotions/spec/system/solidus_promotions/backend/main_menu_spec.rb b/promotions/spec/system/solidus_promotions/backend/main_menu_spec.rb index 73021eba6aa..788365fcc98 100644 --- a/promotions/spec/system/solidus_promotions/backend/main_menu_spec.rb +++ b/promotions/spec/system/solidus_promotions/backend/main_menu_spec.rb @@ -12,10 +12,10 @@ end it "should have a link to promotions" do - expect(page).to have_link("Promotions", href: solidus_promotions.admin_promotions_path, count: 2) + expect(page).to have_link("Promotions (new)", href: solidus_promotions.admin_promotions_path, count: 2) end it "should have a link to legacy promotions" do - expect(page).to have_link("Legacy Promotions", href: spree.admin_promotions_path, count: 2) + expect(page).to have_link("Promotions", href: spree.admin_promotions_path, count: 2) end end @@ -25,11 +25,11 @@ end it "should have a link to promotions" do - within(".selected .admin-subnav") { expect(page).to have_link("Promotions", href: solidus_promotions.admin_promotions_path) } + within(".selected .admin-subnav") { expect(page).to have_link("Promotions (new)", href: solidus_promotions.admin_promotions_path) } end it "should have a link to promotion categories" do - within(".selected .admin-subnav") { expect(page).to have_link("Promotion Categories", href: solidus_promotions.admin_promotion_categories_path) } + within(".selected .admin-subnav") { expect(page).to have_link("Promotion Categories (new)", href: solidus_promotions.admin_promotion_categories_path) } end end @@ -39,11 +39,11 @@ end it "should have a link to promotions" do - within(".selected .admin-subnav") { expect(page).to have_link("Legacy Promotions", href: spree.admin_promotions_path) } + within(".selected .admin-subnav") { expect(page).to have_link("Promotions", href: spree.admin_promotions_path) } end it "should have a link to promotion categories" do - within(".selected .admin-subnav") { expect(page).to have_link("Legacy Promotion Categories", href: spree.admin_promotion_categories_path) } + within(".selected .admin-subnav") { expect(page).to have_link("Promotion Categories", href: spree.admin_promotion_categories_path) } end end end From 4541a6c2b0a1c71a1a610e8fe84fbb75cd851aac Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Fri, 15 Nov 2024 22:13:46 +0100 Subject: [PATCH 13/25] Feat(SolidusPromotions): Allow viewing both promotion systems Prior to this commit, the new promotion system would exchange the promotion and promotion category index page components if the gem was loaded. This made it impossible to actually see the old promotion configuration when using the new admin. This commit now only changes the orders/index component if the new promotion system is activated. In any case, it will display new promotion and promotion category records under "Promotions (new)". --- .../promotion_categories_controller.rb | 2 +- .../admin/solidus_promotions/promotions_controller.rb | 2 +- promotions/lib/solidus_promotions/engine.rb | 11 +++++++---- .../solidus_promotions/admin/orders/index_spec.rb | 6 ++++++ 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/promotions/lib/controllers/admin/solidus_promotions/promotion_categories_controller.rb b/promotions/lib/controllers/admin/solidus_promotions/promotion_categories_controller.rb index f27166e38d5..cefb9d44d5d 100644 --- a/promotions/lib/controllers/admin/solidus_promotions/promotion_categories_controller.rb +++ b/promotions/lib/controllers/admin/solidus_promotions/promotion_categories_controller.rb @@ -13,7 +13,7 @@ def index set_page_and_extract_portion_from(promotion_categories) respond_to do |format| - format.html { render component("promotion_categories/index").new(page: @page) } + format.html { render component("solidus_promotions/categories/index").new(page: @page) } end end diff --git a/promotions/lib/controllers/admin/solidus_promotions/promotions_controller.rb b/promotions/lib/controllers/admin/solidus_promotions/promotions_controller.rb index de2fcf25f78..77bc6515108 100644 --- a/promotions/lib/controllers/admin/solidus_promotions/promotions_controller.rb +++ b/promotions/lib/controllers/admin/solidus_promotions/promotions_controller.rb @@ -19,7 +19,7 @@ def index set_page_and_extract_portion_from(promotions) respond_to do |format| - format.html { render component("promotions/index").new(page: @page) } + format.html { render component("solidus_promotions/promotions/index").new(page: @page) } end end diff --git a/promotions/lib/solidus_promotions/engine.rb b/promotions/lib/solidus_promotions/engine.rb index 2225ee1cda6..29df050ba6d 100644 --- a/promotions/lib/solidus_promotions/engine.rb +++ b/promotions/lib/solidus_promotions/engine.rb @@ -52,11 +52,14 @@ class Engine < Rails::Engine end end - initializer "solidus_promotions.add_admin_order_index_component", after: "solidus_legacy_promotions.add_admin_order_index_component" do + initializer "solidus_promotions.add_admin_order_index_component", after: "spree.load_config_initializers" do if SolidusSupport.admin_available? - SolidusAdmin::Config.components["orders/index"] = "SolidusPromotions::Orders::Index::Component" - SolidusAdmin::Config.components["promotions/index"] = "SolidusPromotions::Promotions::Index::Component" - SolidusAdmin::Config.components["promotion_categories/index"] = "SolidusPromotions::PromotionCategories::Index::Component" + if Spree::Config.promotions.is_a?(SolidusPromotions::Configuration) + SolidusAdmin::Config.components["orders/index"] = "SolidusPromotions::Orders::Index::Component" + end + + SolidusAdmin::Config.components["solidus_promotions/promotions/index"] = "SolidusPromotions::Promotions::Index::Component" + SolidusAdmin::Config.components["solidus_promotions/categories/index"] = "SolidusPromotions::PromotionCategories::Index::Component" end end diff --git a/promotions/spec/system/solidus_promotions/admin/orders/index_spec.rb b/promotions/spec/system/solidus_promotions/admin/orders/index_spec.rb index dc6304eb355..159ef8a0a31 100644 --- a/promotions/spec/system/solidus_promotions/admin/orders/index_spec.rb +++ b/promotions/spec/system/solidus_promotions/admin/orders/index_spec.rb @@ -9,6 +9,12 @@ before { sign_in create(:admin_user, email: "admin@example.com") } + around do |example| + SolidusAdmin::Config.components["orders/index"] = "SolidusPromotions::Orders::Index::Component" + example.run + SolidusAdmin::Config.components["orders/index"] = "SolidusAdmin::Orders::Index::Component" + end + it "lists products", :js, :flaky do visit "/admin/orders" From b7bbce3e2faf0b28828ab97f2e6d47b212c899c3 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Tue, 19 Nov 2024 09:00:20 +0100 Subject: [PATCH 14/25] Include solidus_legacy_promotions in release task Not sure how we missed that when including `solidus_promotions`. --- tasks/releasing.rake | 2 +- tasks/testing.rake | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks/releasing.rake b/tasks/releasing.rake index 4336ea0f3ce..098192672c5 100644 --- a/tasks/releasing.rake +++ b/tasks/releasing.rake @@ -2,7 +2,7 @@ require 'bundler/gem_tasks' -SOLIDUS_GEM_NAMES = %w[core api backend sample promotions] +SOLIDUS_GEM_NAMES = %w[core api backend sample promotions legacy_promotions] %w[build install].each do |task_name| desc "Run rake #{task} for each Solidus gem" diff --git a/tasks/testing.rake b/tasks/testing.rake index 8ed89ec92c3..e3c62f0eb10 100644 --- a/tasks/testing.rake +++ b/tasks/testing.rake @@ -18,7 +18,7 @@ def subproject_task(project, task, title: project, task_name: nil) end %w[spec db:drop db:create db:migrate db:reset].each do |task| - solidus_gem_names = %w[core api backend sample promotions] + solidus_gem_names = %w[core api backend sample promotions legacy_promotions] solidus_gem_names.each do |project| desc "Run specs for #{project}" if task == 'spec' subproject_task(project, task) From 46506466f29de260a4a7ee418b32224353cf5b63 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Tue, 19 Nov 2024 09:19:28 +0100 Subject: [PATCH 15/25] Add `#authorization_subject` to Promotions controllers The `authorization_subject` method from `solidus_admin` assumes that all models are in the `Spree` namespace. --- .../solidus_promotions/promotion_categories_controller.rb | 6 ++++++ .../admin/solidus_promotions/promotions_controller.rb | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/promotions/lib/controllers/admin/solidus_promotions/promotion_categories_controller.rb b/promotions/lib/controllers/admin/solidus_promotions/promotion_categories_controller.rb index cefb9d44d5d..0218e3a94c2 100644 --- a/promotions/lib/controllers/admin/solidus_promotions/promotion_categories_controller.rb +++ b/promotions/lib/controllers/admin/solidus_promotions/promotion_categories_controller.rb @@ -25,5 +25,11 @@ def destroy flash[:notice] = t(".success") redirect_back_or_to solidus_promotions.promotion_categories_path, status: :see_other end + + private + + def authorization_subject + SolidusPromotions::PromotionCategory + end end end diff --git a/promotions/lib/controllers/admin/solidus_promotions/promotions_controller.rb b/promotions/lib/controllers/admin/solidus_promotions/promotions_controller.rb index 77bc6515108..62b856006a0 100644 --- a/promotions/lib/controllers/admin/solidus_promotions/promotions_controller.rb +++ b/promotions/lib/controllers/admin/solidus_promotions/promotions_controller.rb @@ -42,5 +42,9 @@ def load_promotion def promotion_params params.require(:promotion).permit(:user_id, permitted_promotion_attributes) end + + def authorization_subject + SolidusPromotions::Promotion + end end end From e9a111c51d1406b5334dbc37ba6df0919629aed3 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Tue, 19 Nov 2024 09:50:49 +0100 Subject: [PATCH 16/25] Fix admin promotions controller This controller still did not know how what to authorize against, and wanted to visit a URL that doesn't exist when clicking on a promotion. This also changes at least the name of each promotion to be a link element that can easily be targeted with Capybara and works with all major browsers. --- .../solidus_promotions/promotions/index/component.rb | 10 ++++++---- .../solidus_promotions/promotions/index/component.yml | 1 + .../system/solidus_promotions/admin/promotions_spec.rb | 4 ++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/promotions/lib/components/admin/solidus_promotions/promotions/index/component.rb b/promotions/lib/components/admin/solidus_promotions/promotions/index/component.rb index 4d64c3164e9..8416e5d343c 100644 --- a/promotions/lib/components/admin/solidus_promotions/promotions/index/component.rb +++ b/promotions/lib/components/admin/solidus_promotions/promotions/index/component.rb @@ -14,7 +14,7 @@ def search_url end def row_url(promotion) - solidus_promotions.admin_promotion_path(promotion) + solidus_promotions.edit_admin_promotion_path(promotion) end def page_actions @@ -63,14 +63,16 @@ def columns { header: :name, data: ->(promotion) do - content_tag :div, promotion.name + link_to promotion.name, row_url(promotion) end }, { header: :code, data: ->(promotion) do - count = promotion.codes.count - (count == 1) ? promotion.codes.pick(:value) : t("spree.number_of_codes", count: count) + link_to solidus_promotions.admin_promotion_promotion_codes_path(promotion), title: t(".codes") do + count = promotion.codes.count + (count == 1) ? promotion.codes.pick(:value) : t("spree.number_of_codes", count: count) + end end }, { diff --git a/promotions/lib/components/admin/solidus_promotions/promotions/index/component.yml b/promotions/lib/components/admin/solidus_promotions/promotions/index/component.yml index 7ba70160390..cf53ebf0d54 100644 --- a/promotions/lib/components/admin/solidus_promotions/promotions/index/component.yml +++ b/promotions/lib/components/admin/solidus_promotions/promotions/index/component.yml @@ -8,3 +8,4 @@ en: status: active: Active inactive: Inactive + codes: Codes diff --git a/promotions/spec/system/solidus_promotions/admin/promotions_spec.rb b/promotions/spec/system/solidus_promotions/admin/promotions_spec.rb index b49bbd94d37..ddc65c9b46f 100644 --- a/promotions/spec/system/solidus_promotions/admin/promotions_spec.rb +++ b/promotions/spec/system/solidus_promotions/admin/promotions_spec.rb @@ -32,5 +32,9 @@ expect(page).to have_content("Promotions were successfully removed.") expect(page).not_to have_content("My active Promotion") expect(SolidusPromotions::Promotion.count).to eq(3) + + click_link("My future Promotion") + expect(page).to have_content("My future Promotion") + expect(page).to have_content("Starts at") end end From bf2ee9e681cc14dfc9ec7b366c2eb8fce99a9190 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Tue, 19 Nov 2024 20:38:40 +0100 Subject: [PATCH 17/25] Release solidus_admin/v0.3.2 --- admin/lib/solidus_admin/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/lib/solidus_admin/version.rb b/admin/lib/solidus_admin/version.rb index 838637885d0..352f61370ad 100644 --- a/admin/lib/solidus_admin/version.rb +++ b/admin/lib/solidus_admin/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module SolidusAdmin - VERSION = "0.3.1" + VERSION = "0.3.2" end From 110e05423d1b0459fabe82d6d8f8400228bb9016 Mon Sep 17 00:00:00 2001 From: Chris Todorov Date: Thu, 14 Nov 2024 13:50:33 -0800 Subject: [PATCH 18/25] Allow PORT to be specified when using `bin/dev` Previously this would force the development server to run on 3000, but it is useful to be able to override that. Co-authored-by: Harmony Evangelina --- bin/dev | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/dev b/bin/dev index 20dee8d5d1e..a55e33a5e0f 100755 --- a/bin/dev +++ b/bin/dev @@ -9,5 +9,5 @@ if ! test -d sandbox; then bin/sandbox fi -export PORT=3000 +export PORT=${PORT:-3000} exec foreman start -f Procfile.dev "$@" From c95c7b2f491ff91dc585b00b72e90e62b15541c3 Mon Sep 17 00:00:00 2001 From: Mayur Shah Date: Mon, 2 Dec 2024 23:26:12 +0530 Subject: [PATCH 19/25] Updated sample data for brand --- sample/db/samples/products.rb | 11 +++++++++++ sample/db/samples/taxonomies.rb | 2 +- sample/db/samples/taxons.rb | 12 +++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/sample/db/samples/products.rb b/sample/db/samples/products.rb index e2245c24b15..3a7558a5986 100644 --- a/sample/db/samples/products.rb +++ b/sample/db/samples/products.rb @@ -153,6 +153,17 @@ height: 20, width: 10, depth: 5 + }, + { + name: "Solidus laptop", + tax_category:, + shipping_category:, + price: 18.99, + eur_price: 20, + weight: 10, + height: 20, + width: 10, + depth: 5 } ] diff --git a/sample/db/samples/taxonomies.rb b/sample/db/samples/taxonomies.rb index 3c4614b6131..8ceada0cf5e 100644 --- a/sample/db/samples/taxonomies.rb +++ b/sample/db/samples/taxonomies.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -store = Spree::Store.where(code: 'sample-store').first +store = Spree::Store.find_by!(code: 'sample-store') taxonomies = [ { name: "Categories", store: }, diff --git a/sample/db/samples/taxons.rb b/sample/db/samples/taxons.rb index 8d96e53e3a8..9fa0e8560eb 100644 --- a/sample/db/samples/taxons.rb +++ b/sample/db/samples/taxons.rb @@ -4,6 +4,7 @@ Spree::Sample.load_sample("products") categories = Spree::Taxonomy.find_by!(name: "Categories") +brands = Spree::Taxonomy.find_by!(name: "Brands") products = { solidus_bottles: "Solidus Water Bottle", @@ -17,7 +18,8 @@ solidus_long_sleeve_tee: "Solidus long sleeve tee", solidus_dark_tee: "Solidus dark tee", solidus_canvas_tote: "Solidus canvas tote bag", - solidus_cap: "Solidus cap" + solidus_cap: "Solidus cap", + solidus_laptop: "Solidus laptop" } products.each do |key, name| @@ -90,6 +92,14 @@ products: [ products[:solidus_hoodie], ] + }, + { + name: "Laptop", + taxonomy: brands, + parent: "Brands", + products: [ + products[:solidus_laptop] + ] } ] From 03aba31f188b5217de9b0918725bed29c33560f8 Mon Sep 17 00:00:00 2001 From: Mayur Shah Date: Tue, 3 Dec 2024 00:49:38 +0530 Subject: [PATCH 20/25] Code improvement --- sample/db/samples/products.rb | 11 ----------- sample/db/samples/taxons.rb | 13 ++----------- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/sample/db/samples/products.rb b/sample/db/samples/products.rb index 3a7558a5986..e2245c24b15 100644 --- a/sample/db/samples/products.rb +++ b/sample/db/samples/products.rb @@ -153,17 +153,6 @@ height: 20, width: 10, depth: 5 - }, - { - name: "Solidus laptop", - tax_category:, - shipping_category:, - price: 18.99, - eur_price: 20, - weight: 10, - height: 20, - width: 10, - depth: 5 } ] diff --git a/sample/db/samples/taxons.rb b/sample/db/samples/taxons.rb index 9fa0e8560eb..b50dc3da995 100644 --- a/sample/db/samples/taxons.rb +++ b/sample/db/samples/taxons.rb @@ -18,8 +18,7 @@ solidus_long_sleeve_tee: "Solidus long sleeve tee", solidus_dark_tee: "Solidus dark tee", solidus_canvas_tote: "Solidus canvas tote bag", - solidus_cap: "Solidus cap", - solidus_laptop: "Solidus laptop" + solidus_cap: "Solidus cap" } products.each do |key, name| @@ -87,19 +86,11 @@ }, { name: "Hoodies", - taxonomy: categories, + taxonomy: brands, parent: "Clothing", products: [ products[:solidus_hoodie], ] - }, - { - name: "Laptop", - taxonomy: brands, - parent: "Brands", - products: [ - products[:solidus_laptop] - ] } ] From b670f557a6a484868dcd8678c106f4d7cba1fa04 Mon Sep 17 00:00:00 2001 From: Fab Date: Mon, 2 Dec 2024 21:41:11 +0100 Subject: [PATCH 21/25] Revert "Updated sample data for brand" This reverts commit 41917374132a138c25d459081aa0fad745692784. --- sample/db/samples/taxonomies.rb | 2 +- sample/db/samples/taxons.rb | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/sample/db/samples/taxonomies.rb b/sample/db/samples/taxonomies.rb index 8ceada0cf5e..3c4614b6131 100644 --- a/sample/db/samples/taxonomies.rb +++ b/sample/db/samples/taxonomies.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -store = Spree::Store.find_by!(code: 'sample-store') +store = Spree::Store.where(code: 'sample-store').first taxonomies = [ { name: "Categories", store: }, diff --git a/sample/db/samples/taxons.rb b/sample/db/samples/taxons.rb index b50dc3da995..5aa42c10f7b 100644 --- a/sample/db/samples/taxons.rb +++ b/sample/db/samples/taxons.rb @@ -4,7 +4,6 @@ Spree::Sample.load_sample("products") categories = Spree::Taxonomy.find_by!(name: "Categories") -brands = Spree::Taxonomy.find_by!(name: "Brands") products = { solidus_bottles: "Solidus Water Bottle", From 96974e0c40a42c42fb64061d84ffdf0439017081 Mon Sep 17 00:00:00 2001 From: Fab Date: Mon, 2 Dec 2024 22:03:08 +0100 Subject: [PATCH 22/25] Added Sample Data for Brands --- sample/db/samples/taxons.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/sample/db/samples/taxons.rb b/sample/db/samples/taxons.rb index b50dc3da995..859387d217f 100644 --- a/sample/db/samples/taxons.rb +++ b/sample/db/samples/taxons.rb @@ -4,7 +4,6 @@ Spree::Sample.load_sample("products") categories = Spree::Taxonomy.find_by!(name: "Categories") -brands = Spree::Taxonomy.find_by!(name: "Brands") products = { solidus_bottles: "Solidus Water Bottle", @@ -30,6 +29,18 @@ name: "Categories", taxonomy: categories, }, + { + name: "Brands", + taxonomy: Brands, + }, + { + name: "Solidus", + taxonomy: categories, + parent: "Brands", + products: [ + products[:solidus_cap] + ] + }, { name: "Clothing", taxonomy: categories, @@ -86,7 +97,7 @@ }, { name: "Hoodies", - taxonomy: brands, + taxonomy: categories, parent: "Clothing", products: [ products[:solidus_hoodie], From a80f7cbc9f110fa423eb4ddb89c3a76728a81904 Mon Sep 17 00:00:00 2001 From: Fab Date: Mon, 2 Dec 2024 22:16:35 +0100 Subject: [PATCH 23/25] Create Solidus Sample Brand Creates a solidus sample brand and adds all products --- sample/db/samples/taxons.rb | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/sample/db/samples/taxons.rb b/sample/db/samples/taxons.rb index 5aa42c10f7b..8bc8fa7a1b7 100644 --- a/sample/db/samples/taxons.rb +++ b/sample/db/samples/taxons.rb @@ -25,6 +25,30 @@ end taxons = [ + { + name: "Brands", + taxonomy: brands + }, + { + name: "Solidus", + taxonomy: brands, + parent: "Brands", + products: [ + products[:solidus_bottles], + products[:solidus_tote], + products[:solidus_hoodie], + products[:solidus_mug_set], + products[:solidus_hat], + products[:solidus_sticker], + products[:solidus_notebook], + products[:solidus_tshirt], + products[:solidus_long_sleeve_tee], + products[:solidus_dark_tee], + products[:solidus_bottles], + products[:solidus_canvas_tote], + products[:solidus_cap] + ] + }, { name: "Categories", taxonomy: categories, @@ -85,7 +109,7 @@ }, { name: "Hoodies", - taxonomy: brands, + taxonomy: categories, parent: "Clothing", products: [ products[:solidus_hoodie], From ef5c3fb13db1d90642f992253fbff2df080f332b Mon Sep 17 00:00:00 2001 From: Fab Date: Mon, 2 Dec 2024 22:23:36 +0100 Subject: [PATCH 24/25] Bugfix Sample Data --- sample/db/samples/taxons.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sample/db/samples/taxons.rb b/sample/db/samples/taxons.rb index 7658de6c81e..cca32012d4c 100644 --- a/sample/db/samples/taxons.rb +++ b/sample/db/samples/taxons.rb @@ -55,7 +55,7 @@ }, { name: "Brands", - taxonomy: Brands, + taxonomy: brands, }, { name: "Solidus", From 3eac54bae71ae3b80532a511694acd39317ebf33 Mon Sep 17 00:00:00 2001 From: Mayur Shah Date: Tue, 3 Dec 2024 03:08:17 +0530 Subject: [PATCH 25/25] Code cleanup --- sample/db/samples/taxons.rb | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/sample/db/samples/taxons.rb b/sample/db/samples/taxons.rb index cca32012d4c..ad7236d87fe 100644 --- a/sample/db/samples/taxons.rb +++ b/sample/db/samples/taxons.rb @@ -4,6 +4,7 @@ Spree::Sample.load_sample("products") categories = Spree::Taxonomy.find_by!(name: "Categories") +brands = Spree::Taxonomy.find_by!(name: "Brands") products = { solidus_bottles: "Solidus Water Bottle", @@ -25,6 +26,10 @@ end taxons = [ + { + name: "Categories", + taxonomy: categories, + }, { name: "Brands", taxonomy: brands @@ -49,14 +54,6 @@ products[:solidus_cap] ] }, - { - name: "Categories", - taxonomy: categories, - }, - { - name: "Brands", - taxonomy: brands, - }, { name: "Solidus", taxonomy: categories,