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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 5c775a337b7b88a78b9bc3640d9916e7222dab2531a0e2d21ddbc00de81b3209
4
- data.tar.gz: f0012e6e408f4d6d949d7bb0f8560865ad2fb031ffc57386481c089f513e245d
2
+ SHA1:
3
+ metadata.gz: 677ea538aa5d07cafe028a25887601a469365457
4
+ data.tar.gz: cc58aa18f3e4507b4a8c9a883a7b286d9983d304
5
5
  SHA512:
6
- metadata.gz: 44b279d33f77d975be6b7f1f1e7d8b9eef9e665a5e095e62e81ff58af89eb556757b319c531b5f6759e7cd89a01c7c886a57a5e6f49f1ee2ef6435e6470c5ff6
7
- data.tar.gz: 4c7b349bca39e9939d635fd4fa0ef24a216937f140ca77410adb847b19beb31ea3faa5ac5e9cb154155e273cfaf7a6ab293b28816e682c7fecb1071e737f4cd7
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.find(id)
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
- @product = super(params[:product_id])
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('ArgumentError')
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
- if @quantity < 0 || @target_shipment == @original_shipment
95
- unprocessable_entity('ArgumentError')
96
- return
97
- end
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
- @original_shipment.transfer_to_shipment(@variant, @quantity, @target_shipment)
100
- render json: { success: true, message: Spree.t(:shipment_transfer_success) }, status: 201
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
- : @stock_item.adjust_count_on_hand(count_on_hand)
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
- @taxons = taxonomy.root.children
8
- else
9
- if params[:ids]
10
- @taxons = Spree::Taxon.includes(:children).accessible_by(current_ability, :read).where(id: params[:ids].split(','))
11
- else
12
- @taxons = Spree::Taxon.includes(:children).accessible_by(current_ability, :read).order(:taxonomy_id, :lft).ransack(params[:q]).result
13
- end
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({ option_values: :option_type }, :product, :default_price, :images, stock_items: :stock_location).
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({ option_values: :option_type }, :option_values, :product, :default_price, :images, stock_items: :stock_location).
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).friendly.find(params[:product_id]) if params[:product_id]
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
@@ -0,0 +1,2 @@
1
+ object false
2
+ node(:error) { Spree.t(:insufficient_quantity, scope: [:api, :order]) }
@@ -13,7 +13,7 @@ child selected_shipping_rate: :selected_shipping_rate do
13
13
  end
14
14
 
15
15
  child shipping_methods: :shipping_methods do
16
- attributes :id, :name
16
+ attributes :id, :name, :tracking_url
17
17
  child zones: :zones do
18
18
  attributes :id, :name, :description
19
19
  end
@@ -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.6
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: 2019-12-12 00:00:00.000000000 Z
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.4.6
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.4.6
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: '0'
236
+ version: 1.3.1
236
237
  requirements: []
237
- rubygems_version: 3.0.2
238
+ rubyforge_project:
239
+ rubygems_version: 2.6.14
238
240
  signing_key:
239
241
  specification_version: 4
240
242
  summary: Spree's API