-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The controller code we were using relied on a patch to Solidus[1] that will only be released with Solidus 4.2. We want to be compatible with Solidus 4 though, so we're incorporating that patch into our own BaseController and use that instead of Solidus' ResourceController. [1] solidusio/solidus#5219
- Loading branch information
Showing
5 changed files
with
58 additions
and
12 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
promotions/app/controllers/solidus_friendly_promotions/admin/base_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# frozen_string_literal: true | ||
|
||
module SolidusFriendlyPromotions | ||
module Admin | ||
class BaseController < Spree::Admin::ResourceController | ||
def parent | ||
@parent ||= self.class.parent_data[:model_class] | ||
.includes(self.class.parent_data[:includes]) | ||
.find_by!(self.class.parent_data[:find_by] => params["#{parent_model_name}_id"]) | ||
instance_variable_set("@#{parent_model_name}", @parent) | ||
rescue ActiveRecord::RecordNotFound => e | ||
resource_not_found(flash_class: e.model.constantize, redirect_url: routes_proxy.polymorphic_url([:admin, parent_model_name.pluralize.to_sym])) | ||
end | ||
|
||
def new_object_url(options = {}) | ||
if parent? | ||
routes_proxy.new_polymorphic_url([:admin, parent, model_class], options) | ||
else | ||
routes_proxy.new_polymorphic_url([:admin, model_class], options) | ||
end | ||
end | ||
|
||
def edit_object_url(object, options = {}) | ||
if parent? | ||
routes_proxy.polymorphic_url([:edit, :admin, parent, object], options) | ||
else | ||
routes_proxy.polymorphic_url([:edit, :admin, object], options) | ||
end | ||
end | ||
|
||
def object_url(object = nil, options = {}) | ||
target = object || @object | ||
|
||
if parent? | ||
routes_proxy.polymorphic_url([:admin, parent, target], options) | ||
else | ||
routes_proxy.polymorphic_url([:admin, target], options) | ||
end | ||
end | ||
|
||
def collection_url(options = {}) | ||
if parent? | ||
routes_proxy.polymorphic_url([:admin, parent, model_class], options) | ||
else | ||
routes_proxy.polymorphic_url([:admin, model_class], options) | ||
end | ||
end | ||
|
||
def routes_proxy | ||
solidus_friendly_promotions | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters