2022-08-21 19:08:10 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Concern for CartController and CheckoutController
|
|
|
|
module API::OrderConcern
|
|
|
|
private
|
|
|
|
|
|
|
|
def order_token
|
|
|
|
request.headers['X-Fablab-Order-Token'] || cart_params[:order_token]
|
|
|
|
end
|
|
|
|
|
|
|
|
def current_order
|
2022-08-26 10:46:30 +02:00
|
|
|
@current_order = Order.find_by(token: order_token, state: 'cart')
|
2022-08-21 19:08:10 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def ensure_order
|
|
|
|
raise ActiveRecord::RecordNotFound if @current_order.nil?
|
|
|
|
end
|
2022-08-25 08:52:17 +02:00
|
|
|
|
|
|
|
def cart_params
|
2022-09-08 15:10:56 +02:00
|
|
|
params.permit(:order_token, :orderable_id, :quantity, :user_id, :is_offered)
|
2022-08-25 08:52:17 +02:00
|
|
|
end
|
2022-08-21 19:08:10 +02:00
|
|
|
end
|