Module: SpreeCmCommissioner::Admin::OrdersControllerDecorator
- Defined in:
- app/controllers/spree_cm_commissioner/admin/orders_controller_decorator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #accept_all ⇒ Object
- #alert_request_to_vendor ⇒ Object
-
#cancel ⇒ Object
override.
- #fire_notification ⇒ Object
- #initialize_notification_methods ⇒ Object
-
#initialize_order_events ⇒ Object
override.
- #notifications ⇒ Object
- #queue_webhooks_requests ⇒ Object
- #reject_all ⇒ Object
-
#resume ⇒ Object
override.
- #update_order_status ⇒ Object
Class Method Details
.prepended(base) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/controllers/spree_cm_commissioner/admin/orders_controller_decorator.rb', line 4 def self.prepended(base) # spree try to create an empty order in the #new action base.around_action :set_writing_role, only: %i[new edit] base.before_action :load_order, only: %i[ edit update cancel resume approve resend open_adjustments close_adjustments cart channel set_channel accept_all reject_all alert_request_to_vendor notifications fire_notification queue_webhooks_requests update_order_status ] base.before_action :initialize_notification_methods, only: %i[ notifications fire_notification queue_webhooks_requests ] end |
Instance Method Details
#accept_all ⇒ Object
22 23 24 25 26 |
# File 'app/controllers/spree_cm_commissioner/admin/orders_controller_decorator.rb', line 22 def accept_all @order.accepted_by(try_spree_current_user) flash[:success] = Spree.t(:accepted) redirect_back fallback_location: spree.edit_admin_order_url(@order) end |
#alert_request_to_vendor ⇒ Object
34 35 36 37 38 39 |
# File 'app/controllers/spree_cm_commissioner/admin/orders_controller_decorator.rb', line 34 def alert_request_to_vendor @order.send_order_request_telegram_confirmation_alert_to_vendor flash[:success] = Spree.t(:alerted_to_vendor) redirect_back fallback_location: spree.edit_admin_order_url(@order) end |
#cancel ⇒ Object
override
42 43 44 45 46 47 |
# File 'app/controllers/spree_cm_commissioner/admin/orders_controller_decorator.rb', line 42 def cancel internal_note = params.dig(:order, :internal_note) @order.canceled_by(try_spree_current_user, cancellation_reason: internal_note) flash[:success] = Spree.t(:order_canceled) redirect_back fallback_location: spree.edit_admin_order_url(@order) end |
#fire_notification ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/controllers/spree_cm_commissioner/admin/orders_controller_decorator.rb', line 49 def fire_notification method = @notification_methods.find { |e| e == params['notification_method'] } if method.present? && @order.send(method) flash[:success] = Spree.t(:sent) else flash[:error] = Spree.t(:send_failed_or_method_not_support) end redirect_back fallback_location: notifications_admin_order_url(@order) end |
#initialize_notification_methods ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'app/controllers/spree_cm_commissioner/admin/orders_controller_decorator.rb', line 106 def initialize_notification_methods @notification_methods = %w[ send_order_complete_telegram_alert_to_vendors send_order_complete_telegram_alert_to_store send_order_requested_telegram_alert_to_store send_order_accepted_telegram_alert_to_store send_order_rejected_telegram_alert_to_store notify_order_complete_app_notification_to_user notify_order_complete_telegram_notification_to_user ] @webhook_events = [ 'order.create', 'order.delete', 'order.update', 'order.canceled', 'order.placed', 'order.resumed', 'order.shipped' ] end |
#initialize_order_events ⇒ Object
override
102 103 104 |
# File 'app/controllers/spree_cm_commissioner/admin/orders_controller_decorator.rb', line 102 def initialize_order_events @order_events = %w[alert_request_to_vendor resume approve] end |
#notifications ⇒ Object
78 |
# File 'app/controllers/spree_cm_commissioner/admin/orders_controller_decorator.rb', line 78 def notifications; end |
#queue_webhooks_requests ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/controllers/spree_cm_commissioner/admin/orders_controller_decorator.rb', line 61 def queue_webhooks_requests event = @webhook_events.find { |e| e == params['event'] } if event.present? Spree::Webhooks::Subscribers::QueueRequests.call( event_name: event, webhook_payload_body: @order.send(:webhook_payload_body), **@order.send(:webhooks_request_options) ) flash[:success] = Spree.t(:sent) else flash[:error] = Spree.t(:send_failed_or_method_not_support) end redirect_back fallback_location: notifications_admin_order_url(@order) end |
#reject_all ⇒ Object
28 29 30 31 32 |
# File 'app/controllers/spree_cm_commissioner/admin/orders_controller_decorator.rb', line 28 def reject_all @order.rejected_by(try_spree_current_user) flash[:success] = Spree.t(:rejected) redirect_back fallback_location: spree.edit_admin_order_url(@order) end |
#resume ⇒ Object
override
91 92 93 94 95 96 97 98 99 |
# File 'app/controllers/spree_cm_commissioner/admin/orders_controller_decorator.rb', line 91 def resume resumed = @order.resume if resumed flash[:success] = 'Order resumed' # rubocop:disable Rails/I18nLocaleTexts else flash[:error] = @order.errors..to_sentence end redirect_back fallback_location: spree.edit_admin_order_url(@order) end |
#update_order_status ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'app/controllers/spree_cm_commissioner/admin/orders_controller_decorator.rb', line 80 def update_order_status if @order.next flash[:success] = I18n.t('orders.update_order_status.success') else = @order.errors..to_sentence flash[:error] = (.presence || I18n.t('orders.update_order_status.fail')) end redirect_back fallback_location: spree.edit_admin_order_url(@order) end |