spree_api 3.6.6 → 3.7.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/spree/api/main.js +36 -0
- data/app/assets/javascripts/spree/api/storefront/cart.js +49 -0
- data/app/controllers/concerns/spree/api/v2/storefront/order_concern.rb +48 -0
- data/app/controllers/spree/api/errors_controller.rb +9 -0
- data/app/controllers/spree/api/v1/checkouts_controller.rb +12 -0
- data/app/controllers/spree/api/v1/customer_returns_controller.rb +1 -0
- data/app/controllers/spree/api/v1/line_items_controller.rb +11 -10
- data/app/controllers/spree/api/v1/orders_controller.rb +6 -6
- data/app/controllers/spree/api/v1/product_properties_controller.rb +1 -0
- data/app/controllers/spree/api/v1/products_controller.rb +6 -6
- data/app/controllers/spree/api/v1/promotions_controller.rb +1 -0
- data/app/controllers/spree/api/v1/reimbursements_controller.rb +1 -0
- data/app/controllers/spree/api/v1/shipments_controller.rb +12 -3
- data/app/controllers/spree/api/v1/variants_controller.rb +5 -3
- data/app/controllers/spree/api/v2/base_controller.rb +94 -0
- data/app/controllers/spree/api/v2/storefront/account/credit_cards_controller.rb +55 -0
- data/app/controllers/spree/api/v2/storefront/account_controller.rb +33 -0
- data/app/controllers/spree/api/v2/storefront/cart_controller.rb +124 -0
- data/app/controllers/spree/api/v2/storefront/checkout_controller.rb +108 -0
- data/app/controllers/spree/api/v2/storefront/countries_controller.rb +57 -0
- data/app/controllers/spree/api/v2/storefront/products_controller.rb +87 -0
- data/app/controllers/spree/api/v2/storefront/taxons_controller.rb +82 -0
- data/app/helpers/spree/api/api_helpers.rb +1 -1
- data/app/helpers/spree/api/v2/collection_options_helpers.rb +37 -0
- data/app/models/doorkeeper/access_grant_decorator.rb +3 -0
- data/app/models/doorkeeper/access_token_decorator.rb +3 -0
- data/app/models/doorkeeper/application_decorator.rb +3 -0
- data/app/serializers/spree/v2/storefront/account/credit_card_serializer.rb +16 -0
- data/app/serializers/spree/v2/storefront/account_serializer.rb +29 -0
- data/app/serializers/spree/v2/storefront/address_serializer.rb +14 -0
- data/app/serializers/spree/v2/storefront/base_serializer.rb +9 -0
- data/app/serializers/spree/v2/storefront/cart_serializer.rb +40 -0
- data/app/serializers/spree/v2/storefront/country_serializer.rb +18 -0
- data/app/serializers/spree/v2/storefront/image_serializer.rb +11 -0
- data/app/serializers/spree/v2/storefront/line_item_serializer.rb +17 -0
- data/app/serializers/spree/v2/storefront/option_type_serializer.rb +13 -0
- data/app/serializers/spree/v2/storefront/option_value_serializer.rb +11 -0
- data/app/serializers/spree/v2/storefront/payment_method_serializer.rb +11 -0
- data/app/serializers/spree/v2/storefront/payment_serializer.rb +12 -0
- data/app/serializers/spree/v2/storefront/product_property_serializer.rb +14 -0
- data/app/serializers/spree/v2/storefront/product_serializer.rb +35 -0
- data/app/serializers/spree/v2/storefront/promotion_serializer.rb +12 -0
- data/app/serializers/spree/v2/storefront/shipment_serializer.rb +16 -0
- data/app/serializers/spree/v2/storefront/shipping_rate_serializer.rb +14 -0
- data/app/serializers/spree/v2/storefront/state_serializer.rb +11 -0
- data/app/serializers/spree/v2/storefront/taxon_image_serializer.rb +11 -0
- data/app/serializers/spree/v2/storefront/taxon_serializer.rb +28 -0
- data/app/serializers/spree/v2/storefront/taxonomy_serializer.rb +11 -0
- data/app/serializers/spree/v2/storefront/user_serializer.rb +11 -0
- data/app/serializers/spree/v2/storefront/variant_serializer.rb +21 -0
- data/app/views/spree/api/v1/orders/order.v1.rabl +1 -1
- data/config/initializers/doorkeeper.rb +20 -0
- data/config/locales/en.yml +4 -0
- data/config/routes.rb +51 -3
- data/db/migrate/20180320110726_create_doorkeeper_tables.rb +69 -0
- data/docs/oauth/index.yml +77 -0
- data/docs/v2/storefront/index.yaml +2444 -0
- data/lib/spree/api/engine.rb +9 -2
- data/lib/spree_api.rb +2 -0
- data/spree_api.gemspec +5 -1
- metadata +92 -7
@@ -0,0 +1,82 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
module Storefront
|
5
|
+
class TaxonsController < ::Spree::Api::V2::BaseController
|
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
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def serialize_collection(collection)
|
19
|
+
dependencies[:collection_serializer].new(
|
20
|
+
collection,
|
21
|
+
collection_options(collection)
|
22
|
+
).serializable_hash
|
23
|
+
end
|
24
|
+
|
25
|
+
def serialize_resource(resource)
|
26
|
+
dependencies[:resource_serializer].new(
|
27
|
+
resource,
|
28
|
+
include: resource_includes,
|
29
|
+
fields: sparse_fields
|
30
|
+
).serializable_hash
|
31
|
+
end
|
32
|
+
|
33
|
+
def dependencies
|
34
|
+
{
|
35
|
+
collection_finder: Spree::Taxons::Find,
|
36
|
+
collection_paginator: Spree::Shared::Paginate,
|
37
|
+
collection_serializer: Spree::V2::Storefront::TaxonSerializer,
|
38
|
+
resource_serializer: Spree::V2::Storefront::TaxonSerializer
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def collection_options(collection)
|
43
|
+
{
|
44
|
+
links: collection_links(collection),
|
45
|
+
meta: collection_meta(collection),
|
46
|
+
include: resource_includes,
|
47
|
+
fields: sparse_fields
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
def paginated_collection
|
52
|
+
dependencies[:collection_paginator].new(collection, params).call
|
53
|
+
end
|
54
|
+
|
55
|
+
def collection
|
56
|
+
dependencies[:collection_finder].new(scope: scope, params: params).execute
|
57
|
+
end
|
58
|
+
|
59
|
+
def resource
|
60
|
+
scope.find_by(permalink: params[:id]) || scope.find(params[:id])
|
61
|
+
end
|
62
|
+
|
63
|
+
def scope
|
64
|
+
Spree::Taxon.accessible_by(current_ability, :read).includes(scope_includes)
|
65
|
+
end
|
66
|
+
|
67
|
+
def scope_includes
|
68
|
+
node_includes = %i[icon products parent taxonomy]
|
69
|
+
|
70
|
+
{
|
71
|
+
parent: node_includes,
|
72
|
+
children: node_includes,
|
73
|
+
taxonomy: [root: node_includes],
|
74
|
+
products: [],
|
75
|
+
icon: []
|
76
|
+
}
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
module CollectionOptionsHelpers
|
5
|
+
def collection_links(collection)
|
6
|
+
{
|
7
|
+
self: request.original_url,
|
8
|
+
next: pagination_url(collection.next_page || collection.total_pages),
|
9
|
+
prev: pagination_url(collection.prev_page || 1),
|
10
|
+
last: pagination_url(collection.total_pages),
|
11
|
+
first: pagination_url(1)
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
def collection_meta(collection)
|
16
|
+
{
|
17
|
+
count: collection.size,
|
18
|
+
total_count: collection.total_count,
|
19
|
+
total_pages: collection.total_pages
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
# leaving this method in public scope so it's still possible to modify
|
24
|
+
# those params to support non-standard non-JSON API parameters
|
25
|
+
def collection_permitted_params
|
26
|
+
params.permit(:format, :page, :per_page, :sort, :include, :fields, filter: {})
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def pagination_url(page)
|
32
|
+
url_for(collection_permitted_params.merge(page: page))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Spree
|
2
|
+
module V2
|
3
|
+
module Storefront
|
4
|
+
module Account
|
5
|
+
class CreditCardSerializer < BaseSerializer
|
6
|
+
set_type :credit_card
|
7
|
+
|
8
|
+
attributes :cc_type, :last_digits, :month, :year, :name
|
9
|
+
|
10
|
+
belongs_to :payment_method,
|
11
|
+
serializer: Spree::V2::Storefront::PaymentMethodSerializer
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Spree
|
2
|
+
module V2
|
3
|
+
module Storefront
|
4
|
+
class AccountSerializer < BaseSerializer
|
5
|
+
set_type :user
|
6
|
+
|
7
|
+
attributes :email
|
8
|
+
|
9
|
+
attribute :store_credits, &:total_available_store_credit
|
10
|
+
|
11
|
+
attribute :completed_orders do |object|
|
12
|
+
object.orders.complete.count
|
13
|
+
end
|
14
|
+
|
15
|
+
has_one :default_billing_address,
|
16
|
+
id_method_name: :bill_address_id,
|
17
|
+
object_method_name: :bill_address,
|
18
|
+
record_type: :address,
|
19
|
+
serializer: :address
|
20
|
+
|
21
|
+
has_one :default_shipping_address,
|
22
|
+
id_method_name: :ship_address_id,
|
23
|
+
object_method_name: :ship_address,
|
24
|
+
record_type: :address,
|
25
|
+
serializer: :address
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Spree
|
2
|
+
module V2
|
3
|
+
module Storefront
|
4
|
+
class AddressSerializer < BaseSerializer
|
5
|
+
set_type :address
|
6
|
+
|
7
|
+
attributes :firstname, :lastname, :address1, :address2, :city, :zipcode, :phone, :state_name,
|
8
|
+
:company, :country_name, :country_iso3
|
9
|
+
|
10
|
+
attribute :state_code, &:state_abbr
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Spree
|
2
|
+
module V2
|
3
|
+
module Storefront
|
4
|
+
class CartSerializer < BaseSerializer
|
5
|
+
set_type :cart
|
6
|
+
|
7
|
+
attributes :number, :item_total, :total, :ship_total, :adjustment_total, :created_at,
|
8
|
+
:updated_at, :included_tax_total, :additional_tax_total, :display_additional_tax_total,
|
9
|
+
:display_included_tax_total, :tax_total, :currency, :state, :token, :email,
|
10
|
+
:display_item_total, :display_ship_total, :display_adjustment_total, :display_tax_total,
|
11
|
+
:promo_total, :display_promo_total, :item_count, :special_instructions, :display_total
|
12
|
+
|
13
|
+
has_many :line_items
|
14
|
+
has_many :variants
|
15
|
+
has_many :promotions, id_method_name: :promotion_id do |cart|
|
16
|
+
# we only want to display applied and valid promotions
|
17
|
+
# sometimes Order can have multiple promotions but the promo engine
|
18
|
+
# will only apply those that are more beneficial for the customer
|
19
|
+
# TODO: we should probably move this code out of the serializer
|
20
|
+
promotion_ids = cart.all_adjustments.eligible.nonzero.promotion.map { |a| a.source.promotion_id }.uniq
|
21
|
+
|
22
|
+
cart.order_promotions.where(promotion_id: promotion_ids).uniq(&:promotion_id)
|
23
|
+
end
|
24
|
+
has_many :payments do |cart|
|
25
|
+
cart.payments.valid
|
26
|
+
end
|
27
|
+
has_many :shipments
|
28
|
+
|
29
|
+
belongs_to :user
|
30
|
+
belongs_to :billing_address,
|
31
|
+
id_method_name: :bill_address_id,
|
32
|
+
serializer: :address
|
33
|
+
|
34
|
+
belongs_to :shipping_address,
|
35
|
+
id_method_name: :ship_address_id,
|
36
|
+
serializer: :address
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Spree
|
2
|
+
module V2
|
3
|
+
module Storefront
|
4
|
+
class CountrySerializer < BaseSerializer
|
5
|
+
set_type :country
|
6
|
+
|
7
|
+
attributes :iso, :iso3, :iso_name, :name, :states_required,
|
8
|
+
:zipcode_required
|
9
|
+
|
10
|
+
attribute :default do |object|
|
11
|
+
object.default?
|
12
|
+
end
|
13
|
+
|
14
|
+
has_many :states, if: proc { |_record, params| params && params[:include_states] }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Spree
|
2
|
+
module V2
|
3
|
+
module Storefront
|
4
|
+
class LineItemSerializer < BaseSerializer
|
5
|
+
set_type :line_item
|
6
|
+
|
7
|
+
attributes :name, :quantity, :price, :slug, :options_text, :currency,
|
8
|
+
:display_price, :total, :display_total, :adjustment_total,
|
9
|
+
:display_adjustment_total, :additional_tax_total,
|
10
|
+
:display_additional_tax_total, :promo_total, :display_promo_total,
|
11
|
+
:included_tax_total, :display_included_tax_total
|
12
|
+
|
13
|
+
belongs_to :variant
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Spree
|
2
|
+
module V2
|
3
|
+
module Storefront
|
4
|
+
class PaymentSerializer < BaseSerializer
|
5
|
+
set_type :payment
|
6
|
+
|
7
|
+
attributes :amount, :response_code, :number, :cvv_response_code, :cvv_response_message,
|
8
|
+
:payment_method_id, :payment_method_name
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Spree
|
2
|
+
module V2
|
3
|
+
module Storefront
|
4
|
+
class ProductPropertySerializer < BaseSerializer
|
5
|
+
set_type :product_property
|
6
|
+
|
7
|
+
attribute :value
|
8
|
+
|
9
|
+
attribute :name, &:property_name
|
10
|
+
attribute :description, &:property_presentation
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Spree
|
2
|
+
module V2
|
3
|
+
module Storefront
|
4
|
+
class ProductSerializer < BaseSerializer
|
5
|
+
set_type :product
|
6
|
+
|
7
|
+
attributes :name, :description, :price, :currency, :display_price,
|
8
|
+
:available_on, :slug, :meta_description, :meta_keywords,
|
9
|
+
:updated_at
|
10
|
+
|
11
|
+
attribute :purchasable, &:purchasable?
|
12
|
+
attribute :in_stock, &:in_stock?
|
13
|
+
attribute :backorderable, &:backorderable?
|
14
|
+
|
15
|
+
has_many :variants
|
16
|
+
has_many :option_types
|
17
|
+
has_many :product_properties
|
18
|
+
has_many :taxons
|
19
|
+
|
20
|
+
# all images from all variants
|
21
|
+
has_many :images,
|
22
|
+
object_method_name: :variant_images,
|
23
|
+
id_method_name: :variant_image_ids,
|
24
|
+
record_type: :image,
|
25
|
+
serializer: :image
|
26
|
+
|
27
|
+
has_one :default_variant,
|
28
|
+
object_method_name: :default_variant,
|
29
|
+
id_method_name: :default_variant_id,
|
30
|
+
record_type: :variant,
|
31
|
+
serializer: :variant
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Spree
|
2
|
+
module V2
|
3
|
+
module Storefront
|
4
|
+
class ShipmentSerializer < BaseSerializer
|
5
|
+
set_type :shipment
|
6
|
+
|
7
|
+
attributes :number, :final_price, :display_final_price,
|
8
|
+
:state, :shipped_at, :tracking_url
|
9
|
+
|
10
|
+
attribute :free, &:free?
|
11
|
+
|
12
|
+
has_many :shipping_rates, if: proc { |_record, params| params&.dig(:show_rates) }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|