spree_api 3.4.6 → 3.5.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/app/controllers/spree/api/base_controller.rb +3 -2
- data/app/controllers/spree/api/v1/product_properties_controller.rb +5 -2
- data/app/controllers/spree/api/v1/products_controller.rb +6 -3
- data/app/controllers/spree/api/v1/shipments_controller.rb +15 -7
- data/app/controllers/spree/api/v1/stock_items_controller.rb +6 -1
- data/app/controllers/spree/api/v1/taxons_controller.rb +8 -10
- data/app/controllers/spree/api/v1/variants_controller.rb +8 -4
- data/app/views/spree/api/v1/orders/insufficient_quantity.v1.rabl +2 -0
- data/app/views/spree/api/v1/shipments/show.v1.rabl +1 -1
- data/config/locales/en.yml +4 -0
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 677ea538aa5d07cafe028a25887601a469365457
|
4
|
+
data.tar.gz: cc58aa18f3e4507b4a8c9a883a7b286d9983d304
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 345475efd8e9059130c97dea2f4fb067138ae666a92818e24c3de83aa9a6f5848c205ce061ac2f406ea1a8be5297baa092ad365e96b66c3d5adac4d757ae9ddb
|
7
|
+
data.tar.gz: aad528fa2543e85a9b722e9dc2d60c4337b25ef13acbd8ee9d28b8c8a61510b772712e334834cea2cffa7c2240736e3ab37570a59c93fb36492ecaf653a0bb8d
|
@@ -123,9 +123,10 @@ module Spree
|
|
123
123
|
end
|
124
124
|
|
125
125
|
def find_product(id)
|
126
|
-
product_scope.friendly.distinct(false).find(id.to_s)
|
126
|
+
@product = product_scope.friendly.distinct(false).find(id.to_s)
|
127
127
|
rescue ActiveRecord::RecordNotFound
|
128
|
-
product_scope.
|
128
|
+
@product = product_scope.find_by(id: id)
|
129
|
+
not_found unless @product
|
129
130
|
end
|
130
131
|
|
131
132
|
def product_scope
|
@@ -2,7 +2,7 @@ module Spree
|
|
2
2
|
module Api
|
3
3
|
module V1
|
4
4
|
class ProductPropertiesController < Spree::Api::BaseController
|
5
|
-
before_action :find_product
|
5
|
+
before_action :find_product, :authorize_product!
|
6
6
|
before_action :product_property, only: [:show, :update, :destroy]
|
7
7
|
|
8
8
|
def index
|
@@ -47,7 +47,10 @@ module Spree
|
|
47
47
|
private
|
48
48
|
|
49
49
|
def find_product
|
50
|
-
|
50
|
+
super(params[:product_id])
|
51
|
+
end
|
52
|
+
|
53
|
+
def authorize_product!
|
51
54
|
authorize! :read, @product
|
52
55
|
end
|
53
56
|
|
@@ -2,6 +2,8 @@ module Spree
|
|
2
2
|
module Api
|
3
3
|
module V1
|
4
4
|
class ProductsController < Spree::Api::BaseController
|
5
|
+
before_action :find_product, only: [:update, :show, :destroy]
|
6
|
+
|
5
7
|
def index
|
6
8
|
if params[:ids]
|
7
9
|
@products = product_scope.where(id: params[:ids].split(',').flatten)
|
@@ -16,7 +18,6 @@ module Spree
|
|
16
18
|
end
|
17
19
|
|
18
20
|
def show
|
19
|
-
@product = find_product(params[:id])
|
20
21
|
expires_in 15.minutes, public: true
|
21
22
|
headers['Surrogate-Control'] = "max-age=#{15.minutes}"
|
22
23
|
headers['Surrogate-Key'] = 'product_id=1'
|
@@ -74,7 +75,6 @@ module Spree
|
|
74
75
|
end
|
75
76
|
|
76
77
|
def update
|
77
|
-
@product = find_product(params[:id])
|
78
78
|
authorize! :update, @product
|
79
79
|
|
80
80
|
options = { variants_attrs: variants_params, options_attrs: option_types_params }
|
@@ -88,7 +88,6 @@ module Spree
|
|
88
88
|
end
|
89
89
|
|
90
90
|
def destroy
|
91
|
-
@product = find_product(params[:id])
|
92
91
|
authorize! :destroy, @product
|
93
92
|
@product.destroy
|
94
93
|
respond_with(@product, status: 204)
|
@@ -116,6 +115,10 @@ module Spree
|
|
116
115
|
params[:product].fetch(:option_types, [])
|
117
116
|
end
|
118
117
|
|
118
|
+
def find_product
|
119
|
+
super(params[:id])
|
120
|
+
end
|
121
|
+
|
119
122
|
def set_up_shipping_category
|
120
123
|
if shipping_category = params[:product].delete(:shipping_category)
|
121
124
|
id = ShippingCategory.find_or_create_by(name: shipping_category).id
|
@@ -80,7 +80,7 @@ module Spree
|
|
80
80
|
@stock_location = Spree::StockLocation.find(params[:stock_location_id])
|
81
81
|
|
82
82
|
unless @quantity > 0
|
83
|
-
unprocessable_entity('
|
83
|
+
unprocessable_entity("#{Spree.t(:shipment_transfer_errors_occured, scope: 'api')} \n #{Spree.t(:negative_quantity, scope: 'api')}")
|
84
84
|
return
|
85
85
|
end
|
86
86
|
|
@@ -91,13 +91,21 @@ module Spree
|
|
91
91
|
def transfer_to_shipment
|
92
92
|
@target_shipment = Spree::Shipment.find_by!(number: params[:target_shipment_number])
|
93
93
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
94
|
+
error =
|
95
|
+
if @quantity < 0 && @target_shipment == @original_shipment
|
96
|
+
"#{Spree.t(:negative_quantity, scope: 'api')}, \n#{Spree.t('wrong_shipment_target', scope: 'api')}"
|
97
|
+
elsif @target_shipment == @original_shipment
|
98
|
+
Spree.t(:wrong_shipment_target, scope: 'api')
|
99
|
+
elsif @quantity < 0
|
100
|
+
Spree.t(:negative_quantity, scope: 'api')
|
101
|
+
end
|
98
102
|
|
99
|
-
|
100
|
-
|
103
|
+
if error
|
104
|
+
unprocessable_entity("#{Spree.t(:shipment_transfer_errors_occured, scope: 'api')} \n#{error}")
|
105
|
+
else
|
106
|
+
@original_shipment.transfer_to_shipment(@variant, @quantity, @target_shipment)
|
107
|
+
render json: { success: true, message: Spree.t(:shipment_transfer_success) }, status: 201
|
108
|
+
end
|
101
109
|
end
|
102
110
|
|
103
111
|
private
|
@@ -34,6 +34,11 @@ module Spree
|
|
34
34
|
def update
|
35
35
|
@stock_item = StockItem.accessible_by(current_ability, :update).find(params[:id])
|
36
36
|
|
37
|
+
if params[:stock_item].key?(:backorderable)
|
38
|
+
@stock_item.backorderable = params[:stock_item][:backorderable]
|
39
|
+
@stock_item.save
|
40
|
+
end
|
41
|
+
|
37
42
|
count_on_hand = 0
|
38
43
|
if params[:stock_item].key?(:count_on_hand)
|
39
44
|
count_on_hand = params[:stock_item][:count_on_hand].to_i
|
@@ -41,7 +46,7 @@ module Spree
|
|
41
46
|
end
|
42
47
|
|
43
48
|
updated = params[:stock_item][:force] ? @stock_item.set_count_on_hand(count_on_hand)
|
44
|
-
|
49
|
+
: @stock_item.adjust_count_on_hand(count_on_hand)
|
45
50
|
|
46
51
|
if updated
|
47
52
|
respond_with(@stock_item, status: 200, default_template: :show)
|
@@ -3,16 +3,14 @@ module Spree
|
|
3
3
|
module V1
|
4
4
|
class TaxonsController < Spree::Api::BaseController
|
5
5
|
def index
|
6
|
-
if taxonomy
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
|
6
|
+
@taxons = if taxonomy
|
7
|
+
taxonomy.root.children
|
8
|
+
elsif params[:ids]
|
9
|
+
Spree::Taxon.includes(:children).accessible_by(current_ability, :read).where(id: params[:ids].split(','))
|
10
|
+
else
|
11
|
+
Spree::Taxon.includes(:children).accessible_by(current_ability, :read).order(:taxonomy_id, :lft)
|
12
|
+
end
|
13
|
+
@taxons = @taxons.ransack(params[:q]).result
|
16
14
|
@taxons = @taxons.page(params[:page]).per(params[:per_page])
|
17
15
|
respond_with(@taxons)
|
18
16
|
end
|
@@ -24,7 +24,7 @@ module Spree
|
|
24
24
|
# we render on the view so we better update it any time a node is included
|
25
25
|
# or removed from the views.
|
26
26
|
def index
|
27
|
-
@variants = scope.includes(
|
27
|
+
@variants = scope.includes(*variant_includes).for_currency_and_available_price_amount.
|
28
28
|
ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
29
29
|
respond_with(@variants)
|
30
30
|
end
|
@@ -32,8 +32,7 @@ module Spree
|
|
32
32
|
def new; end
|
33
33
|
|
34
34
|
def show
|
35
|
-
@variant = scope.includes(
|
36
|
-
find(params[:id])
|
35
|
+
@variant = scope.includes(*variant_includes).find(params[:id])
|
37
36
|
respond_with(@variant)
|
38
37
|
end
|
39
38
|
|
@@ -49,7 +48,8 @@ module Spree
|
|
49
48
|
private
|
50
49
|
|
51
50
|
def product
|
52
|
-
@product ||= Spree::Product.accessible_by(current_ability, :read).
|
51
|
+
@product ||= Spree::Product.accessible_by(current_ability, :read).
|
52
|
+
friendly.find(params[:product_id]) if params[:product_id]
|
53
53
|
end
|
54
54
|
|
55
55
|
def scope
|
@@ -69,6 +69,10 @@ module Spree
|
|
69
69
|
def variant_params
|
70
70
|
params.require(:variant).permit(permitted_variant_attributes)
|
71
71
|
end
|
72
|
+
|
73
|
+
def variant_includes
|
74
|
+
[{ option_values: :option_type }, :product, :default_price, :images, { stock_items: :stock_location }]
|
75
|
+
end
|
72
76
|
end
|
73
77
|
end
|
74
78
|
end
|
data/config/locales/en.yml
CHANGED
@@ -18,6 +18,7 @@ en:
|
|
18
18
|
order:
|
19
19
|
could_not_transition: "The order could not be transitioned. Please fix the errors and try again."
|
20
20
|
invalid_shipping_method: "Invalid shipping method specified."
|
21
|
+
insufficient_quantity: An item in your cart has become unavailable.
|
21
22
|
payment:
|
22
23
|
credit_over_limit: "This payment can only be credited up to %{limit}. Please specify an amount less than or equal to this number."
|
23
24
|
update_forbidden: "This payment cannot be updated because it is %{state}."
|
@@ -25,3 +26,6 @@ en:
|
|
25
26
|
cannot_ready: "Cannot ready shipment."
|
26
27
|
stock_location_required: "A stock_location_id parameter must be provided in order to retrieve stock movements."
|
27
28
|
invalid_taxonomy_id: "Invalid taxonomy id."
|
29
|
+
shipment_transfer_errors_occured: "Following errors occured while attempting this action:"
|
30
|
+
negative_quantity: "quantity is negative"
|
31
|
+
wrong_shipment_target: "target shipment is the same as original shipment"
|
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.
|
4
|
+
version: 3.5.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Bigg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: spree_core
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 3.
|
19
|
+
version: 3.5.0.rc1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 3.
|
26
|
+
version: 3.5.0.rc1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rabl
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -131,6 +131,7 @@ files:
|
|
131
131
|
- app/views/spree/api/v1/orders/could_not_apply_coupon.v1.rabl
|
132
132
|
- app/views/spree/api/v1/orders/could_not_transition.v1.rabl
|
133
133
|
- app/views/spree/api/v1/orders/index.v1.rabl
|
134
|
+
- app/views/spree/api/v1/orders/insufficient_quantity.v1.rabl
|
134
135
|
- app/views/spree/api/v1/orders/invalid_shipping_method.v1.rabl
|
135
136
|
- app/views/spree/api/v1/orders/mine.v1.rabl
|
136
137
|
- app/views/spree/api/v1/orders/order.v1.rabl
|
@@ -230,11 +231,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
230
231
|
version: 2.2.7
|
231
232
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
232
233
|
requirements:
|
233
|
-
- - "
|
234
|
+
- - ">"
|
234
235
|
- !ruby/object:Gem::Version
|
235
|
-
version:
|
236
|
+
version: 1.3.1
|
236
237
|
requirements: []
|
237
|
-
|
238
|
+
rubyforge_project:
|
239
|
+
rubygems_version: 2.6.14
|
238
240
|
signing_key:
|
239
241
|
specification_version: 4
|
240
242
|
summary: Spree's API
|