From bd70d3be4210562a35459fc085f176cd6c9d0694 Mon Sep 17 00:00:00 2001 From: George Mendoza Date: Fri, 17 Feb 2023 11:10:45 +0800 Subject: [PATCH] Inject SolidusBraintree dependencies into controllers Instead of monkeypatching the controllers, which the user already owns. https://github.com/solidusio/solidus_braintree/pull/102#discussion_r1108019774 --- .../solidus_braintree/carts_controller_decorator.rb | 11 ----------- .../checkout_controller_decorator.rb | 11 ----------- .../solidus_braintree/install/install_generator.rb | 12 ++++++++++++ 3 files changed, 12 insertions(+), 22 deletions(-) delete mode 100644 app/decorators/controllers/solidus_braintree/carts_controller_decorator.rb delete mode 100644 app/decorators/controllers/solidus_braintree/checkout_controller_decorator.rb diff --git a/app/decorators/controllers/solidus_braintree/carts_controller_decorator.rb b/app/decorators/controllers/solidus_braintree/carts_controller_decorator.rb deleted file mode 100644 index f3e2e78d..00000000 --- a/app/decorators/controllers/solidus_braintree/carts_controller_decorator.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -module SolidusBraintree - module CartsControllerDecorator - def self.prepended(base) - base.helper ::SolidusBraintree::BraintreeCheckoutHelper - end - - CartsController.prepend(self) - end -end diff --git a/app/decorators/controllers/solidus_braintree/checkout_controller_decorator.rb b/app/decorators/controllers/solidus_braintree/checkout_controller_decorator.rb deleted file mode 100644 index 0eba46ea..00000000 --- a/app/decorators/controllers/solidus_braintree/checkout_controller_decorator.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -module SolidusBraintree - module CheckoutControllerDecorator - def self.prepended(base) - base.helper ::SolidusBraintree::BraintreeCheckoutHelper - end - - ::CheckoutsController.prepend(self) - end -end diff --git a/lib/generators/solidus_braintree/install/install_generator.rb b/lib/generators/solidus_braintree/install/install_generator.rb index b328f11c..cdd05d65 100644 --- a/lib/generators/solidus_braintree/install/install_generator.rb +++ b/lib/generators/solidus_braintree/install/install_generator.rb @@ -53,6 +53,18 @@ def setup_stylesheets " *= require spree/backend/solidus_braintree\n", before: %r{\*/}, verbose: true end + def inject_checkout_helper_to_frontend_controllers + inject_into_class 'app/controllers/checkouts_controller.rb', + 'CheckoutsController', + " helper SolidusBraintree::BraintreeCheckoutHelper\n\n", + verbose: true + + inject_into_class 'app/controllers/carts_controller.rb', + 'CartsController', + " helper SolidusBraintree::BraintreeCheckoutHelper\n\n", + verbose: true + end + def add_migrations rake 'railties:install:migrations FROM=solidus_braintree' end