Skip to content

Commit

Permalink
Merge branch 'add_brand_from_config' of https://github.com/gms-electr…
Browse files Browse the repository at this point in the history
…onics/solidus into add_brand_from_config
  • Loading branch information
shahmayur001 committed Dec 2, 2024
2 parents 02519e0 + 273a9da commit fd9f796
Show file tree
Hide file tree
Showing 20 changed files with 141 additions and 54 deletions.
12 changes: 12 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -40,6 +50,8 @@
- "!backend/**/*"
- "!api/**/*"
- "!admin/**/*"
- "!promotions/**/*"
- "!legacy_promotions/**/*"
- "!sample/**/*"
- "!lib/**/*"
- "!README.md"
Expand Down
18 changes: 14 additions & 4 deletions admin/app/components/solidus_admin/base_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<li class="group <%= "active" if active? %>">
<a
href="<%= path %>"
aria-current="<%= @item.current?(@url_helpers, @fullpath) ? "page" : "false" %>"
aria-current="<%= @item.current?(self, @fullpath) ? "page" : "false" %>"
class="
flex gap-3 items-center
py-1 px-3 rounded
Expand All @@ -20,7 +20,7 @@

<% if @item.children? %>
<ul class="flex flex-col gap-0.5 pt-0.5 <%= "hidden" unless active? %>">
<%= render self.class.with_collection(@item.children, url_helpers: @url_helpers, fullpath: @fullpath) %>
<%= render self.class.with_collection(@item.children, fullpath: @fullpath) %>
</ul>
<% end %>
</li>
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion admin/lib/solidus_admin/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module SolidusAdmin
VERSION = "0.3.1"
VERSION = "0.3.2"
end
2 changes: 1 addition & 1 deletion bin/dev
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$@"
8 changes: 6 additions & 2 deletions legacy_promotions/config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
en:
solidus_admin:
menu_item:
legacy_promotions: Promotions
legacy_promotion_categories: Promotion Categories
spree:
admin:
promotion_status:
Expand All @@ -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
Expand Down
25 changes: 19 additions & 6 deletions legacy_promotions/lib/solidus_legacy_promotions/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@ 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) },
url: :admin_promotions_path,
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 },
)
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions promotions/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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. <br> If no value is specified, the promotion will never expire.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
},
{
Expand Down Expand Up @@ -101,8 +103,4 @@ def columns
}
]
end

def solidus_promotions
@solidus_promotions ||= SolidusPromotions::Engine.routes.url_helpers
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ en:
status:
active: Active
inactive: Inactive
codes: Codes
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
48 changes: 40 additions & 8 deletions promotions/lib/solidus_promotions/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,38 +52,70 @@ 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

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@

before { sign_in create(:admin_user, email: "[email protected]") }

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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading

0 comments on commit fd9f796

Please sign in to comment.