Skip to content

Commit 59a68df

Browse files
Merge pull request spree#9223 from spark-solutions/3-7-stable
3.7.0 final release
2 parents 5cc2a99 + bcfb63e commit 59a68df

File tree

27 files changed

+166
-74
lines changed

27 files changed

+166
-74
lines changed

api/app/controllers/spree/api/v2/base_controller.rb

+7-3
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,27 @@ class BaseController < ActionController::API
77
rescue_from ActiveRecord::RecordNotFound, with: :record_not_found
88
rescue_from CanCan::AccessDenied, with: :access_denied
99

10+
def content_type
11+
Spree::Api::Config[:api_v2_content_type]
12+
end
13+
1014
private
1115

1216
def collection_paginator
1317
Spree::Api::Dependencies.storefront_collection_paginator.constantize
1418
end
1519

1620
def render_serialized_payload(status = 200)
17-
render json: yield, status: status
21+
render json: yield, status: status, content_type: content_type
1822
rescue ArgumentError => exception
1923
render_error_payload(exception.message, 400)
2024
end
2125

2226
def render_error_payload(error, status = 422)
2327
if error.is_a?(Struct)
24-
render json: { error: error.to_s, errors: error.to_h }, status: status
28+
render json: { error: error.to_s, errors: error.to_h }, status: status, content_type: content_type
2529
elsif error.is_a?(String)
26-
render json: { error: error }, status: status
30+
render json: { error: error }, status: status, content_type: content_type
2731
end
2832
end
2933

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
module Spree
2+
module Api
3+
module V2
4+
module Storefront
5+
class OrderStatusController < ::Spree::Api::V2::BaseController
6+
include Spree::Api::V2::Storefront::OrderConcern
7+
8+
def show
9+
render_serialized_payload { serialize_resource(resource) }
10+
end
11+
12+
private
13+
14+
def resource
15+
resource = resource_finder.new(number: params[:number], token: order_token).execute.take
16+
raise ActiveRecord::RecordNotFound if resource.nil?
17+
18+
resource
19+
end
20+
21+
def serialize_resource(resource)
22+
resource_serializer.new(
23+
resource,
24+
include: resource_includes,
25+
sparse_fields: sparse_fields
26+
).serializable_hash
27+
end
28+
29+
def resource_finder
30+
Spree::Api::Dependencies.storefront_completed_order_finder.constantize
31+
end
32+
33+
def resource_serializer
34+
Spree::Api::Dependencies.storefront_cart_serializer.constantize
35+
end
36+
end
37+
end
38+
end
39+
end
40+
end
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module Spree
22
class ApiConfiguration < Preferences::Configuration
33
preference :requires_authentication, :boolean, default: true
4+
preference :api_v2_content_type, :string, default: 'application/vnd.api+json'
45
end
56
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
api_mime_types = %w(
2+
application/vnd.api+json
3+
text/x-json
4+
application/json
5+
)
6+
7+
Mime::Type.unregister :json
8+
Mime::Type.register 'application/json', :json, api_mime_types

api/config/routes.rb

+1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@
158158

159159
resources :countries, only: %i[index]
160160
get '/countries/:iso', to: 'countries#show', as: :country
161+
get '/order_status/:number', to: 'order_status#show', as: :order_status
161162
resources :products, only: %i[index show]
162163
resources :taxons, only: %i[index show]
163164
end

0 commit comments

Comments
 (0)