From a6e44bd368b566bee7b5000311a7c36a93f0ec2e Mon Sep 17 00:00:00 2001 From: Flavio Auciello Date: Fri, 9 Oct 2020 14:53:54 +0200 Subject: [PATCH] Move `paypal_button_preference` helper method Ref. https://github.com/solidusio/solidus_paypal_braintree/issues/251 Using `Spree::CheckoutController.helper` and `Spree::OrdersController.helper` in `config/initializers/braintree.rb` to include helper modules does not work: at `checkout/payement` step an exception is raised ``` ActionView::Template::Error (undefined method `paypal_button_preference`) ``` This commit move `paypal_button_preferences` (introduced with [1]) in the already present `SolidusPaypalBraintree::BraintreeCheckoutHelper` module, and adds the same helper method to the `Spree::OrdersController` (in the same way done here [2]) to enable the button also in the cart page. [1] https://github.com/solidusio/solidus_paypal_braintree/pull/236 [2] https://github.com/solidusio/solidus_paypal_braintree/pull/232/commits/28d0de963a5e8bf3f8f539dd8bb30d80717b4154 --- .../orders_controller_decorator.rb | 10 ++++++++++ app/helpers/braintree_checkout_helper.rb | 5 ----- .../braintree_checkout_helper.rb | 3 +++ config/initializers/braintree.rb | 5 ----- 4 files changed, 13 insertions(+), 10 deletions(-) create mode 100644 app/controllers/solidus_paypal_braintree/orders_controller_decorator.rb delete mode 100644 app/helpers/braintree_checkout_helper.rb diff --git a/app/controllers/solidus_paypal_braintree/orders_controller_decorator.rb b/app/controllers/solidus_paypal_braintree/orders_controller_decorator.rb new file mode 100644 index 00000000..67791bf3 --- /dev/null +++ b/app/controllers/solidus_paypal_braintree/orders_controller_decorator.rb @@ -0,0 +1,10 @@ +module SolidusPaypalBraintree + module OrdersControllerDecorator + + def self.prepended(base) + base.helper ::SolidusPaypalBraintree::BraintreeCheckoutHelper + end + + ::Spree::OrdersController.prepend(self) + end +end diff --git a/app/helpers/braintree_checkout_helper.rb b/app/helpers/braintree_checkout_helper.rb deleted file mode 100644 index d481dc58..00000000 --- a/app/helpers/braintree_checkout_helper.rb +++ /dev/null @@ -1,5 +0,0 @@ -module BraintreeCheckoutHelper - def paypal_button_preference(key, store:) - store.braintree_configuration.preferences[key] - end -end diff --git a/app/helpers/solidus_paypal_braintree/braintree_checkout_helper.rb b/app/helpers/solidus_paypal_braintree/braintree_checkout_helper.rb index 52dd21ab..12535d9b 100644 --- a/app/helpers/solidus_paypal_braintree/braintree_checkout_helper.rb +++ b/app/helpers/solidus_paypal_braintree/braintree_checkout_helper.rb @@ -40,5 +40,8 @@ def braintree_3ds_options_for(order) } end + def paypal_button_preference(key, store:) + store.braintree_configuration.preferences[key] + end end end diff --git a/config/initializers/braintree.rb b/config/initializers/braintree.rb index 1f370736..3cd773ae 100644 --- a/config/initializers/braintree.rb +++ b/config/initializers/braintree.rb @@ -1,8 +1,3 @@ if SolidusSupport.backend_available? Spree::Admin::PaymentsController.helper :braintree_admin end - -if SolidusSupport.frontend_available? - Spree::CheckoutController.helper :braintree_checkout - Spree::OrdersController.helper :braintree_checkout -end