spree_api 3.7.1 → 3.7.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of spree_api might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/app/controllers/spree/api/v2/storefront/cart_controller.rb +36 -1
- data/app/models/spree/api_dependencies.rb +3 -1
- data/app/serializers/spree/v2/storefront/estimated_shipping_rate_serializer.rb +25 -0
- data/config/locales/en.yml +1 -0
- data/config/routes.rb +2 -0
- data/docs/v2/storefront/index.yaml +49 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5d7921c3d756d21b52c3b0533c15f5a73520b8fadd5b27fdd97865e14f19ca0
|
4
|
+
data.tar.gz: 217e9158bd8b96694763eaf9767cc4cde8fec4b58461cc00669fa9a8d64fb90d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db362f697b5fca101db4c9a6a6262a75da56c97deacf50b85cd346faafad82c6eb17448eb5198b38abdd56f3712ecf25d9b481bf36972ce12cfdc283b214c400
|
7
|
+
data.tar.gz: 9ab9e97101eef9472aef26c85636dedd0c1e7d518bcbc73f469875bd9325da54d69a965200ee9ad483e8b37566a7bd0c2c443034dad443e7b22895125b98156d
|
@@ -90,7 +90,15 @@ module Spree
|
|
90
90
|
def remove_coupon_code
|
91
91
|
spree_authorize! :update, spree_current_order, order_token
|
92
92
|
|
93
|
-
|
93
|
+
coupon_code = if params[:coupon_code].present?
|
94
|
+
params[:coupon_code]
|
95
|
+
else
|
96
|
+
spree_current_order.promotions.coupons.first&.code
|
97
|
+
end
|
98
|
+
|
99
|
+
return render_error_payload(Spree.t('v2.cart.no_coupon_code', scope: 'api')) if coupon_code.nil?
|
100
|
+
|
101
|
+
result = coupon_handler.new(spree_current_order).remove(coupon_code)
|
94
102
|
|
95
103
|
if result.error.blank?
|
96
104
|
render_serialized_payload { serialized_current_order }
|
@@ -99,6 +107,18 @@ module Spree
|
|
99
107
|
end
|
100
108
|
end
|
101
109
|
|
110
|
+
def estimate_shipping_rates
|
111
|
+
spree_authorize! :show, spree_current_order, order_token
|
112
|
+
|
113
|
+
result = estimate_shipping_rates_service.call(order: spree_current_order, country_iso: params[:country_iso])
|
114
|
+
|
115
|
+
if result.error.blank?
|
116
|
+
render_serialized_payload { serialize_estimated_shipping_rates(result.value) }
|
117
|
+
else
|
118
|
+
render_error_payload(result.error)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
102
122
|
private
|
103
123
|
|
104
124
|
def resource_serializer
|
@@ -125,6 +145,10 @@ module Spree
|
|
125
145
|
Spree::Api::Dependencies.storefront_coupon_handler.constantize
|
126
146
|
end
|
127
147
|
|
148
|
+
def estimate_shipping_rates_service
|
149
|
+
Spree::Api::Dependencies.storefront_cart_estimate_shipping_rates_service.constantize
|
150
|
+
end
|
151
|
+
|
128
152
|
def line_item
|
129
153
|
@line_item ||= spree_current_order.line_items.find(params[:line_item_id])
|
130
154
|
end
|
@@ -132,6 +156,17 @@ module Spree
|
|
132
156
|
def render_error_item_quantity
|
133
157
|
render json: { error: I18n.t(:wrong_quantity, scope: 'spree.api.v2.cart') }, status: 422
|
134
158
|
end
|
159
|
+
|
160
|
+
def estimate_shipping_rates_serializer
|
161
|
+
Spree::Api::Dependencies.storefront_estimated_shipment_serializer.constantize
|
162
|
+
end
|
163
|
+
|
164
|
+
def serialize_estimated_shipping_rates(shipping_rates)
|
165
|
+
estimate_shipping_rates_serializer.new(
|
166
|
+
shipping_rates,
|
167
|
+
params: { currency: spree_current_order.currency }
|
168
|
+
).serializable_hash
|
169
|
+
end
|
135
170
|
end
|
136
171
|
end
|
137
172
|
end
|
@@ -13,7 +13,7 @@ module Spree
|
|
13
13
|
:storefront_country_serializer, :storefront_current_order_finder, :storefront_completed_order_finder, :storefront_order_sorter,
|
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
|
-
:storefront_cart_update_service
|
16
|
+
:storefront_cart_update_service, :storefront_cart_estimate_shipping_rates_service, :storefront_estimated_shipment_serializer
|
17
17
|
].freeze
|
18
18
|
|
19
19
|
attr_accessor *INJECTION_POINTS
|
@@ -34,6 +34,7 @@ module Spree
|
|
34
34
|
@storefront_cart_remove_item_service = Spree::Dependencies.cart_remove_item_service
|
35
35
|
@storefront_cart_set_item_quantity_service = Spree::Dependencies.cart_set_item_quantity_service
|
36
36
|
@storefront_cart_recalculate_service = Spree::Dependencies.cart_recalculate_service
|
37
|
+
@storefront_cart_estimate_shipping_rates_service = Spree::Dependencies.cart_estimate_shipping_rates_service
|
37
38
|
|
38
39
|
# coupon code handler
|
39
40
|
@storefront_coupon_handler = Spree::Dependencies.coupon_handler
|
@@ -56,6 +57,7 @@ module Spree
|
|
56
57
|
@storefront_taxon_serializer = 'Spree::V2::Storefront::TaxonSerializer'
|
57
58
|
@storefront_payment_method_serializer = 'Spree::V2::Storefront::PaymentMethodSerializer'
|
58
59
|
@storefront_product_serializer = 'Spree::V2::Storefront::ProductSerializer'
|
60
|
+
@storefront_estimated_shipment_serializer = 'Spree::V2::Storefront::EstimatedShippingRateSerializer'
|
59
61
|
|
60
62
|
# sorters
|
61
63
|
@storefront_order_sorter = Spree::Dependencies.order_sorter
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Spree
|
2
|
+
module V2
|
3
|
+
module Storefront
|
4
|
+
class EstimatedShippingRateSerializer < BaseSerializer
|
5
|
+
set_type :shipping_rate
|
6
|
+
|
7
|
+
attributes :name, :selected, :cost, :tax_amount, :shipping_method_id
|
8
|
+
|
9
|
+
attribute :final_price, &:cost
|
10
|
+
|
11
|
+
attributes :display_cost, :display_final_price do |object, params|
|
12
|
+
Spree::Money.new(object.cost, currency: params[:currency])
|
13
|
+
end
|
14
|
+
|
15
|
+
attribute :display_tax_amount do |object, params|
|
16
|
+
Spree::Money.new(object.tax_amount, currency: params[:currency])
|
17
|
+
end
|
18
|
+
|
19
|
+
attribute :free do |object|
|
20
|
+
object.cost.zero?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/config/locales/en.yml
CHANGED
data/config/routes.rb
CHANGED
@@ -137,6 +137,8 @@ Spree::Core::Engine.add_routes do
|
|
137
137
|
patch :set_quantity
|
138
138
|
patch :apply_coupon_code
|
139
139
|
delete 'remove_coupon_code/:coupon_code', to: 'cart#remove_coupon_code', as: :cart_remove_coupon_code
|
140
|
+
delete 'remove_coupon_code', to: 'cart#remove_coupon_code', as: :cart_remove_coupon_code_without_code
|
141
|
+
get :estimate_shipping_rates
|
140
142
|
end
|
141
143
|
|
142
144
|
resource :checkout, controller: :checkout, only: %i[update] do
|
@@ -404,6 +404,35 @@ paths:
|
|
404
404
|
- orderToken: []
|
405
405
|
- bearerAuth: []
|
406
406
|
|
407
|
+
'/cart/estimate_shipping_rates':
|
408
|
+
get:
|
409
|
+
description: Returns a list of Estimated Shipping Rates for Cart
|
410
|
+
tags:
|
411
|
+
- Cart
|
412
|
+
operationId: 'Estimate Shipping Rates'
|
413
|
+
parameters:
|
414
|
+
- name: country_iso
|
415
|
+
in: query
|
416
|
+
description: >-
|
417
|
+
Country ISO or ISO3 symbol to get estimations for this destination,
|
418
|
+
by default we'll try to reuse Cart shipping address or the default Country for the current Store
|
419
|
+
schema:
|
420
|
+
type: string
|
421
|
+
example: 'USA'
|
422
|
+
- $ref: '#/components/parameters/SparseFieldsParam'
|
423
|
+
responses:
|
424
|
+
'200':
|
425
|
+
description: Returns a list of estimated Shipping Rates for Cart
|
426
|
+
content:
|
427
|
+
application/vnd.api+json:
|
428
|
+
schema:
|
429
|
+
$ref: '#/components/schemas/EstimateShippingRatesList'
|
430
|
+
'404':
|
431
|
+
$ref: '#/components/responses/404NotFound'
|
432
|
+
security:
|
433
|
+
- orderToken: []
|
434
|
+
- bearerAuth: []
|
435
|
+
|
407
436
|
'/checkout':
|
408
437
|
patch:
|
409
438
|
description: >-
|
@@ -788,6 +817,18 @@ paths:
|
|
788
817
|
description: >-
|
789
818
|
Find Prodcuts with Variants that have the specified option (eg. color, size)
|
790
819
|
and value (eg. red, XS)
|
820
|
+
- in: query
|
821
|
+
name: 'filter[show_deleted]'
|
822
|
+
schema:
|
823
|
+
type: boolean
|
824
|
+
example: true
|
825
|
+
description: Returns also deleted products
|
826
|
+
- in: query
|
827
|
+
name: 'filter[show_discontinued]'
|
828
|
+
schema:
|
829
|
+
type: boolean
|
830
|
+
example: true
|
831
|
+
description: Returns also discontinued products
|
791
832
|
- in: query
|
792
833
|
name: sort
|
793
834
|
schema:
|
@@ -2221,6 +2262,14 @@ components:
|
|
2221
2262
|
items:
|
2222
2263
|
oneOf:
|
2223
2264
|
- $ref: '#/components/schemas/ShippingRate'
|
2265
|
+
EstimateShippingRatesList:
|
2266
|
+
required:
|
2267
|
+
- data
|
2268
|
+
properties:
|
2269
|
+
data:
|
2270
|
+
type: array
|
2271
|
+
items:
|
2272
|
+
$ref: '#/components/schemas/ShippingRate'
|
2224
2273
|
ShippingRate:
|
2225
2274
|
properties:
|
2226
2275
|
id:
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spree_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.7.
|
4
|
+
version: 3.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Bigg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jsonapi-rspec
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 3.7.
|
33
|
+
version: 3.7.2
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 3.7.
|
40
|
+
version: 3.7.2
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rabl
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -165,6 +165,7 @@ files:
|
|
165
165
|
- app/serializers/spree/v2/storefront/cart_serializer.rb
|
166
166
|
- app/serializers/spree/v2/storefront/country_serializer.rb
|
167
167
|
- app/serializers/spree/v2/storefront/credit_card_serializer.rb
|
168
|
+
- app/serializers/spree/v2/storefront/estimated_shipping_rate_serializer.rb
|
168
169
|
- app/serializers/spree/v2/storefront/image_serializer.rb
|
169
170
|
- app/serializers/spree/v2/storefront/line_item_serializer.rb
|
170
171
|
- app/serializers/spree/v2/storefront/option_type_serializer.rb
|