spree_api 2.2.14 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +43 -1
- data/app/controllers/spree/api/base_controller.rb +8 -12
- data/app/controllers/spree/api/checkouts_controller.rb +4 -58
- data/app/controllers/spree/api/inventory_units_controller.rb +0 -1
- data/app/controllers/spree/api/line_items_controller.rb +3 -3
- data/app/controllers/spree/api/option_types_controller.rb +2 -2
- data/app/controllers/spree/api/orders_controller.rb +11 -36
- data/app/controllers/spree/api/payments_controller.rb +2 -2
- data/app/controllers/spree/api/products_controller.rb +6 -36
- data/app/controllers/spree/api/shipments_controller.rb +6 -25
- data/app/controllers/spree/api/taxonomies_controller.rb +8 -6
- data/app/controllers/spree/api/taxons_controller.rb +1 -1
- data/app/controllers/spree/api/variants_controller.rb +16 -19
- data/app/helpers/spree/api/api_helpers.rb +6 -1
- data/app/views/spree/api/errors/invalid_resource.v1.rabl +1 -1
- data/app/views/spree/api/orders/could_not_transition.v1.rabl +1 -1
- data/app/views/spree/api/orders/order.v1.rabl +1 -1
- data/app/views/spree/api/orders/show.v1.rabl +10 -4
- data/app/views/spree/api/shipments/small.v1.rabl +33 -0
- data/app/views/spree/api/taxonomies/show.v1.rabl +2 -2
- data/app/views/spree/api/users/show.v1.rabl +7 -0
- data/config/routes.rb +19 -28
- data/lib/spree/api/engine.rb +3 -3
- data/lib/spree/api/responders/rabl_template.rb +1 -1
- data/lib/spree/api/testing_support/helpers.rb +8 -3
- data/spec/controllers/spree/api/base_controller_spec.rb +15 -12
- data/spec/controllers/spree/api/checkouts_controller_spec.rb +78 -90
- data/spec/controllers/spree/api/line_items_controller_spec.rb +13 -9
- data/spec/controllers/spree/api/orders_controller_spec.rb +53 -31
- data/spec/controllers/spree/api/payments_controller_spec.rb +9 -8
- data/spec/controllers/spree/api/products_controller_spec.rb +1 -1
- data/spec/controllers/spree/api/promotion_application_spec.rb +5 -5
- data/spec/controllers/spree/api/shipments_controller_spec.rb +1 -11
- data/spec/controllers/spree/api/taxonomies_controller_spec.rb +2 -2
- data/spec/controllers/spree/api/users_controller_spec.rb +23 -23
- data/spec/controllers/spree/api/zones_controller_spec.rb +22 -0
- data/spec/requests/rabl_cache_spec.rb +2 -2
- data/spec/spec_helper.rb +0 -1
- data/spec/support/controller_hacks.rb +1 -1
- data/spree_api.gemspec +2 -2
- metadata +12 -15
- data/app/views/spree/api/orders/delivery.v1.rabl +0 -3
- data/lib/spree/api/version.rb +0 -5
- data/spec/requests/ransackable_attributes_spec.rb +0 -79
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9382ec4d33c38fa47416c8870483987c4091d5b
|
4
|
+
data.tar.gz: 1ebe36b2b47efa8dea70bb402595b9ac4cee46a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4f4adc24185720919817b204e649d5d295f86ddfd9368becaf875780c868676dfaa1c9d8a6a70714d906679922829a32cf80ea2fcf43ec32509fecd0b4fae00
|
7
|
+
data.tar.gz: d8265a70d2d7dd78ddaf0aa7c006e32d3ee2d393b5b6beb4f08cec387c291c45fcc49a44102da52c5cc601598a061b76e39ada2e6f0cec052b62e1717134f3b7
|
data/CHANGELOG.md
CHANGED
@@ -1 +1,43 @@
|
|
1
|
-
## Spree 2.
|
1
|
+
## Spree 2.3.0 (unreleased) ##
|
2
|
+
|
3
|
+
* Support existing credit card feature on checkout.
|
4
|
+
|
5
|
+
Checkouts_controller#update now uses the same Order::Checkout#update_from_params
|
6
|
+
from spree frontend which help us to remove a lot of duplicated logic. As a
|
7
|
+
result of that `payment_source` params must be sent now outsite the `order` key.
|
8
|
+
|
9
|
+
Before you'd send a request like this:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
api_put :update, :id => order.to_param, :order_token => order.guest_token,
|
13
|
+
:order => {
|
14
|
+
:payments_attributes => [{ :payment_method_id => @payment_method.id.to_s }],
|
15
|
+
:payment_source => { @payment_method.id.to_s => { name: "Spree" } }
|
16
|
+
}
|
17
|
+
```
|
18
|
+
|
19
|
+
Now it should look like this:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
api_put :update, :id => order.to_param, :order_token => order.guest_token,
|
23
|
+
:order => {
|
24
|
+
:payments_attributes => [{ :payment_method_id => @payment_method.id.to_s }]
|
25
|
+
},
|
26
|
+
:payment_source => {
|
27
|
+
@payment_method.id.to_s => { name: "Spree" }
|
28
|
+
}
|
29
|
+
```
|
30
|
+
|
31
|
+
Josh Hepworth and Washington
|
32
|
+
|
33
|
+
* api/orders/show now display credit cards as source under payment
|
34
|
+
|
35
|
+
Washington Luiz
|
36
|
+
|
37
|
+
* refactor the api to use a general importer in core gem.
|
38
|
+
|
39
|
+
Peter Berkenbosch
|
40
|
+
|
41
|
+
* Shipment manifests viewed within the context of an order no longer return variant info. The line items for the order already contains this information. #4498
|
42
|
+
|
43
|
+
* Ryan Bigg
|
@@ -5,6 +5,7 @@ module Spree
|
|
5
5
|
class BaseController < ActionController::Base
|
6
6
|
include Spree::Api::ControllerSetup
|
7
7
|
include Spree::Core::ControllerHelpers::SSL
|
8
|
+
include Spree::Core::ControllerHelpers::Store
|
8
9
|
include Spree::Core::ControllerHelpers::StrongParameters
|
9
10
|
|
10
11
|
attr_accessor :current_api_user
|
@@ -42,7 +43,7 @@ module Spree
|
|
42
43
|
# users should be able to set price when importing orders via api
|
43
44
|
def permitted_line_item_attributes
|
44
45
|
if current_api_user.has_spree_role?("admin")
|
45
|
-
super
|
46
|
+
super << [:price, :variant_id, :sku]
|
46
47
|
else
|
47
48
|
super
|
48
49
|
end
|
@@ -61,7 +62,7 @@ module Spree
|
|
61
62
|
end
|
62
63
|
|
63
64
|
def load_user
|
64
|
-
@current_api_user = Spree.user_class.find_by(spree_api_key: api_key.to_s)
|
65
|
+
@current_api_user = (try_spree_current_user || Spree.user_class.find_by(spree_api_key: api_key.to_s))
|
65
66
|
end
|
66
67
|
|
67
68
|
def authenticate_user
|
@@ -129,27 +130,22 @@ module Spree
|
|
129
130
|
end
|
130
131
|
|
131
132
|
def product_scope
|
133
|
+
variants_associations = [{ option_values: :option_type }, :default_price, :prices, :images]
|
132
134
|
if current_api_user.has_spree_role?("admin")
|
133
|
-
scope = Product.with_deleted.accessible_by(current_ability, :read)
|
135
|
+
scope = Product.with_deleted.accessible_by(current_ability, :read)
|
136
|
+
.includes(:properties, :option_types, variants: variants_associations, master: variants_associations)
|
134
137
|
|
135
138
|
unless params[:show_deleted]
|
136
139
|
scope = scope.not_deleted
|
137
140
|
end
|
138
141
|
else
|
139
|
-
scope = Product.accessible_by(current_ability, :read).active
|
142
|
+
scope = Product.accessible_by(current_ability, :read).active
|
143
|
+
.includes(:properties, :option_types, variants: variants_associations, master: variants_associations)
|
140
144
|
end
|
141
145
|
|
142
146
|
scope
|
143
147
|
end
|
144
148
|
|
145
|
-
def variants_associations
|
146
|
-
[{ option_values: :option_type }, :default_price, :images]
|
147
|
-
end
|
148
|
-
|
149
|
-
def product_includes
|
150
|
-
[ :option_types, variants: variants_associations, master: variants_associations ]
|
151
|
-
end
|
152
|
-
|
153
149
|
def order_id
|
154
150
|
params[:order_id] || params[:checkout_id] || params[:order_number]
|
155
151
|
end
|
@@ -8,12 +8,6 @@ module Spree
|
|
8
8
|
# This before_filter comes from Spree::Core::ControllerHelpers::Order
|
9
9
|
skip_before_filter :set_current_order
|
10
10
|
|
11
|
-
def create
|
12
|
-
authorize! :create, Order
|
13
|
-
@order = Spree::Core::Importer::Order.import(current_api_user, nested_params)
|
14
|
-
respond_with(@order, default_template: 'spree/api/orders/show', status: 201)
|
15
|
-
end
|
16
|
-
|
17
11
|
def next
|
18
12
|
load_order(true)
|
19
13
|
authorize! :update, @order, order_token
|
@@ -30,20 +24,15 @@ module Spree
|
|
30
24
|
respond_with(@order, default_template: 'spree/api/orders/show', status: 200)
|
31
25
|
end
|
32
26
|
|
33
|
-
def show
|
34
|
-
redirect_to(api_order_path(params[:id]), status: 301)
|
35
|
-
end
|
36
|
-
|
37
27
|
def update
|
38
28
|
load_order(true)
|
39
29
|
authorize! :update, @order, order_token
|
40
|
-
|
41
|
-
|
42
|
-
if @order.update_attributes(order_params)
|
43
|
-
@order.update_line_items(line_items)
|
30
|
+
|
31
|
+
if @order.update_from_params(params, permitted_checkout_attributes, request.headers.env)
|
44
32
|
if current_api_user.has_spree_role?('admin') && user_id.present?
|
45
33
|
@order.associate_user!(Spree.user_class.find(user_id))
|
46
34
|
end
|
35
|
+
|
47
36
|
return if after_update_attributes
|
48
37
|
state_callback(:after) if @order.next
|
49
38
|
respond_with(@order, default_template: 'spree/api/orders/show')
|
@@ -53,41 +42,10 @@ module Spree
|
|
53
42
|
end
|
54
43
|
|
55
44
|
private
|
56
|
-
def object_params
|
57
|
-
modify_payment_attributes params[:order] || {}
|
58
|
-
|
59
|
-
protected_params = if params[:order]
|
60
|
-
params.require(:order).permit(permitted_checkout_attributes)
|
61
|
-
else
|
62
|
-
{}
|
63
|
-
end
|
64
|
-
|
65
|
-
map_nested_attributes_keys Order, protected_params
|
66
|
-
end
|
67
|
-
|
68
45
|
def user_id
|
69
46
|
params[:order][:user_id] if params[:order]
|
70
47
|
end
|
71
48
|
|
72
|
-
# For payment step, filter order parameters to produce the expected
|
73
|
-
# nested attributes for a single payment and its source, discarding
|
74
|
-
# attributes for payment methods other than the one selected
|
75
|
-
#
|
76
|
-
# respond_to check is necessary due to issue described in #2910
|
77
|
-
def modify_payment_attributes(object_params)
|
78
|
-
if @order.has_checkout_step?('payment') && @order.payment?
|
79
|
-
if object_params[:payments_attributes].is_a?(Hash)
|
80
|
-
object_params[:payments_attributes] = [object_params[:payments_attributes]]
|
81
|
-
end
|
82
|
-
if object_params[:payment_source].present? && source_params = object_params.delete(:payment_source)[object_params[:payments_attributes].first[:payment_method_id].to_s]
|
83
|
-
object_params[:payments_attributes].first[:source_attributes] = source_params
|
84
|
-
end
|
85
|
-
if object_params[:payments_attributes]
|
86
|
-
object_params[:payments_attributes].first[:amount] = @order.total.to_s
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
49
|
def nested_params
|
92
50
|
map_nested_attributes_keys Order, params[:order] || {}
|
93
51
|
end
|
@@ -105,10 +63,6 @@ module Spree
|
|
105
63
|
state_callback(:before)
|
106
64
|
end
|
107
65
|
|
108
|
-
def ip_address
|
109
|
-
''
|
110
|
-
end
|
111
|
-
|
112
66
|
def raise_insufficient_quantity
|
113
67
|
respond_with(@order, default_template: 'spree/api/orders/insufficient_quantity')
|
114
68
|
end
|
@@ -118,16 +72,8 @@ module Spree
|
|
118
72
|
send(method_name) if respond_to?(method_name, true)
|
119
73
|
end
|
120
74
|
|
121
|
-
def next!(options={})
|
122
|
-
if @order.valid? && @order.next
|
123
|
-
render 'spree/api/orders/show', status: options[:status] || 200
|
124
|
-
else
|
125
|
-
render 'spree/api/orders/could_not_transition', status: 422
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
75
|
def after_update_attributes
|
130
|
-
if
|
76
|
+
if nested_params && nested_params[:coupon_code].present?
|
131
77
|
handler = PromotionHandler::Coupon.new(@order).apply
|
132
78
|
|
133
79
|
if handler.error.present?
|
@@ -1,11 +1,12 @@
|
|
1
1
|
module Spree
|
2
2
|
module Api
|
3
3
|
class LineItemsController < Spree::Api::BaseController
|
4
|
-
|
5
4
|
def create
|
6
5
|
variant = Spree::Variant.find(params[:line_item][:variant_id])
|
7
6
|
@line_item = order.contents.add(variant, params[:line_item][:quantity] || 1)
|
7
|
+
|
8
8
|
if @line_item.errors.empty?
|
9
|
+
@order.ensure_updated_shipments
|
9
10
|
respond_with(@line_item, status: 201, default_template: :show)
|
10
11
|
else
|
11
12
|
invalid_resource!(@line_item)
|
@@ -15,7 +16,6 @@ module Spree
|
|
15
16
|
def update
|
16
17
|
@line_item = find_line_item
|
17
18
|
if @order.contents.update_cart(line_items_attributes)
|
18
|
-
@order.ensure_updated_shipments
|
19
19
|
@line_item.reload
|
20
20
|
respond_with(@line_item, default_template: :show)
|
21
21
|
else
|
@@ -27,11 +27,11 @@ module Spree
|
|
27
27
|
@line_item = find_line_item
|
28
28
|
variant = Spree::Variant.find(@line_item.variant_id)
|
29
29
|
@order.contents.remove(variant, @line_item.quantity)
|
30
|
+
@order.ensure_updated_shipments
|
30
31
|
respond_with(@line_item, status: 204)
|
31
32
|
end
|
32
33
|
|
33
34
|
private
|
34
|
-
|
35
35
|
def order
|
36
36
|
@order ||= Spree::Order.includes(:line_items).find_by!(number: order_id)
|
37
37
|
authorize! :update, @order, order_token
|
@@ -3,9 +3,9 @@ module Spree
|
|
3
3
|
class OptionTypesController < Spree::Api::BaseController
|
4
4
|
def index
|
5
5
|
if params[:ids]
|
6
|
-
@option_types = Spree::OptionType.
|
6
|
+
@option_types = Spree::OptionType.accessible_by(current_ability, :read).where(:id => params[:ids].split(','))
|
7
7
|
else
|
8
|
-
@option_types = Spree::OptionType.
|
8
|
+
@option_types = Spree::OptionType.accessible_by(current_ability, :read).load.ransack(params[:q]).result
|
9
9
|
end
|
10
10
|
respond_with(@option_types)
|
11
11
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module Spree
|
2
2
|
module Api
|
3
3
|
class OrdersController < Spree::Api::BaseController
|
4
|
-
wrap_parameters false
|
5
|
-
|
6
4
|
skip_before_filter :check_for_user_or_api_key, only: :apply_coupon_code
|
7
5
|
skip_before_filter :authenticate_user, only: :apply_coupon_code
|
8
6
|
|
7
|
+
before_filter :find_order, except: [:create, :mine, :index, :update]
|
8
|
+
|
9
9
|
# Dynamically defines our stores checkout steps to ensure we check authorization on each step.
|
10
10
|
Order.checkout_steps.keys.each do |step|
|
11
11
|
define_method step do
|
@@ -15,10 +15,9 @@ module Spree
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def cancel
|
18
|
-
find_order
|
19
18
|
authorize! :update, @order, params[:token]
|
20
19
|
@order.cancel!
|
21
|
-
|
20
|
+
render :show
|
22
21
|
end
|
23
22
|
|
24
23
|
def create
|
@@ -28,10 +27,8 @@ module Spree
|
|
28
27
|
end
|
29
28
|
|
30
29
|
def empty
|
31
|
-
find_order
|
32
30
|
authorize! :update, @order, order_token
|
33
31
|
@order.empty!
|
34
|
-
@order.update!
|
35
32
|
render text: nil, status: 200
|
36
33
|
end
|
37
34
|
|
@@ -42,7 +39,6 @@ module Spree
|
|
42
39
|
end
|
43
40
|
|
44
41
|
def show
|
45
|
-
find_order
|
46
42
|
authorize! :show, @order, order_token
|
47
43
|
method = "before_#{@order.state}"
|
48
44
|
send(method) if respond_to?(method, true)
|
@@ -52,16 +48,12 @@ module Spree
|
|
52
48
|
def update
|
53
49
|
find_order(true)
|
54
50
|
authorize! :update, @order, order_token
|
55
|
-
# Parsing line items through as an update_attributes call in the API will result in
|
56
|
-
# many line items for the same variant_id being created. We must be smarter about this,
|
57
|
-
# hence the use of the update_line_items method, defined within order_decorator.rb.
|
58
|
-
order_params.delete("line_items_attributes")
|
59
|
-
if @order.update_attributes(order_params)
|
60
|
-
|
61
|
-
deal_with_line_items if params[:order][:line_items]
|
62
51
|
|
63
|
-
|
64
|
-
|
52
|
+
if @order.contents.update_cart(order_params)
|
53
|
+
user_id = params[:order][:user_id]
|
54
|
+
if current_api_user.has_spree_role?('admin') && user_id
|
55
|
+
@order.associate_user!(Spree.user_class.find(user_id))
|
56
|
+
end
|
65
57
|
respond_with(@order, default_template: :show)
|
66
58
|
else
|
67
59
|
invalid_resource!(@order)
|
@@ -70,7 +62,7 @@ module Spree
|
|
70
62
|
|
71
63
|
def mine
|
72
64
|
if current_api_user.persisted?
|
73
|
-
@orders = current_api_user.orders.
|
65
|
+
@orders = current_api_user.orders.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
74
66
|
else
|
75
67
|
render "spree/api/errors/unauthorized", status: :unauthorized
|
76
68
|
end
|
@@ -86,15 +78,6 @@ module Spree
|
|
86
78
|
end
|
87
79
|
|
88
80
|
private
|
89
|
-
def deal_with_line_items
|
90
|
-
line_item_attributes = params[:order][:line_items]
|
91
|
-
line_item_attributes.each_key do |key|
|
92
|
-
# need to call .to_hash to make sure Rails 4's strong parameters don't bite
|
93
|
-
line_item_attributes[key] = line_item_attributes[key].slice(*permitted_line_item_attributes).to_hash
|
94
|
-
end
|
95
|
-
@order.update_line_items(line_item_attributes)
|
96
|
-
end
|
97
|
-
|
98
81
|
def order_params
|
99
82
|
if params[:order]
|
100
83
|
params[:order][:payments_attributes] = params[:order][:payments] if params[:order][:payments]
|
@@ -111,7 +94,7 @@ module Spree
|
|
111
94
|
|
112
95
|
def permitted_order_attributes
|
113
96
|
if current_api_user.has_spree_role? "admin"
|
114
|
-
super
|
97
|
+
super << admin_order_attributes
|
115
98
|
else
|
116
99
|
super
|
117
100
|
end
|
@@ -119,7 +102,7 @@ module Spree
|
|
119
102
|
|
120
103
|
def permitted_shipment_attributes
|
121
104
|
if current_api_user.has_spree_role? "admin"
|
122
|
-
super
|
105
|
+
super << admin_shipment_attributes
|
123
106
|
else
|
124
107
|
super
|
125
108
|
end
|
@@ -133,14 +116,6 @@ module Spree
|
|
133
116
|
[:import, :number, :completed_at, :locked_at, :channel]
|
134
117
|
end
|
135
118
|
|
136
|
-
def next!(options={})
|
137
|
-
if @order.valid? && @order.next
|
138
|
-
render :show, status: options[:status] || 200
|
139
|
-
else
|
140
|
-
render :could_not_transition, status: 422
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
119
|
def find_order(lock = false)
|
145
120
|
@order = Spree::Order.lock(lock).find_by!(number: params[:id])
|
146
121
|
end
|
@@ -11,7 +11,7 @@ module Spree
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def new
|
14
|
-
@payment_methods = Spree::PaymentMethod.
|
14
|
+
@payment_methods = Spree::PaymentMethod.where(environment: Rails.env)
|
15
15
|
respond_with(@payment_method)
|
16
16
|
end
|
17
17
|
|
@@ -67,7 +67,7 @@ module Spree
|
|
67
67
|
|
68
68
|
def find_order
|
69
69
|
@order = Spree::Order.find_by(number: order_id)
|
70
|
-
authorize! :read, @order
|
70
|
+
authorize! :read, @order
|
71
71
|
end
|
72
72
|
|
73
73
|
def find_payment
|
@@ -12,7 +12,6 @@ module Spree
|
|
12
12
|
@products = @products.distinct.page(params[:page]).per(params[:per_page])
|
13
13
|
expires_in 15.minutes, :public => true
|
14
14
|
headers['Surrogate-Control'] = "max-age=#{15.minutes}"
|
15
|
-
respond_with(@products)
|
16
15
|
end
|
17
16
|
|
18
17
|
def show
|
@@ -20,7 +19,6 @@ module Spree
|
|
20
19
|
expires_in 15.minutes, :public => true
|
21
20
|
headers['Surrogate-Control'] = "max-age=#{15.minutes}"
|
22
21
|
headers['Surrogate-Key'] = "product_id=1"
|
23
|
-
respond_with(@product)
|
24
22
|
end
|
25
23
|
|
26
24
|
# Takes besides the products attributes either an array of variants or
|
@@ -61,22 +59,10 @@ module Spree
|
|
61
59
|
params[:product][:available_on] ||= Time.now
|
62
60
|
set_up_shipping_category
|
63
61
|
|
64
|
-
|
65
|
-
|
66
|
-
variants_params.each do |variant_attribute|
|
67
|
-
# make sure the product is assigned before the options=
|
68
|
-
@product.variants.create({ product: @product }.merge(variant_attribute))
|
69
|
-
end
|
70
|
-
|
71
|
-
option_types_params.each do |name|
|
72
|
-
option_type = OptionType.where(name: name).first_or_initialize do |option_type|
|
73
|
-
option_type.presentation = name
|
74
|
-
option_type.save!
|
75
|
-
end
|
76
|
-
|
77
|
-
@product.option_types << option_type unless @product.option_types.include?(option_type)
|
78
|
-
end
|
62
|
+
options = { variants_attrs: variants_params, options_attrs: option_types_params }
|
63
|
+
@product = Core::Importer::Product.new(nil, product_params, options).create
|
79
64
|
|
65
|
+
if @product.persisted?
|
80
66
|
respond_with(@product, :status => 201, :default_template => :show)
|
81
67
|
else
|
82
68
|
invalid_resource!(@product)
|
@@ -87,26 +73,10 @@ module Spree
|
|
87
73
|
@product = find_product(params[:id])
|
88
74
|
authorize! :update, @product
|
89
75
|
|
90
|
-
|
91
|
-
|
92
|
-
# update the variant if the id is present in the payload
|
93
|
-
if variant_attribute['id'].present?
|
94
|
-
@product.variants.find(variant_attribute['id'].to_i).update_attributes(variant_attribute)
|
95
|
-
else
|
96
|
-
# make sure the product is assigned before the options=
|
97
|
-
@product.variants.create({ product: @product }.merge(variant_attribute))
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
option_types_params.each do |name|
|
102
|
-
option_type = OptionType.where(name: name).first_or_initialize do |option_type|
|
103
|
-
option_type.presentation = name
|
104
|
-
option_type.save!
|
105
|
-
end
|
106
|
-
|
107
|
-
@product.option_types << option_type unless @product.option_types.include?(option_type)
|
108
|
-
end
|
76
|
+
options = { variants_attrs: variants_params, options_attrs: option_types_params }
|
77
|
+
@product = Core::Importer::Product.new(@product, product_params, options).update
|
109
78
|
|
79
|
+
if @product.errors.empty?
|
110
80
|
respond_with(@product.reload, :status => 200, :default_template => :show)
|
111
81
|
else
|
112
82
|
invalid_resource!(@product)
|
@@ -2,34 +2,27 @@ module Spree
|
|
2
2
|
module Api
|
3
3
|
class ShipmentsController < Spree::Api::BaseController
|
4
4
|
|
5
|
-
before_filter :find_order
|
6
5
|
before_filter :find_and_update_shipment, only: [:ship, :ready, :add, :remove]
|
7
6
|
|
8
7
|
def create
|
9
|
-
|
10
|
-
|
11
|
-
@order = Spree::Order.find_by!(number: params[:shipment][:order_id])
|
12
|
-
authorize! :read, @order
|
13
|
-
end
|
8
|
+
@order = Spree::Order.find_by!(number: params[:shipment][:order_id])
|
9
|
+
authorize! :read, @order
|
14
10
|
authorize! :create, Shipment
|
15
11
|
variant = Spree::Variant.find(params[:variant_id])
|
16
12
|
quantity = params[:quantity].to_i
|
17
13
|
@shipment = @order.shipments.create(stock_location_id: params[:stock_location_id])
|
18
14
|
@order.contents.add(variant, quantity, nil, @shipment)
|
19
15
|
|
16
|
+
@shipment.refresh_rates
|
20
17
|
@shipment.save!
|
21
18
|
|
22
19
|
respond_with(@shipment.reload, default_template: :show)
|
23
20
|
end
|
24
21
|
|
25
22
|
def update
|
26
|
-
|
27
|
-
@shipment = @order.shipments.accessible_by(current_ability, :update).find_by!(number: params[:id])
|
28
|
-
else
|
29
|
-
@shipment = Spree::Shipment.accessible_by(current_ability, :update).readonly(false).find_by!(number: params[:id])
|
30
|
-
end
|
31
|
-
|
23
|
+
@shipment = Spree::Shipment.accessible_by(current_ability, :update).readonly(false).find_by!(number: params[:id])
|
32
24
|
@shipment.update_attributes_and_order(shipment_params)
|
25
|
+
|
33
26
|
respond_with(@shipment.reload, default_template: :show)
|
34
27
|
end
|
35
28
|
|
@@ -71,20 +64,8 @@ module Spree
|
|
71
64
|
|
72
65
|
private
|
73
66
|
|
74
|
-
def find_order
|
75
|
-
if params[:order_id].present?
|
76
|
-
ActiveSupport::Deprecation.warn "Spree::Api::ShipmentsController#find_order is deprecated and will be removed from Spree 2.3.x, access shipments directly without being nested to orders route instead.", caller
|
77
|
-
@order = Spree::Order.find_by!(number: params[:order_id])
|
78
|
-
authorize! :read, @order
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
67
|
def find_and_update_shipment
|
83
|
-
|
84
|
-
@shipment = @order.shipments.accessible_by(current_ability, :update).find_by!(number: params[:id])
|
85
|
-
else
|
86
|
-
@shipment = Spree::Shipment.accessible_by(current_ability, :update).readonly(false).find_by!(number: params[:id])
|
87
|
-
end
|
68
|
+
@shipment = Spree::Shipment.accessible_by(current_ability, :update).readonly(false).find_by!(number: params[:id])
|
88
69
|
@shipment.update_attributes(shipment_params)
|
89
70
|
@shipment.reload
|
90
71
|
end
|
@@ -3,15 +3,11 @@ module Spree
|
|
3
3
|
class TaxonomiesController < Spree::Api::BaseController
|
4
4
|
|
5
5
|
def index
|
6
|
-
|
7
|
-
ransack(params[:q]).result.
|
8
|
-
page(params[:page]).per(params[:per_page])
|
9
|
-
respond_with(@taxonomies)
|
6
|
+
respond_with(taxonomies)
|
10
7
|
end
|
11
8
|
|
12
9
|
def show
|
13
|
-
|
14
|
-
respond_with(@taxonomy)
|
10
|
+
respond_with(taxonomy)
|
15
11
|
end
|
16
12
|
|
17
13
|
# Because JSTree wants parameters in a *slightly* different format
|
@@ -46,6 +42,12 @@ module Spree
|
|
46
42
|
|
47
43
|
private
|
48
44
|
|
45
|
+
def taxonomies
|
46
|
+
@taxonomies = Taxonomy.accessible_by(current_ability, :read).order('name').includes(:root => :children).
|
47
|
+
ransack(params[:q]).result.
|
48
|
+
page(params[:page]).per(params[:per_page])
|
49
|
+
end
|
50
|
+
|
49
51
|
def taxonomy
|
50
52
|
@taxonomy ||= Taxonomy.accessible_by(current_ability, :read).find(params[:id])
|
51
53
|
end
|
@@ -65,7 +65,7 @@ module Spree
|
|
65
65
|
# Products#index does not do the sorting.
|
66
66
|
taxon = Spree::Taxon.find(params[:id])
|
67
67
|
@products = taxon.products.ransack(params[:q]).result
|
68
|
-
@products = @products.page(params[:page]).per(params[:per_page]
|
68
|
+
@products = @products.page(params[:page]).per(500 || params[:per_page])
|
69
69
|
render "spree/api/products/index"
|
70
70
|
end
|
71
71
|
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module Spree
|
2
2
|
module Api
|
3
3
|
class VariantsController < Spree::Api::BaseController
|
4
|
-
|
5
4
|
before_filter :product
|
6
5
|
|
7
6
|
def create
|
@@ -20,9 +19,13 @@ module Spree
|
|
20
19
|
respond_with(@variant, status: 204)
|
21
20
|
end
|
22
21
|
|
22
|
+
# The lazyloaded associations here are pretty much attached to which nodes
|
23
|
+
# we render on the view so we better update it any time a node is included
|
24
|
+
# or removed from the views.
|
23
25
|
def index
|
24
|
-
@variants = scope.includes(
|
25
|
-
page(params[:page]).per(params[:per_page])
|
26
|
+
@variants = scope.includes({ option_values: :option_type }, :product, :default_price, :images, { stock_items: :stock_location })
|
27
|
+
.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
28
|
+
|
26
29
|
respond_with(@variants)
|
27
30
|
end
|
28
31
|
|
@@ -30,7 +33,8 @@ module Spree
|
|
30
33
|
end
|
31
34
|
|
32
35
|
def show
|
33
|
-
@variant = scope.includes(:option_values
|
36
|
+
@variant = scope.includes({ option_values: :option_type }, :option_values, :product, :default_price, :images, { stock_items: :stock_location })
|
37
|
+
.find(params[:id])
|
34
38
|
respond_with(@variant)
|
35
39
|
end
|
36
40
|
|
@@ -44,29 +48,22 @@ module Spree
|
|
44
48
|
end
|
45
49
|
|
46
50
|
private
|
47
|
-
|
48
51
|
def product
|
49
52
|
@product ||= Spree::Product.accessible_by(current_ability, :read).friendly.find(params[:product_id]) if params[:product_id]
|
50
53
|
end
|
51
54
|
|
52
55
|
def scope
|
53
56
|
if @product
|
54
|
-
|
55
|
-
variants = @product.variants_including_master.accessible_by(current_ability, :read)
|
56
|
-
else
|
57
|
-
variants = @product.variants_including_master.with_deleted.accessible_by(current_ability, :read)
|
58
|
-
end
|
57
|
+
variants = @product.variants_including_master
|
59
58
|
else
|
60
|
-
variants = Variant
|
61
|
-
if current_api_user.has_spree_role?('admin')
|
62
|
-
unless params[:show_deleted]
|
63
|
-
variants = Variant.accessible_by(current_ability, :read).active
|
64
|
-
end
|
65
|
-
else
|
66
|
-
variants = variants.active
|
67
|
-
end
|
59
|
+
variants = Variant
|
68
60
|
end
|
69
|
-
|
61
|
+
|
62
|
+
if current_ability.can?(:manage, Variant) && params[:show_deleted]
|
63
|
+
variants = variants.with_deleted
|
64
|
+
end
|
65
|
+
|
66
|
+
variants.accessible_by(current_ability, :read)
|
70
67
|
end
|
71
68
|
|
72
69
|
def variant_params
|