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_internal_note ⇒ Object
- #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 21 |
# 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 update_internal_note ] base.before_action :initialize_notification_methods, only: %i[ notifications fire_notification queue_webhooks_requests ] end |
Instance Method Details
#accept_all ⇒ Object
23 24 25 26 27 |
# File 'app/controllers/spree_cm_commissioner/admin/orders_controller_decorator.rb', line 23 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
35 36 37 38 39 40 |
# File 'app/controllers/spree_cm_commissioner/admin/orders_controller_decorator.rb', line 35 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
43 44 45 46 47 48 49 50 51 52 |
# File 'app/controllers/spree_cm_commissioner/admin/orders_controller_decorator.rb', line 43 def cancel if @order.guests_in_transfer? flash[:error] = Spree.t('admin.orders.cannot_cancel_guest_transfer') else internal_note = params.dig(:order, :internal_note) @order.canceled_by(try_spree_current_user, cancellation_reason: internal_note) flash[:success] = Spree.t(:order_canceled) end redirect_back fallback_location: spree.edit_admin_order_url(@order) end |
#fire_notification ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/controllers/spree_cm_commissioner/admin/orders_controller_decorator.rb', line 54 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
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'app/controllers/spree_cm_commissioner/admin/orders_controller_decorator.rb', line 119 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
115 116 117 |
# File 'app/controllers/spree_cm_commissioner/admin/orders_controller_decorator.rb', line 115 def initialize_order_events @order_events = %w[alert_request_to_vendor resume approve] end |
#notifications ⇒ Object
83 |
# File 'app/controllers/spree_cm_commissioner/admin/orders_controller_decorator.rb', line 83 def notifications; end |
#queue_webhooks_requests ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/controllers/spree_cm_commissioner/admin/orders_controller_decorator.rb', line 66 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
29 30 31 32 33 |
# File 'app/controllers/spree_cm_commissioner/admin/orders_controller_decorator.rb', line 29 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
104 105 106 107 108 109 110 111 112 |
# File 'app/controllers/spree_cm_commissioner/admin/orders_controller_decorator.rb', line 104 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_internal_note ⇒ Object
85 86 87 88 89 90 91 |
# File 'app/controllers/spree_cm_commissioner/admin/orders_controller_decorator.rb', line 85 def update_internal_note internal_note = params.dig(:order, :internal_note).to_s.strip.presence @order.update_columns(internal_note: internal_note, updated_at: Time.current) # rubocop:disable Rails/SkipsModelValidations flash[:success] = Spree.t(:internal_note_updated, default: 'Internal note updated') redirect_back fallback_location: spree.edit_admin_order_url(@order) end |
#update_order_status ⇒ Object
93 94 95 96 97 98 99 100 101 |
# File 'app/controllers/spree_cm_commissioner/admin/orders_controller_decorator.rb', line 93 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 |