From 6c631d323594cb653bef8ba2aee3cd555a0ce97e Mon Sep 17 00:00:00 2001 From: Connor Ferguson <68167430+cpfergus1@users.noreply.github.com> Date: Tue, 22 Jun 2021 14:43:36 -0600 Subject: [PATCH] Hooks has been deprecated in favor of subscribing to order_recalculate Please see PR #[3553](https://github.com/solidusio/solidus/pull/3553) for more information concerning this change. --- .../spree/order_decorator.rb | 7 ------- .../klarna_subscriber.rb | 20 +++++++++++++++++++ 2 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 app/subscribers/solidus_klarna_payments/klarna_subscriber.rb diff --git a/app/decorators/models/solidus_klarna_payments/spree/order_decorator.rb b/app/decorators/models/solidus_klarna_payments/spree/order_decorator.rb index b640d11c..919cfdf5 100644 --- a/app/decorators/models/solidus_klarna_payments/spree/order_decorator.rb +++ b/app/decorators/models/solidus_klarna_payments/spree/order_decorator.rb @@ -5,13 +5,6 @@ module Spree module OrderDecorator KLARNA_SESSION_LIFETIME = 48.hours - def self.prepended(base) - base.class_eval do - register_update_hook(:update_klarna_shipments) - register_update_hook(:update_klarna_customer) - end - end - def update_klarna_session(session_id: nil, client_token: nil) update!( klarna_session_id: session_id, diff --git a/app/subscribers/solidus_klarna_payments/klarna_subscriber.rb b/app/subscribers/solidus_klarna_payments/klarna_subscriber.rb new file mode 100644 index 00000000..c37520cf --- /dev/null +++ b/app/subscribers/solidus_klarna_payments/klarna_subscriber.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module SolidusKlarnaPayments + module KlarnaSubscriber + include ::Spree::Event::Subscriber + + event_action :update_klarna_shipments, event_name: :order_recalulated + event_action :update_klarna_customer, event_name: :order_recalulated + + def update_klarna_shipments + order = event.payload[:order] + order.update_klarna_shipments + end + + def update_klarna_customer + order = event.payload[:order] + order.update_klarna_customer + end + end +end