spree_api 4.2.0.rc1 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/concerns/spree/api/v2/storefront/order_concern.rb +7 -7
- data/app/controllers/spree/api/base_controller.rb +10 -2
- data/app/controllers/spree/api/v1/shipments_controller.rb +16 -6
- data/app/controllers/spree/api/v1/taxons_controller.rb +1 -1
- data/app/controllers/spree/api/v2/base_controller.rb +21 -4
- data/app/controllers/spree/api/v2/resource_controller.rb +59 -0
- data/app/controllers/spree/api/v2/storefront/account/addresses_controller.rb +3 -11
- data/app/controllers/spree/api/v2/storefront/account/credit_cards_controller.rb +7 -15
- data/app/controllers/spree/api/v2/storefront/account/orders_controller.rb +7 -26
- data/app/controllers/spree/api/v2/storefront/account_controller.rb +1 -5
- data/app/controllers/spree/api/v2/storefront/cart_controller.rb +1 -1
- data/app/controllers/spree/api/v2/storefront/countries_controller.rb +9 -16
- data/app/controllers/spree/api/v2/storefront/order_status_controller.rb +2 -6
- data/app/controllers/spree/api/v2/storefront/products_controller.rb +4 -14
- data/app/controllers/spree/api/v2/storefront/stores_controller.rb +2 -6
- data/app/controllers/spree/api/v2/storefront/taxons_controller.rb +3 -13
- data/app/helpers/spree/api/api_helpers.rb +1 -1
- data/app/helpers/spree/api/v2/display_money_helper.rb +43 -0
- data/app/models/spree/api_configuration.rb +1 -0
- data/app/models/spree/api_dependencies.rb +8 -3
- data/app/serializers/spree/v2/storefront/address_serializer.rb +7 -2
- data/app/serializers/spree/v2/storefront/base_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/cart_serializer.rb +2 -1
- data/app/serializers/spree/v2/storefront/country_serializer.rb +6 -0
- data/app/serializers/spree/v2/storefront/estimated_shipping_rate_serializer.rb +3 -1
- data/app/serializers/spree/v2/storefront/payment_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/product_property_serializer.rb +7 -2
- data/app/serializers/spree/v2/storefront/product_serializer.rb +38 -7
- data/app/serializers/spree/v2/storefront/shipment_serializer.rb +3 -1
- data/app/serializers/spree/v2/storefront/shipping_rate_serializer.rb +3 -1
- data/app/serializers/spree/v2/storefront/store_credit_category_serializer.rb +11 -0
- data/app/serializers/spree/v2/storefront/store_credit_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/store_serializer.rb +3 -1
- data/app/serializers/spree/v2/storefront/taxon_serializer.rb +11 -3
- data/app/serializers/spree/v2/storefront/user_serializer.rb +3 -1
- data/app/serializers/spree/v2/storefront/variant_serializer.rb +34 -5
- data/app/services/spree/api/error_handler.rb +40 -0
- data/config/initializers/doorkeeper.rb +10 -1
- data/config/locales/en.yml +1 -1
- data/docs/oauth/index.yml +78 -15
- data/docs/v2/storefront/index.yaml +3232 -663
- data/lib/spree/api/testing_support/v2/current_order.rb +2 -0
- data/lib/spree_api.rb +1 -1
- data/spree_api.gemspec +1 -1
- metadata +15 -11
@@ -2,15 +2,11 @@ module Spree
|
|
2
2
|
module Api
|
3
3
|
module V2
|
4
4
|
module Storefront
|
5
|
-
class OrderStatusController < ::Spree::Api::V2::
|
5
|
+
class OrderStatusController < ::Spree::Api::V2::ResourceController
|
6
6
|
include Spree::Api::V2::Storefront::OrderConcern
|
7
7
|
|
8
8
|
before_action :ensure_order_token
|
9
9
|
|
10
|
-
def show
|
11
|
-
render_serialized_payload { serialize_resource(resource) }
|
12
|
-
end
|
13
|
-
|
14
10
|
private
|
15
11
|
|
16
12
|
def resource
|
@@ -29,7 +25,7 @@ module Spree
|
|
29
25
|
end
|
30
26
|
|
31
27
|
def ensure_order_token
|
32
|
-
raise ActiveRecord::RecordNotFound unless order_token
|
28
|
+
raise ActiveRecord::RecordNotFound unless order_token.present?
|
33
29
|
end
|
34
30
|
end
|
35
31
|
end
|
@@ -2,21 +2,11 @@ module Spree
|
|
2
2
|
module Api
|
3
3
|
module V2
|
4
4
|
module Storefront
|
5
|
-
class ProductsController < ::Spree::Api::V2::
|
6
|
-
include Spree::Api::V2::CollectionOptionsHelpers
|
7
|
-
|
8
|
-
def index
|
9
|
-
render_serialized_payload { serialize_collection(paginated_collection) }
|
10
|
-
end
|
11
|
-
|
12
|
-
def show
|
13
|
-
render_serialized_payload { serialize_resource(resource) }
|
14
|
-
end
|
15
|
-
|
5
|
+
class ProductsController < ::Spree::Api::V2::ResourceController
|
16
6
|
private
|
17
7
|
|
18
8
|
def sorted_collection
|
19
|
-
collection_sorter.new(collection, params,
|
9
|
+
collection_sorter.new(collection, current_currency, params, allowed_sort_attributes).call
|
20
10
|
end
|
21
11
|
|
22
12
|
def collection
|
@@ -43,8 +33,8 @@ module Spree
|
|
43
33
|
Spree::Api::Dependencies.storefront_product_serializer.constantize
|
44
34
|
end
|
45
35
|
|
46
|
-
def
|
47
|
-
Spree::Product
|
36
|
+
def model_class
|
37
|
+
Spree::Product
|
48
38
|
end
|
49
39
|
|
50
40
|
def scope_includes
|
@@ -2,14 +2,10 @@ module Spree
|
|
2
2
|
module Api
|
3
3
|
module V2
|
4
4
|
module Storefront
|
5
|
-
class StoresController < ::Spree::Api::V2::
|
6
|
-
def show
|
7
|
-
render_serialized_payload { serialize_resource(resource) }
|
8
|
-
end
|
9
|
-
|
5
|
+
class StoresController < ::Spree::Api::V2::ResourceController
|
10
6
|
private
|
11
7
|
|
12
|
-
def
|
8
|
+
def model_class
|
13
9
|
Spree::Store
|
14
10
|
end
|
15
11
|
|
@@ -2,17 +2,7 @@ module Spree
|
|
2
2
|
module Api
|
3
3
|
module V2
|
4
4
|
module Storefront
|
5
|
-
class TaxonsController < ::Spree::Api::V2::
|
6
|
-
include Spree::Api::V2::CollectionOptionsHelpers
|
7
|
-
|
8
|
-
def index
|
9
|
-
render_serialized_payload { serialize_collection(paginated_collection) }
|
10
|
-
end
|
11
|
-
|
12
|
-
def show
|
13
|
-
render_serialized_payload { serialize_resource(resource) }
|
14
|
-
end
|
15
|
-
|
5
|
+
class TaxonsController < ::Spree::Api::V2::ResourceController
|
16
6
|
private
|
17
7
|
|
18
8
|
def collection_serializer
|
@@ -39,8 +29,8 @@ module Spree
|
|
39
29
|
scope.find_by(permalink: params[:id]) || scope.find(params[:id])
|
40
30
|
end
|
41
31
|
|
42
|
-
def
|
43
|
-
Spree::Taxon
|
32
|
+
def model_class
|
33
|
+
Spree::Taxon
|
44
34
|
end
|
45
35
|
|
46
36
|
def scope_includes
|
@@ -163,7 +163,7 @@ module Spree
|
|
163
163
|
:id, :name, :url, :meta_description, :meta_keywords, :seo_title,
|
164
164
|
:mail_from_address, :customer_support_email, :default_currency,
|
165
165
|
:code, :default, :facebook, :twitter, :instagram,
|
166
|
-
:supported_currencies
|
166
|
+
:supported_currencies, :default_locale, :supported_locales
|
167
167
|
]
|
168
168
|
|
169
169
|
@@tag_attributes = [:id, :name]
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
module DisplayMoneyHelper
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
class_methods do
|
8
|
+
def find_price(product_or_variant, currency)
|
9
|
+
product_or_variant.price_in(currency)
|
10
|
+
end
|
11
|
+
|
12
|
+
def price(product_or_variant, currency)
|
13
|
+
price = find_price(product_or_variant, currency)
|
14
|
+
return nil if price.new_record?
|
15
|
+
|
16
|
+
format('%.2f', price.amount)
|
17
|
+
end
|
18
|
+
|
19
|
+
def display_price(product_or_variant, currency)
|
20
|
+
price = find_price(product_or_variant, currency)
|
21
|
+
return nil if price.new_record?
|
22
|
+
|
23
|
+
Spree::Money.new(price.amount, currency: currency).to_s
|
24
|
+
end
|
25
|
+
|
26
|
+
def compare_at_price(product_or_variant, currency)
|
27
|
+
price = find_price(product_or_variant, currency)
|
28
|
+
return nil if price.new_record? || price.compare_at_amount.blank?
|
29
|
+
|
30
|
+
format('%.2f', price.compare_at_amount)
|
31
|
+
end
|
32
|
+
|
33
|
+
def display_compare_at_price(product_or_variant, currency)
|
34
|
+
price = find_price(product_or_variant, currency)
|
35
|
+
return nil if price.new_record? || price.compare_at_amount.blank?
|
36
|
+
|
37
|
+
Spree::Money.new(price.compare_at_amount, currency: currency).to_s
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -2,5 +2,6 @@ module Spree
|
|
2
2
|
class ApiConfiguration < Preferences::Configuration
|
3
3
|
preference :requires_authentication, :boolean, default: true
|
4
4
|
preference :api_v2_content_type, :string, default: 'application/vnd.api+json'
|
5
|
+
preference :api_v2_per_page_limit, :integer, default: 100
|
5
6
|
end
|
6
7
|
end
|
@@ -14,8 +14,9 @@ module Spree
|
|
14
14
|
:storefront_collection_paginator, :storefront_user_serializer, :storefront_products_sorter, :storefront_products_finder,
|
15
15
|
:storefront_product_serializer, :storefront_taxon_serializer, :storefront_taxon_finder, :storefront_find_by_variant_finder,
|
16
16
|
:storefront_cart_update_service, :storefront_cart_estimate_shipping_rates_service, :storefront_estimated_shipment_serializer,
|
17
|
-
:storefront_store_serializer, :storefront_address_serializer,
|
18
|
-
:storefront_account_create_address_service, :storefront_account_update_address_service, :storefront_address_finder
|
17
|
+
:storefront_store_serializer, :storefront_address_serializer, :storefront_order_serializer,
|
18
|
+
:storefront_account_create_address_service, :storefront_account_update_address_service, :storefront_address_finder,
|
19
|
+
:storefront_collection_sorter, :error_handler
|
19
20
|
].freeze
|
20
21
|
|
21
22
|
attr_accessor *INJECTION_POINTS
|
@@ -66,9 +67,11 @@ module Spree
|
|
66
67
|
@storefront_product_serializer = 'Spree::V2::Storefront::ProductSerializer'
|
67
68
|
@storefront_estimated_shipment_serializer = 'Spree::V2::Storefront::EstimatedShippingRateSerializer'
|
68
69
|
@storefront_store_serializer = 'Spree::V2::Storefront::StoreSerializer'
|
70
|
+
@storefront_order_serializer = 'Spree::V2::Storefront::CartSerializer'
|
69
71
|
|
70
72
|
# sorters
|
71
|
-
@
|
73
|
+
@storefront_collection_sorter = Spree::Dependencies.collection_sorter
|
74
|
+
@storefront_order_sorter = Spree::Dependencies.collection_sorter
|
72
75
|
@storefront_products_sorter = Spree::Dependencies.products_sorter
|
73
76
|
|
74
77
|
# paginators
|
@@ -83,6 +86,8 @@ module Spree
|
|
83
86
|
@storefront_find_by_variant_finder = Spree::Dependencies.line_item_by_variant_finder
|
84
87
|
@storefront_products_finder = Spree::Dependencies.products_finder
|
85
88
|
@storefront_taxon_finder = Spree::Dependencies.taxon_finder
|
89
|
+
|
90
|
+
@error_handler = 'Spree::Api::ErrorHandler'
|
86
91
|
end
|
87
92
|
end
|
88
93
|
end
|
@@ -7,8 +7,13 @@ module Spree
|
|
7
7
|
attributes :firstname, :lastname, :address1, :address2, :city, :zipcode, :phone, :state_name,
|
8
8
|
:company, :country_name, :country_iso3, :country_iso, :label
|
9
9
|
|
10
|
-
attribute :state_code
|
11
|
-
|
10
|
+
attribute :state_code do |address|
|
11
|
+
address.state_abbr
|
12
|
+
end
|
13
|
+
|
14
|
+
attribute :state_name do |address|
|
15
|
+
address.state_name_text
|
16
|
+
end
|
12
17
|
end
|
13
18
|
end
|
14
19
|
end
|
@@ -9,7 +9,8 @@ module Spree
|
|
9
9
|
:display_included_tax_total, :tax_total, :currency, :state, :token, :email,
|
10
10
|
:display_item_total, :display_ship_total, :display_adjustment_total, :display_tax_total,
|
11
11
|
:promo_total, :display_promo_total, :item_count, :special_instructions, :display_total,
|
12
|
-
:pre_tax_item_amount, :display_pre_tax_item_amount, :pre_tax_total, :display_pre_tax_total
|
12
|
+
:pre_tax_item_amount, :display_pre_tax_item_amount, :pre_tax_total, :display_pre_tax_total,
|
13
|
+
:shipment_state, :payment_state
|
13
14
|
|
14
15
|
has_many :line_items
|
15
16
|
has_many :variants
|
@@ -12,6 +12,12 @@ module Spree
|
|
12
12
|
end
|
13
13
|
|
14
14
|
has_many :states, if: proc { |_record, params| params && params[:include_states] }
|
15
|
+
|
16
|
+
has_many :checkout_zone_applicable_states,
|
17
|
+
serializer: ::Spree::V2::Storefront::StateSerializer,
|
18
|
+
if: proc { |_record, params| params && params[:current_store].present? } do |object, params|
|
19
|
+
params[:current_store].states_available_for_checkout(object)
|
20
|
+
end
|
15
21
|
end
|
16
22
|
end
|
17
23
|
end
|
@@ -6,7 +6,9 @@ module Spree
|
|
6
6
|
|
7
7
|
attributes :name, :selected, :cost, :tax_amount, :shipping_method_id
|
8
8
|
|
9
|
-
attribute :final_price
|
9
|
+
attribute :final_price do |shipping_rate|
|
10
|
+
shipping_rate.cost
|
11
|
+
end
|
10
12
|
|
11
13
|
attributes :display_cost, :display_final_price do |object, params|
|
12
14
|
Spree::Money.new(object.cost, currency: params[:currency])
|
@@ -6,8 +6,13 @@ module Spree
|
|
6
6
|
|
7
7
|
attribute :value
|
8
8
|
|
9
|
-
attribute :name
|
10
|
-
|
9
|
+
attribute :name do |product_property|
|
10
|
+
product_property.property_name
|
11
|
+
end
|
12
|
+
|
13
|
+
attribute :description do |product_property|
|
14
|
+
product_property.property_presentation
|
15
|
+
end
|
11
16
|
end
|
12
17
|
end
|
13
18
|
end
|
@@ -2,16 +2,47 @@ module Spree
|
|
2
2
|
module V2
|
3
3
|
module Storefront
|
4
4
|
class ProductSerializer < BaseSerializer
|
5
|
+
include ::Spree::Api::V2::DisplayMoneyHelper
|
6
|
+
|
5
7
|
set_type :product
|
6
8
|
|
7
|
-
attributes :name, :description, :
|
8
|
-
|
9
|
-
|
9
|
+
attributes :name, :description, :available_on, :slug, :meta_description, :meta_keywords, :updated_at
|
10
|
+
|
11
|
+
attribute :purchasable do |product|
|
12
|
+
product.purchasable?
|
13
|
+
end
|
14
|
+
|
15
|
+
attribute :in_stock do |product|
|
16
|
+
product.in_stock?
|
17
|
+
end
|
18
|
+
|
19
|
+
attribute :backorderable do |product|
|
20
|
+
product.backorderable?
|
21
|
+
end
|
22
|
+
|
23
|
+
attribute :available do |product|
|
24
|
+
product.available?
|
25
|
+
end
|
26
|
+
|
27
|
+
attribute :currency do |_product, params|
|
28
|
+
params[:currency]
|
29
|
+
end
|
30
|
+
|
31
|
+
attribute :price do |product, params|
|
32
|
+
price(product, params[:currency])
|
33
|
+
end
|
34
|
+
|
35
|
+
attribute :display_price do |product, params|
|
36
|
+
display_price(product, params[:currency])
|
37
|
+
end
|
38
|
+
|
39
|
+
attribute :compare_at_price do |product, params|
|
40
|
+
compare_at_price(product, params[:currency])
|
41
|
+
end
|
10
42
|
|
11
|
-
attribute :
|
12
|
-
|
13
|
-
|
14
|
-
attribute :available, &:available?
|
43
|
+
attribute :display_compare_at_price do |product, params|
|
44
|
+
display_compare_at_price(product, params[:currency])
|
45
|
+
end
|
15
46
|
|
16
47
|
has_many :variants
|
17
48
|
has_many :option_types
|
@@ -7,7 +7,9 @@ module Spree
|
|
7
7
|
attributes :name, :selected, :final_price, :display_final_price, :cost,
|
8
8
|
:display_cost, :tax_amount, :display_tax_amount, :shipping_method_id
|
9
9
|
|
10
|
-
attribute :free
|
10
|
+
attribute :free do |shipping_rate|
|
11
|
+
shipping_rate.free?
|
12
|
+
end
|
11
13
|
end
|
12
14
|
end
|
13
15
|
end
|
@@ -6,7 +6,9 @@ module Spree
|
|
6
6
|
|
7
7
|
attributes :name, :url, :meta_description, :meta_keywords, :seo_title, :default_currency, :default, :supported_currencies, :facebook,
|
8
8
|
:twitter, :instagram, :default_locale, :customer_support_email, :default_country_id, :description,
|
9
|
-
:address, :contact_phone, :
|
9
|
+
:address, :contact_phone, :supported_locales
|
10
|
+
|
11
|
+
has_one :default_country, serializer: :country, record_type: :country, id_method_name: :default_country_id
|
10
12
|
end
|
11
13
|
end
|
12
14
|
end
|
@@ -7,9 +7,17 @@ module Spree
|
|
7
7
|
attributes :name, :pretty_name, :permalink, :seo_title, :description, :meta_title, :meta_description,
|
8
8
|
:meta_keywords, :left, :right, :position, :depth, :updated_at
|
9
9
|
|
10
|
-
attribute :is_root
|
11
|
-
|
12
|
-
|
10
|
+
attribute :is_root do |taxon|
|
11
|
+
taxon.root?
|
12
|
+
end
|
13
|
+
|
14
|
+
attribute :is_child do |taxon|
|
15
|
+
taxon.child?
|
16
|
+
end
|
17
|
+
|
18
|
+
attribute :is_leaf do |taxon|
|
19
|
+
taxon.leaf?
|
20
|
+
end
|
13
21
|
|
14
22
|
belongs_to :parent, record_type: :taxon, serializer: :taxon
|
15
23
|
belongs_to :taxonomy, record_type: :taxonomy
|