spree_api 4.3.0.rc1 → 4.3.1
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/caching.rb +33 -0
- data/app/controllers/spree/api/v2/base_controller.rb +3 -1
- data/app/controllers/spree/api/v2/platform/menu_items_controller.rb +2 -2
- data/app/controllers/spree/api/v2/platform/menus_controller.rb +4 -0
- data/app/controllers/spree/api/v2/platform/products_controller.rb +12 -0
- data/app/controllers/spree/api/v2/platform/resource_controller.rb +3 -0
- data/app/controllers/spree/api/v2/resource_controller.rb +6 -1
- data/app/controllers/spree/api/v2/storefront/account/addresses_controller.rb +3 -1
- data/app/controllers/spree/api/v2/storefront/account/orders_controller.rb +4 -0
- data/app/controllers/spree/api/v2/storefront/cart_controller.rb +39 -1
- data/app/controllers/spree/api/v2/storefront/countries_controller.rb +7 -0
- data/app/controllers/spree/api/v2/storefront/products_controller.rb +12 -0
- data/app/models/spree/api_configuration.rb +4 -2
- data/app/models/spree/api_dependencies.rb +6 -2
- data/app/presenters/spree/api/products/filters_presenter.rb +39 -0
- data/app/serializers/concerns/spree/api/v2/image_transformation_concern.rb +15 -0
- data/app/serializers/concerns/spree/api/v2/taxon_image_transformation_concern.rb +15 -0
- data/app/serializers/spree/api/v2/base_serializer.rb +1 -1
- data/app/serializers/spree/api/v2/platform/icon_serializer.rb +16 -0
- data/app/serializers/spree/api/v2/platform/image_serializer.rb +3 -1
- data/app/serializers/spree/api/v2/platform/menu_item_serializer.rb +28 -5
- data/app/serializers/spree/api/v2/platform/product_serializer.rb +11 -11
- data/app/serializers/spree/api/v2/platform/taxon_image_serializer.rb +3 -1
- data/app/serializers/spree/api/v2/platform/user_serializer.rb +16 -0
- data/app/serializers/spree/v2/storefront/icon_serializer.rb +14 -0
- data/app/serializers/spree/v2/storefront/image_serializer.rb +3 -1
- data/app/serializers/spree/v2/storefront/menu_item_serializer.rb +12 -6
- data/app/serializers/spree/v2/storefront/payment_method_serializer.rb +4 -0
- data/app/serializers/spree/v2/storefront/product_serializer.rb +18 -12
- data/app/serializers/spree/v2/storefront/taxon_image_serializer.rb +3 -1
- data/config/locales/en.yml +1 -1
- data/config/routes.rb +3 -1
- data/docs/oauth/index.yml +2 -2
- data/docs/v2/platform/index.yaml +2442 -244
- data/docs/v2/storefront/index.yaml +11541 -1152
- data/lib/spree/api/testing_support/v2/platform_contexts.rb +15 -5
- data/spree_api.gemspec +1 -1
- metadata +16 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebccfdea767ae857de3ace38671f8e7ab7e30d3b9f5eb61ee43ef02b317ddf85
|
4
|
+
data.tar.gz: f483c076187833ce9c64c28a068cc7c2399aa076c9239ee1494b9b78fca002f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 440f825585fb1ca9c66584aa773bbcd38f54b9f29b7c49813e63bd64ec5860ad400160385003b4dc25a9135d13a00fc33ad446e2125dbe4b2eadacc88288975a
|
7
|
+
data.tar.gz: 627bcf3c7ab826dc4bfd35b3391a3d3a3a016e2ad1283debde518157a052118e1a767ea46fdf92cad31b98d5d9d2a1adf9addd5697d3c7228b9b420f9d3c5b23
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
module Caching
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
def collection_cache_key(collection)
|
8
|
+
unscoped_collection = collection.unscope(:includes).unscope(:order)
|
9
|
+
cache_key_parts = [
|
10
|
+
self.class.to_s,
|
11
|
+
unscoped_collection.maximum(:updated_at),
|
12
|
+
unscoped_collection.ids,
|
13
|
+
resource_includes,
|
14
|
+
sparse_fields,
|
15
|
+
serializer_params,
|
16
|
+
params[:sort]&.strip,
|
17
|
+
params[:page]&.to_s&.strip,
|
18
|
+
params[:per_page]&.to_s&.strip,
|
19
|
+
].flatten.join('-')
|
20
|
+
|
21
|
+
Digest::MD5.hexdigest(cache_key_parts)
|
22
|
+
end
|
23
|
+
|
24
|
+
def collection_cache_opts
|
25
|
+
{
|
26
|
+
namespace: Spree::Api::Config[:api_v2_collection_cache_namespace],
|
27
|
+
expires_in: Spree::Api::Config[:api_v2_collection_cache_ttl],
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -132,7 +132,9 @@ module Spree
|
|
132
132
|
currency: current_currency,
|
133
133
|
locale: current_locale,
|
134
134
|
store: current_store,
|
135
|
-
user: spree_current_user
|
135
|
+
user: spree_current_user,
|
136
|
+
image_transformation: params[:image_transformation],
|
137
|
+
taxon_image_transformation: params[:taxon_image_transformation]
|
136
138
|
}
|
137
139
|
end
|
138
140
|
|
@@ -8,7 +8,7 @@ module Spree
|
|
8
8
|
def reposition
|
9
9
|
spree_authorize! :update, @moved_item if spree_current_user.present?
|
10
10
|
|
11
|
-
@moved_item = scope.find(params[:
|
11
|
+
@moved_item = scope.find(params[:id])
|
12
12
|
@new_parent = scope.find(params[:new_parent_id])
|
13
13
|
new_index = params[:new_position_idx].to_i
|
14
14
|
|
@@ -19,7 +19,7 @@ module Spree
|
|
19
19
|
end
|
20
20
|
|
21
21
|
if @moved_item.save
|
22
|
-
|
22
|
+
render_serialized_payload { serialize_resource(resource) }
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -14,6 +14,18 @@ module Spree
|
|
14
14
|
def scope_includes
|
15
15
|
product_list_includes
|
16
16
|
end
|
17
|
+
|
18
|
+
def allowed_sort_attributes
|
19
|
+
super << :available_on
|
20
|
+
end
|
21
|
+
|
22
|
+
def sorted_collection
|
23
|
+
collection_sorter.new(collection, current_currency, params, allowed_sort_attributes).call
|
24
|
+
end
|
25
|
+
|
26
|
+
def collection_sorter
|
27
|
+
Spree::Api::Dependencies.platform_products_sorter.constantize
|
28
|
+
end
|
17
29
|
end
|
18
30
|
end
|
19
31
|
end
|
@@ -18,6 +18,8 @@ module Spree
|
|
18
18
|
def create
|
19
19
|
resource = model_class.new(permitted_resource_params)
|
20
20
|
|
21
|
+
ensure_current_store(resource)
|
22
|
+
|
21
23
|
if resource.save
|
22
24
|
render_serialized_payload(201) { serialize_resource(resource) }
|
23
25
|
else
|
@@ -27,6 +29,7 @@ module Spree
|
|
27
29
|
|
28
30
|
def update
|
29
31
|
if resource.update(permitted_resource_params)
|
32
|
+
ensure_current_store(resource)
|
30
33
|
render_serialized_payload { serialize_resource(resource) }
|
31
34
|
else
|
32
35
|
render_error_payload(resource.errors)
|
@@ -3,9 +3,14 @@ module Spree
|
|
3
3
|
module V2
|
4
4
|
class ResourceController < ::Spree::Api::V2::BaseController
|
5
5
|
include Spree::Api::V2::CollectionOptionsHelpers
|
6
|
+
include Spree::Api::V2::Caching
|
6
7
|
|
7
8
|
def index
|
8
|
-
render_serialized_payload
|
9
|
+
render_serialized_payload do
|
10
|
+
Rails.cache.fetch(collection_cache_key(paginated_collection), collection_cache_opts) do
|
11
|
+
serialize_collection(paginated_collection)
|
12
|
+
end
|
13
|
+
end
|
9
14
|
end
|
10
15
|
|
11
16
|
def show
|
@@ -4,6 +4,8 @@ module Spree
|
|
4
4
|
module Storefront
|
5
5
|
module Account
|
6
6
|
class AddressesController < ::Spree::Api::V2::ResourceController
|
7
|
+
include Spree::BaseHelper
|
8
|
+
|
7
9
|
before_action :require_spree_current_user
|
8
10
|
|
9
11
|
def create
|
@@ -37,7 +39,7 @@ module Spree
|
|
37
39
|
end
|
38
40
|
|
39
41
|
def scope
|
40
|
-
super.where(user: spree_current_user).not_deleted
|
42
|
+
super.where(user: spree_current_user, country: available_countries).not_deleted
|
41
43
|
end
|
42
44
|
|
43
45
|
def model_class
|
@@ -4,8 +4,10 @@ module Spree
|
|
4
4
|
module Storefront
|
5
5
|
class CartController < ::Spree::Api::V2::BaseController
|
6
6
|
include Spree::Api::V2::Storefront::OrderConcern
|
7
|
-
before_action :ensure_order, except:
|
7
|
+
before_action :ensure_order, except: %i[create associate]
|
8
8
|
before_action :load_variant, only: :add_item
|
9
|
+
before_action :require_spree_current_user, only: :associate
|
10
|
+
|
9
11
|
|
10
12
|
def create
|
11
13
|
spree_authorize! :create, Spree::Order
|
@@ -128,6 +130,34 @@ module Spree
|
|
128
130
|
end
|
129
131
|
end
|
130
132
|
|
133
|
+
def associate
|
134
|
+
guest_order_token = params[:guest_order_token]
|
135
|
+
guest_order = ::Spree::Api::Dependencies.storefront_current_order_finder.constantize.new.execute(
|
136
|
+
store: current_store,
|
137
|
+
user: nil,
|
138
|
+
token: guest_order_token,
|
139
|
+
currency: current_currency
|
140
|
+
)
|
141
|
+
|
142
|
+
spree_authorize! :update, guest_order, guest_order_token
|
143
|
+
|
144
|
+
result = associate_service.call(guest_order: guest_order, user: spree_current_user)
|
145
|
+
|
146
|
+
if result.success?
|
147
|
+
render_serialized_payload { serialize_resource(guest_order) }
|
148
|
+
else
|
149
|
+
render_error_payload(result.error)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def change_currency
|
154
|
+
spree_authorize! :update, spree_current_order, order_token
|
155
|
+
|
156
|
+
result = change_currency_service.call(order: spree_current_order, new_currency: params[:new_currency])
|
157
|
+
|
158
|
+
render_order(result)
|
159
|
+
end
|
160
|
+
|
131
161
|
private
|
132
162
|
|
133
163
|
def resource_serializer
|
@@ -166,6 +196,14 @@ module Spree
|
|
166
196
|
Spree::Api::Dependencies.storefront_cart_estimate_shipping_rates_service.constantize
|
167
197
|
end
|
168
198
|
|
199
|
+
def associate_service
|
200
|
+
Spree::Api::Dependencies.storefront_cart_associate_service.constantize
|
201
|
+
end
|
202
|
+
|
203
|
+
def change_currency_service
|
204
|
+
Spree::Api::Dependencies.storefront_cart_change_currency_service.constantize
|
205
|
+
end
|
206
|
+
|
169
207
|
def line_item
|
170
208
|
@line_item ||= spree_current_order.line_items.find(params[:line_item_id])
|
171
209
|
end
|
@@ -3,6 +3,8 @@ module Spree
|
|
3
3
|
module V2
|
4
4
|
module Storefront
|
5
5
|
class CountriesController < ::Spree::Api::V2::ResourceController
|
6
|
+
before_action :set_default_per_page
|
7
|
+
|
6
8
|
private
|
7
9
|
|
8
10
|
def serialize_collection(collection)
|
@@ -43,6 +45,11 @@ module Spree
|
|
43
45
|
def model_class
|
44
46
|
Spree::Country
|
45
47
|
end
|
48
|
+
|
49
|
+
# by default we want to return all countries on a single page
|
50
|
+
def set_default_per_page
|
51
|
+
params[:per_page] ||= Spree::Country.count
|
52
|
+
end
|
46
53
|
end
|
47
54
|
end
|
48
55
|
end
|
@@ -42,6 +42,18 @@ module Spree
|
|
42
42
|
def scope_includes
|
43
43
|
product_list_includes
|
44
44
|
end
|
45
|
+
|
46
|
+
def allowed_sort_attributes
|
47
|
+
super << :available_on
|
48
|
+
end
|
49
|
+
|
50
|
+
def collection_meta(collection)
|
51
|
+
super(collection).merge(filters: filters_meta)
|
52
|
+
end
|
53
|
+
|
54
|
+
def filters_meta
|
55
|
+
Spree::Api::Products::FiltersPresenter.new(current_store, current_currency, params).to_h
|
56
|
+
end
|
45
57
|
end
|
46
58
|
end
|
47
59
|
end
|
@@ -1,8 +1,10 @@
|
|
1
1
|
module Spree
|
2
2
|
class ApiConfiguration < Preferences::Configuration
|
3
3
|
preference :requires_authentication, :boolean, default: true
|
4
|
-
preference :
|
4
|
+
preference :api_v2_serializers_cache_ttl, :integer, default: 3600 # 1 hour in seconds
|
5
|
+
preference :api_v2_collection_cache_ttl, :integer, default: 3600 # 1 hour in seconds
|
6
|
+
preference :api_v2_collection_cache_namespace, :string, default: 'api_v2_collection_cache'
|
5
7
|
preference :api_v2_content_type, :string, default: 'application/vnd.api+json'
|
6
|
-
preference :api_v2_per_page_limit, :integer, default:
|
8
|
+
preference :api_v2_per_page_limit, :integer, default: 500
|
7
9
|
end
|
8
10
|
end
|
@@ -14,12 +14,13 @@ module Spree
|
|
14
14
|
:storefront_country_serializer, :storefront_menu_serializer, :storefront_menu_finder, :storefront_current_order_finder,
|
15
15
|
:storefront_completed_order_finder, :storefront_order_sorter, :storefront_collection_paginator, :storefront_user_serializer,
|
16
16
|
:storefront_products_sorter, :storefront_products_finder, :storefront_product_serializer, :storefront_taxon_serializer,
|
17
|
-
:storefront_taxon_finder, :storefront_find_by_variant_finder, :storefront_cart_update_service,
|
17
|
+
:storefront_taxon_finder, :storefront_find_by_variant_finder, :storefront_cart_update_service, :storefront_cart_associate_service,
|
18
18
|
:storefront_cart_estimate_shipping_rates_service, :storefront_estimated_shipment_serializer,
|
19
19
|
:storefront_store_serializer, :storefront_address_serializer, :storefront_order_serializer,
|
20
20
|
:storefront_account_create_address_service, :storefront_account_update_address_service, :storefront_address_finder,
|
21
21
|
:storefront_account_create_service, :storefront_account_update_service, :storefront_collection_sorter, :error_handler,
|
22
|
-
:storefront_cart_empty_service, :storefront_cart_destroy_service, :storefront_credit_cards_destroy_service
|
22
|
+
:storefront_cart_empty_service, :storefront_cart_destroy_service, :storefront_credit_cards_destroy_service, :platform_products_sorter,
|
23
|
+
:storefront_cart_change_currency_service
|
23
24
|
].freeze
|
24
25
|
|
25
26
|
attr_accessor *INJECTION_POINTS
|
@@ -43,6 +44,8 @@ module Spree
|
|
43
44
|
@storefront_cart_estimate_shipping_rates_service = Spree::Dependencies.cart_estimate_shipping_rates_service
|
44
45
|
@storefront_cart_empty_service = Spree::Dependencies.cart_empty_service
|
45
46
|
@storefront_cart_destroy_service = Spree::Dependencies.cart_destroy_service
|
47
|
+
@storefront_cart_associate_service = Spree::Dependencies.cart_associate_service
|
48
|
+
@storefront_cart_change_currency_service = Spree::Dependencies.cart_change_currency_service
|
46
49
|
|
47
50
|
# coupon code handler
|
48
51
|
@storefront_coupon_handler = Spree::Dependencies.coupon_handler
|
@@ -85,6 +88,7 @@ module Spree
|
|
85
88
|
@storefront_collection_sorter = Spree::Dependencies.collection_sorter
|
86
89
|
@storefront_order_sorter = Spree::Dependencies.collection_sorter
|
87
90
|
@storefront_products_sorter = Spree::Dependencies.products_sorter
|
91
|
+
@platform_products_sorter = Spree::Dependencies.products_sorter
|
88
92
|
|
89
93
|
# paginators
|
90
94
|
@storefront_collection_paginator = Spree::Dependencies.collection_paginator
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module Products
|
4
|
+
class FiltersPresenter
|
5
|
+
def initialize(current_store, current_currency, params)
|
6
|
+
@products_for_filters = find_products_for_filters(current_store, current_currency, params)
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_h
|
10
|
+
option_values = Spree::OptionValues::FindAvailable.new(products_scope: products_for_filters).execute
|
11
|
+
option_values_presenters = Spree::Filters::OptionsPresenter.new(option_values_scope: option_values).to_a
|
12
|
+
product_properties = Spree::ProductProperties::FindAvailable.new(products_scope: products_for_filters).execute
|
13
|
+
product_properties_presenters = Spree::Filters::PropertiesPresenter.new(product_properties_scope: product_properties).to_a
|
14
|
+
{
|
15
|
+
option_types: option_values_presenters.map(&:to_h),
|
16
|
+
product_properties: product_properties_presenters.map(&:to_h)
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
attr_reader :products_for_filters
|
23
|
+
|
24
|
+
def find_products_for_filters(current_store, current_currency, params)
|
25
|
+
current_taxons = find_current_taxons(current_store, params)
|
26
|
+
current_store.products.active(current_currency).in_taxons(current_taxons)
|
27
|
+
end
|
28
|
+
|
29
|
+
def find_current_taxons(current_store, params)
|
30
|
+
taxons_param = params.dig(:filter, :taxons)
|
31
|
+
return nil if taxons_param.nil? || taxons_param.to_s.blank?
|
32
|
+
|
33
|
+
taxon_ids = taxons_param.to_s.split(',')
|
34
|
+
current_store.taxons.where(id: taxon_ids)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
module ImageTransformationConcern
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
def self.included(base)
|
8
|
+
base.attribute :transformed_url do |image, params|
|
9
|
+
image.generate_url(size: params.dig(:image_transformation, :size))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
module TaxonImageTransformationConcern
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
def self.included(base)
|
8
|
+
base.attribute :transformed_url do |image, params|
|
9
|
+
image.generate_url(size: params.dig(:taxon_image_transformation, :size))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -7,7 +7,7 @@ module Spree
|
|
7
7
|
# to learn more about caching, please refer to:
|
8
8
|
# https://github.com/jsonapi-serializer/jsonapi-serializer#caching
|
9
9
|
# https://guides.rubyonrails.org/caching_with_rails.html#low-level-caching
|
10
|
-
cache_options(store: Rails.cache, namespace: 'jsonapi-serializer', expires_in: Spree::Api::Config[:
|
10
|
+
cache_options(store: Rails.cache, namespace: 'jsonapi-serializer', expires_in: Spree::Api::Config[:api_v2_serializers_cache_ttl])
|
11
11
|
|
12
12
|
def self.record_cache_options(options, fieldset, include_list, params)
|
13
13
|
opts = options.dup
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
module Platform
|
5
|
+
class IconSerializer < BaseSerializer
|
6
|
+
set_type :icon
|
7
|
+
|
8
|
+
attribute :url do |icon|
|
9
|
+
url_helpers = Rails.application.routes.url_helpers
|
10
|
+
url_helpers.polymorphic_url(icon.attachment, only_path: true)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -3,9 +3,11 @@ module Spree
|
|
3
3
|
module V2
|
4
4
|
module Platform
|
5
5
|
class ImageSerializer < BaseSerializer
|
6
|
+
include ::Spree::Api::V2::ImageTransformationConcern
|
7
|
+
|
6
8
|
set_type :image
|
7
9
|
|
8
|
-
attributes :styles, :position, :alt, :created_at, :updated_at
|
10
|
+
attributes :styles, :position, :alt, :created_at, :updated_at, :original_url
|
9
11
|
|
10
12
|
belongs_to :viewable, polymorphic: true
|
11
13
|
end
|
@@ -5,16 +5,39 @@ module Spree
|
|
5
5
|
class MenuItemSerializer < BaseSerializer
|
6
6
|
include ::Spree::Api::V2::ResourceSerializerConcern
|
7
7
|
|
8
|
-
|
8
|
+
attributes :link
|
9
|
+
|
10
|
+
attribute :is_container do |menu_item|
|
11
|
+
menu_item.container?
|
12
|
+
end
|
13
|
+
|
14
|
+
attribute :is_root do |menu_item|
|
15
|
+
menu_item.root?
|
16
|
+
end
|
17
|
+
|
18
|
+
attribute :is_child do |menu_item|
|
19
|
+
menu_item.child?
|
20
|
+
end
|
21
|
+
|
22
|
+
attribute :is_leaf do |menu_item|
|
23
|
+
menu_item.leaf?
|
24
|
+
end
|
25
|
+
|
26
|
+
has_one :icon,
|
9
27
|
object_method_name: :icon,
|
10
28
|
id_method_name: :icon_id,
|
11
|
-
record_type: :
|
12
|
-
serializer: :
|
29
|
+
record_type: :icon,
|
30
|
+
serializer: :icon
|
13
31
|
|
14
32
|
belongs_to :menu, serializer: :menu
|
15
33
|
belongs_to :parent, record_type: :menu_item, serializer: :menu_item
|
16
|
-
belongs_to :linked_resource, polymorphic:
|
17
|
-
|
34
|
+
belongs_to :linked_resource, polymorphic: {
|
35
|
+
Spree::Cms::Pages::StandardPage => :cms_page,
|
36
|
+
Spree::Cms::Pages::FeaturePage => :cms_page,
|
37
|
+
Spree::Cms::Pages::Homepage => :cms_page
|
38
|
+
}
|
39
|
+
|
40
|
+
has_many :children, record_type: :menu_item, serializer: :menu_item
|
18
41
|
end
|
19
42
|
end
|
20
43
|
end
|
@@ -44,22 +44,22 @@ module Spree
|
|
44
44
|
|
45
45
|
belongs_to :tax_category
|
46
46
|
|
47
|
-
has_one
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
47
|
+
has_one :primary_variant,
|
48
|
+
object_method_name: :master,
|
49
|
+
id_method_name: :master_id,
|
50
|
+
record_type: :variant,
|
51
|
+
serializer: :variant
|
52
52
|
|
53
|
-
has_one
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
53
|
+
has_one :default_variant,
|
54
|
+
object_method_name: :default_variant,
|
55
|
+
id_method_name: :default_variant_id,
|
56
|
+
record_type: :variant,
|
57
|
+
serializer: :variant
|
58
58
|
|
59
59
|
has_many :variants
|
60
60
|
has_many :option_types
|
61
61
|
has_many :product_properties
|
62
|
-
has_many :taxons do |object, params|
|
62
|
+
has_many :taxons, serializer: :taxon, record_type: :taxon do |object, params|
|
63
63
|
object.taxons_for_store(params[:store])
|
64
64
|
end
|
65
65
|
|
@@ -3,9 +3,11 @@ module Spree
|
|
3
3
|
module V2
|
4
4
|
module Platform
|
5
5
|
class TaxonImageSerializer < BaseSerializer
|
6
|
+
include ::Spree::Api::V2::TaxonImageTransformationConcern
|
7
|
+
|
6
8
|
set_type :taxon_image
|
7
9
|
|
8
|
-
attributes :
|
10
|
+
attributes :alt, :created_at, :updated_at, :original_url
|
9
11
|
end
|
10
12
|
end
|
11
13
|
end
|
@@ -7,6 +7,18 @@ module Spree
|
|
7
7
|
|
8
8
|
attributes :email, :created_at, :updated_at
|
9
9
|
|
10
|
+
attribute :average_order_value do |user, params|
|
11
|
+
price_stats(user.report_values_for(:average_order_value, params[:store]))
|
12
|
+
end
|
13
|
+
|
14
|
+
attribute :lifetime_value do |user, params|
|
15
|
+
price_stats(user.report_values_for(:lifetime_value, params[:store]))
|
16
|
+
end
|
17
|
+
|
18
|
+
attribute :store_credits do |user, params|
|
19
|
+
price_stats(user.available_store_credits(params[:store]))
|
20
|
+
end
|
21
|
+
|
10
22
|
has_one :bill_address,
|
11
23
|
record_type: :address,
|
12
24
|
serializer: :address
|
@@ -14,6 +26,10 @@ module Spree
|
|
14
26
|
has_one :ship_address,
|
15
27
|
record_type: :address,
|
16
28
|
serializer: :address
|
29
|
+
|
30
|
+
def self.price_stats(stats)
|
31
|
+
stats.map { |value| { currency: value.currency.to_s, amount: value.money.to_s } }
|
32
|
+
end
|
17
33
|
end
|
18
34
|
end
|
19
35
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Spree
|
2
|
+
module V2
|
3
|
+
module Storefront
|
4
|
+
class IconSerializer < BaseSerializer
|
5
|
+
set_type :icon
|
6
|
+
|
7
|
+
attribute :url do |icon|
|
8
|
+
url_helpers = Rails.application.routes.url_helpers
|
9
|
+
url_helpers.polymorphic_url(icon.attachment, only_path: true)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -2,9 +2,11 @@ module Spree
|
|
2
2
|
module V2
|
3
3
|
module Storefront
|
4
4
|
class ImageSerializer < BaseSerializer
|
5
|
+
include ::Spree::Api::V2::ImageTransformationConcern
|
6
|
+
|
5
7
|
set_type :image
|
6
8
|
|
7
|
-
attributes :
|
9
|
+
attributes :styles, :position, :alt, :original_url
|
8
10
|
end
|
9
11
|
end
|
10
12
|
end
|
@@ -4,7 +4,7 @@ module Spree
|
|
4
4
|
class MenuItemSerializer < BaseSerializer
|
5
5
|
set_type :menu_item
|
6
6
|
|
7
|
-
attributes :code, :name, :subtitle, :link, :new_window, :lft, :rgt, :depth
|
7
|
+
attributes :code, :name, :subtitle, :link, :destination, :item_type, :new_window, :lft, :rgt, :depth
|
8
8
|
|
9
9
|
attribute :is_container do |menu_item|
|
10
10
|
menu_item.container?
|
@@ -22,15 +22,21 @@ module Spree
|
|
22
22
|
menu_item.leaf?
|
23
23
|
end
|
24
24
|
|
25
|
-
has_one :
|
25
|
+
has_one :icon,
|
26
26
|
object_method_name: :icon,
|
27
27
|
id_method_name: :icon_id,
|
28
|
-
record_type: :
|
29
|
-
serializer: :
|
28
|
+
record_type: :icon,
|
29
|
+
serializer: :icon
|
30
30
|
|
31
|
+
belongs_to :menu, serializer: :menu
|
31
32
|
belongs_to :parent, record_type: :menu_item, serializer: :menu_item
|
32
|
-
belongs_to :linked_resource, polymorphic:
|
33
|
-
|
33
|
+
belongs_to :linked_resource, polymorphic: {
|
34
|
+
Spree::Cms::Pages::StandardPage => :cms_page,
|
35
|
+
Spree::Cms::Pages::FeaturePage => :cms_page,
|
36
|
+
Spree::Cms::Pages::Homepage => :cms_page
|
37
|
+
}
|
38
|
+
|
39
|
+
has_many :children, record_type: :menu_item, serializer: :menu_item
|
34
40
|
end
|
35
41
|
end
|
36
42
|
end
|