Class: Spree::Api::V2::Tenant::LineItemsController
- Inherits:
-
BaseController
- Object
- ResourceController
- BaseController
- Spree::Api::V2::Tenant::LineItemsController
- Defined in:
- app/controllers/spree/api/v2/tenant/line_items_controller.rb
Instance Method Summary collapse
- #collection ⇒ Object
-
#mark_as_completed ⇒ Object
rubocop:disable Metrics/PerceivedComplexity.
- #show ⇒ Object
Methods inherited from BaseController
#render_serialized_payload, #require_tenant, #scope
Instance Method Details
#collection ⇒ Object
8 9 10 11 12 13 14 |
# File 'app/controllers/spree/api/v2/tenant/line_items_controller.rb', line 8 def collection if spree_current_user.nil? line_items_by_order_tokens else spree_current_user.line_items.filter_by_event(params[:event]) end end |
#mark_as_completed ⇒ Object
rubocop:disable Metrics/PerceivedComplexity
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/controllers/spree/api/v2/tenant/line_items_controller.rb', line 21 def mark_as_completed # rubocop:disable Metrics/PerceivedComplexity line_item = Spree::LineItem.find(params[:id]) = (line_item. || {}).deep_transform_keys(&:to_s) steps = ['completion_steps'] if steps.present? && steps.is_a?(Array) step = steps.find { |s| s['position'] == 1 } || steps[0] if step if step['action_url'].present? step['completed'] = true ['completion_steps'] = steps line_item. = line_item.save! render_serialized_payload { serialize_resource(line_item) } else render_error_payload('Action url is nil, cannot update to completed') end else render_error_payload('Step with position 1 not found') end else render_error_payload('completion_steps does not exist for this line_item') end end |
#show ⇒ Object
16 17 18 19 |
# File 'app/controllers/spree/api/v2/tenant/line_items_controller.rb', line 16 def show line_item = Spree::LineItem.find(params[:id]) render_serialized_payload { serialize_resource(line_item) } end |