spree_api 3.0.10 → 3.1.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/spree/api/base_controller.rb +21 -22
- data/app/controllers/spree/api/v1/addresses_controller.rb +46 -0
- data/app/controllers/spree/api/v1/checkouts_controller.rb +103 -0
- data/app/controllers/spree/api/v1/classifications_controller.rb +20 -0
- data/app/controllers/spree/api/v1/countries_controller.rb +24 -0
- data/app/controllers/spree/api/v1/credit_cards_controller.rb +27 -0
- data/app/controllers/spree/api/v1/images_controller.rb +56 -0
- data/app/controllers/spree/api/v1/inventory_units_controller.rb +54 -0
- data/app/controllers/spree/api/v1/line_items_controller.rb +70 -0
- data/app/controllers/spree/api/v1/option_types_controller.rb +51 -0
- data/app/controllers/spree/api/v1/option_values_controller.rb +60 -0
- data/app/controllers/spree/api/v1/orders_controller.rb +137 -0
- data/app/controllers/spree/api/v1/payments_controller.rb +82 -0
- data/app/controllers/spree/api/v1/product_properties_controller.rb +73 -0
- data/app/controllers/spree/api/v1/products_controller.rb +126 -0
- data/app/controllers/spree/api/v1/promotions_controller.rb +28 -0
- data/app/controllers/spree/api/v1/properties_controller.rb +72 -0
- data/app/controllers/spree/api/v1/return_authorizations_controller.rb +71 -0
- data/app/controllers/spree/api/v1/shipments_controller.rb +163 -0
- data/app/controllers/spree/api/v1/states_controller.rb +37 -0
- data/app/controllers/spree/api/v1/stock_items_controller.rb +77 -0
- data/app/controllers/spree/api/v1/stock_locations_controller.rb +52 -0
- data/app/controllers/spree/api/v1/stock_movements_controller.rb +45 -0
- data/app/controllers/spree/api/v1/stores_controller.rb +57 -0
- data/app/controllers/spree/api/v1/taxonomies_controller.rb +66 -0
- data/app/controllers/spree/api/v1/taxons_controller.rb +95 -0
- data/app/controllers/spree/api/v1/users_controller.rb +60 -0
- data/app/controllers/spree/api/v1/variants_controller.rb +75 -0
- data/app/controllers/spree/api/v1/zones_controller.rb +51 -0
- data/app/helpers/spree/api/api_helpers.rb +3 -2
- data/app/views/spree/api/{addresses → v1/addresses}/show.v1.rabl +0 -0
- data/app/views/spree/api/{adjustments → v1/adjustments}/show.v1.rabl +0 -0
- data/app/views/spree/api/{config → v1/config}/money.v1.rabl +0 -0
- data/app/views/spree/api/{config → v1/config}/show.v1.rabl +0 -0
- data/app/views/spree/api/{countries → v1/countries}/index.v1.rabl +0 -0
- data/app/views/spree/api/{countries → v1/countries}/show.v1.rabl +0 -0
- data/app/views/spree/api/{credit_cards → v1/credit_cards}/index.v1.rabl +1 -1
- data/app/views/spree/api/{credit_cards → v1/credit_cards}/show.v1.rabl +0 -0
- data/app/views/spree/api/{images → v1/images}/index.v1.rabl +1 -1
- data/app/views/spree/api/v1/images/new.v1.rabl +3 -0
- data/app/views/spree/api/{images → v1/images}/show.v1.rabl +0 -0
- data/app/views/spree/api/{inventory_units → v1/inventory_units}/show.rabl +0 -0
- data/app/views/spree/api/{line_items → v1/line_items}/new.v1.rabl +0 -0
- data/app/views/spree/api/{line_items → v1/line_items}/show.v1.rabl +3 -3
- data/app/views/spree/api/v1/option_types/index.v1.rabl +3 -0
- data/app/views/spree/api/v1/option_types/new.v1.rabl +3 -0
- data/app/views/spree/api/{option_types → v1/option_types}/show.v1.rabl +0 -0
- data/app/views/spree/api/v1/option_values/index.v1.rabl +3 -0
- data/app/views/spree/api/v1/option_values/new.v1.rabl +3 -0
- data/app/views/spree/api/{option_values → v1/option_values}/show.v1.rabl +0 -0
- data/app/views/spree/api/{orders → v1/orders}/address.v1.rabl +0 -0
- data/app/views/spree/api/{orders → v1/orders}/canceled.v1.rabl +0 -0
- data/app/views/spree/api/{orders → v1/orders}/cart.v1.rabl +0 -0
- data/app/views/spree/api/{orders → v1/orders}/complete.v1.rabl +0 -0
- data/app/views/spree/api/{orders → v1/orders}/could_not_apply_coupon.v1.rabl +0 -0
- data/app/views/spree/api/{orders → v1/orders}/could_not_transition.v1.rabl +0 -0
- data/app/views/spree/api/{orders → v1/orders}/index.v1.rabl +1 -1
- data/app/views/spree/api/{orders → v1/orders}/invalid_shipping_method.v1.rabl +0 -0
- data/app/views/spree/api/{orders → v1/orders}/mine.v1.rabl +1 -1
- data/app/views/spree/api/{orders → v1/orders}/order.v1.rabl +1 -0
- data/app/views/spree/api/{orders → v1/orders}/payment.v1.rabl +0 -0
- data/app/views/spree/api/{orders → v1/orders}/show.v1.rabl +9 -9
- data/app/views/spree/api/{payments → v1/payments}/credit_over_limit.v1.rabl +0 -0
- data/app/views/spree/api/{payments → v1/payments}/index.v1.rabl +0 -0
- data/app/views/spree/api/{payments → v1/payments}/new.v1.rabl +0 -0
- data/app/views/spree/api/{payments → v1/payments}/show.v1.rabl +0 -0
- data/app/views/spree/api/{payments → v1/payments}/update_forbidden.v1.rabl +0 -0
- data/app/views/spree/api/{product_properties → v1/product_properties}/index.v1.rabl +0 -0
- data/app/views/spree/api/{product_properties → v1/product_properties}/new.v1.rabl +0 -0
- data/app/views/spree/api/{product_properties → v1/product_properties}/show.v1.rabl +0 -0
- data/app/views/spree/api/{products → v1/products}/index.v1.rabl +1 -1
- data/app/views/spree/api/{products → v1/products}/new.v1.rabl +0 -0
- data/app/views/spree/api/{products → v1/products}/product.v1.rabl +0 -0
- data/app/views/spree/api/{products → v1/products}/show.v1.rabl +3 -3
- data/app/views/spree/api/{promotions → v1/promotions}/handler.v1.rabl +0 -0
- data/app/views/spree/api/{promotions → v1/promotions}/show.v1.rabl +0 -0
- data/app/views/spree/api/{properties → v1/properties}/index.v1.rabl +0 -0
- data/app/views/spree/api/{properties → v1/properties}/new.v1.rabl +0 -0
- data/app/views/spree/api/{properties → v1/properties}/show.v1.rabl +0 -0
- data/app/views/spree/api/{return_authorizations → v1/return_authorizations}/index.v1.rabl +0 -0
- data/app/views/spree/api/{return_authorizations → v1/return_authorizations}/new.v1.rabl +0 -0
- data/app/views/spree/api/{return_authorizations → v1/return_authorizations}/show.v1.rabl +0 -0
- data/app/views/spree/api/{shared → v1/shared}/stock_location_required.v1.rabl +0 -0
- data/app/views/spree/api/{shipments → v1/shipments}/big.v1.rabl +7 -7
- data/app/views/spree/api/{shipments → v1/shipments}/cannot_ready_shipment.v1.rabl +0 -0
- data/app/views/spree/api/{shipments → v1/shipments}/mine.v1.rabl +1 -1
- data/app/views/spree/api/{shipments → v1/shipments}/show.v1.rabl +3 -3
- data/app/views/spree/api/{shipments → v1/shipments}/small.v1.rabl +3 -3
- data/app/views/spree/api/{shipping_rates → v1/shipping_rates}/show.v1.rabl +0 -0
- data/app/views/spree/api/{states → v1/states}/index.v1.rabl +0 -0
- data/app/views/spree/api/{states → v1/states}/show.v1.rabl +0 -0
- data/app/views/spree/api/{stock_items → v1/stock_items}/index.v1.rabl +1 -1
- data/app/views/spree/api/{stock_items → v1/stock_items}/show.v1.rabl +1 -1
- data/app/views/spree/api/{stock_locations → v1/stock_locations}/index.v1.rabl +1 -1
- data/app/views/spree/api/{stock_locations → v1/stock_locations}/show.v1.rabl +0 -0
- data/app/views/spree/api/{stock_movements → v1/stock_movements}/index.v1.rabl +1 -1
- data/app/views/spree/api/{stock_movements → v1/stock_movements}/show.v1.rabl +1 -1
- data/app/views/spree/api/{stores → v1/stores}/index.v1.rabl +0 -0
- data/app/views/spree/api/{stores → v1/stores}/show.v1.rabl +0 -0
- data/app/views/spree/api/{taxonomies → v1/taxonomies}/index.v1.rabl +1 -1
- data/app/views/spree/api/{taxonomies → v1/taxonomies}/jstree.rabl +0 -0
- data/app/views/spree/api/{taxonomies → v1/taxonomies}/nested.v1.rabl +1 -1
- data/app/views/spree/api/{taxonomies → v1/taxonomies}/new.v1.rabl +0 -0
- data/app/views/spree/api/{taxonomies → v1/taxonomies}/show.v1.rabl +4 -4
- data/app/views/spree/api/{taxons → v1/taxons}/index.v1.rabl +1 -1
- data/app/views/spree/api/{taxons → v1/taxons}/jstree.rabl +0 -0
- data/app/views/spree/api/{taxons → v1/taxons}/new.v1.rabl +0 -0
- data/app/views/spree/api/{taxons → v1/taxons}/show.v1.rabl +0 -0
- data/app/views/spree/api/v1/taxons/taxons.v1.rabl +5 -0
- data/app/views/spree/api/{users → v1/users}/index.v1.rabl +1 -1
- data/app/views/spree/api/{users → v1/users}/new.v1.rabl +0 -0
- data/app/views/spree/api/{users → v1/users}/show.v1.rabl +2 -2
- data/app/views/spree/api/{variants → v1/variants}/big.v1.rabl +1 -1
- data/app/views/spree/api/{variants → v1/variants}/index.v1.rabl +1 -1
- data/app/views/spree/api/{variants → v1/variants}/new.v1.rabl +0 -0
- data/app/views/spree/api/{variants → v1/variants}/show.v1.rabl +1 -1
- data/app/views/spree/api/{variants → v1/variants}/small.v1.rabl +1 -1
- data/app/views/spree/api/{zones → v1/zones}/index.v1.rabl +1 -1
- data/app/views/spree/api/{zones → v1/zones}/show.v1.rabl +0 -0
- data/config/routes.rb +85 -88
- data/spec/controllers/spree/api/base_controller_spec.rb +14 -42
- data/spec/controllers/spree/api/{addresses_controller_spec.rb → v1/addresses_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{checkouts_controller_spec.rb → v1/checkouts_controller_spec.rb} +51 -3
- data/spec/controllers/spree/api/{classifications_controller_spec.rb → v1/classifications_controller_spec.rb} +2 -2
- data/spec/controllers/spree/api/{countries_controller_spec.rb → v1/countries_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{credit_cards_controller_spec.rb → v1/credit_cards_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{images_controller_spec.rb → v1/images_controller_spec.rb} +23 -1
- data/spec/controllers/spree/api/{inventory_units_controller_spec.rb → v1/inventory_units_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{line_items_controller_spec.rb → v1/line_items_controller_spec.rb} +2 -2
- data/spec/controllers/spree/api/{option_types_controller_spec.rb → v1/option_types_controller_spec.rb} +9 -3
- data/spec/controllers/spree/api/{option_values_controller_spec.rb → v1/option_values_controller_spec.rb} +8 -2
- data/spec/controllers/spree/api/{orders_controller_spec.rb → v1/orders_controller_spec.rb} +29 -8
- data/spec/controllers/spree/api/{payments_controller_spec.rb → v1/payments_controller_spec.rb} +2 -2
- data/spec/controllers/spree/api/{product_properties_controller_spec.rb → v1/product_properties_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{products_controller_spec.rb → v1/products_controller_spec.rb} +5 -5
- data/spec/controllers/spree/api/{promotion_application_spec.rb → v1/promotion_application_spec.rb} +2 -2
- data/spec/controllers/spree/api/{promotions_controller_spec.rb → v1/promotions_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{properties_controller_spec.rb → v1/properties_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{return_authorizations_controller_spec.rb → v1/return_authorizations_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{shipments_controller_spec.rb → v1/shipments_controller_spec.rb} +4 -4
- data/spec/controllers/spree/api/{states_controller_spec.rb → v1/states_controller_spec.rb} +14 -10
- data/spec/controllers/spree/api/{stock_items_controller_spec.rb → v1/stock_items_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{stock_locations_controller_spec.rb → v1/stock_locations_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{stock_movements_controller_spec.rb → v1/stock_movements_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{stores_controller_spec.rb → v1/stores_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{taxonomies_controller_spec.rb → v1/taxonomies_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{taxons_controller_spec.rb → v1/taxons_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{unauthenticated_products_controller_spec.rb → v1/unauthenticated_products_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{users_controller_spec.rb → v1/users_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{variants_controller_spec.rb → v1/variants_controller_spec.rb} +3 -3
- data/spec/controllers/spree/api/{zones_controller_spec.rb → v1/zones_controller_spec.rb} +7 -5
- data/spec/requests/rabl_cache_spec.rb +2 -2
- data/spec/requests/ransackable_attributes_spec.rb +6 -6
- data/spec/requests/version_spec.rb +19 -0
- data/spree_api.gemspec +1 -1
- metadata +188 -185
- data/CHANGELOG.md +0 -3
- data/app/controllers/spree/api/addresses_controller.rb +0 -43
- data/app/controllers/spree/api/checkouts_controller.rb +0 -98
- data/app/controllers/spree/api/classifications_controller.rb +0 -18
- data/app/controllers/spree/api/countries_controller.rb +0 -23
- data/app/controllers/spree/api/credit_cards_controller.rb +0 -25
- data/app/controllers/spree/api/images_controller.rb +0 -47
- data/app/controllers/spree/api/inventory_units_controller.rb +0 -52
- data/app/controllers/spree/api/line_items_controller.rb +0 -69
- data/app/controllers/spree/api/option_types_controller.rb +0 -49
- data/app/controllers/spree/api/option_values_controller.rb +0 -58
- data/app/controllers/spree/api/orders_controller.rb +0 -130
- data/app/controllers/spree/api/payments_controller.rb +0 -80
- data/app/controllers/spree/api/product_properties_controller.rb +0 -72
- data/app/controllers/spree/api/products_controller.rb +0 -124
- data/app/controllers/spree/api/promotions_controller.rb +0 -26
- data/app/controllers/spree/api/properties_controller.rb +0 -70
- data/app/controllers/spree/api/return_authorizations_controller.rb +0 -69
- data/app/controllers/spree/api/shipments_controller.rb +0 -149
- data/app/controllers/spree/api/states_controller.rb +0 -38
- data/app/controllers/spree/api/stock_items_controller.rb +0 -75
- data/app/controllers/spree/api/stock_locations_controller.rb +0 -50
- data/app/controllers/spree/api/stock_movements_controller.rb +0 -43
- data/app/controllers/spree/api/stores_controller.rb +0 -55
- data/app/controllers/spree/api/taxonomies_controller.rb +0 -64
- data/app/controllers/spree/api/taxons_controller.rb +0 -93
- data/app/controllers/spree/api/users_controller.rb +0 -56
- data/app/controllers/spree/api/variants_controller.rb +0 -73
- data/app/controllers/spree/api/zones_controller.rb +0 -49
- data/app/models/spree/option_value_decorator.rb +0 -9
- data/app/views/spree/api/option_types/index.v1.rabl +0 -3
- data/app/views/spree/api/option_values/index.v1.rabl +0 -3
- data/app/views/spree/api/taxons/taxons.v1.rabl +0 -5
data/CHANGELOG.md
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
module Spree
|
2
|
-
module Api
|
3
|
-
class AddressesController < Spree::Api::BaseController
|
4
|
-
before_action :find_order
|
5
|
-
|
6
|
-
def show
|
7
|
-
authorize! :read, @order, order_token
|
8
|
-
find_address
|
9
|
-
respond_with(@address)
|
10
|
-
end
|
11
|
-
|
12
|
-
def update
|
13
|
-
authorize! :update, @order, order_token
|
14
|
-
find_address
|
15
|
-
|
16
|
-
if @address.update_attributes(address_params)
|
17
|
-
respond_with(@address, :default_template => :show)
|
18
|
-
else
|
19
|
-
invalid_resource!(@address)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
def address_params
|
25
|
-
params.require(:address).permit(permitted_address_attributes)
|
26
|
-
end
|
27
|
-
|
28
|
-
def find_order
|
29
|
-
@order = Spree::Order.find_by!(number: order_id)
|
30
|
-
end
|
31
|
-
|
32
|
-
def find_address
|
33
|
-
@address = if @order.bill_address_id == params[:id].to_i
|
34
|
-
@order.bill_address
|
35
|
-
elsif @order.ship_address_id == params[:id].to_i
|
36
|
-
@order.ship_address
|
37
|
-
else
|
38
|
-
raise CanCan::AccessDenied
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,98 +0,0 @@
|
|
1
|
-
module Spree
|
2
|
-
module Api
|
3
|
-
class CheckoutsController < Spree::Api::BaseController
|
4
|
-
before_action :associate_user, only: :update
|
5
|
-
|
6
|
-
include Spree::Core::ControllerHelpers::Auth
|
7
|
-
include Spree::Core::ControllerHelpers::Order
|
8
|
-
# This before_action comes from Spree::Core::ControllerHelpers::Order
|
9
|
-
skip_before_action :set_current_order
|
10
|
-
|
11
|
-
def next
|
12
|
-
load_order(true)
|
13
|
-
authorize! :update, @order, order_token
|
14
|
-
@order.next!
|
15
|
-
respond_with(@order, default_template: 'spree/api/orders/show', status: 200)
|
16
|
-
rescue StateMachines::InvalidTransition
|
17
|
-
respond_with(@order, default_template: 'spree/api/orders/could_not_transition', status: 422)
|
18
|
-
end
|
19
|
-
|
20
|
-
def advance
|
21
|
-
load_order(true)
|
22
|
-
authorize! :update, @order, order_token
|
23
|
-
while @order.next; end
|
24
|
-
respond_with(@order, default_template: 'spree/api/orders/show', status: 200)
|
25
|
-
end
|
26
|
-
|
27
|
-
def update
|
28
|
-
load_order(true)
|
29
|
-
authorize! :update, @order, order_token
|
30
|
-
|
31
|
-
if @order.update_from_params(params, permitted_checkout_attributes, request.headers.env)
|
32
|
-
if current_api_user.has_spree_role?('admin') && user_id.present?
|
33
|
-
@order.associate_user!(Spree.user_class.find(user_id))
|
34
|
-
end
|
35
|
-
|
36
|
-
return if after_update_attributes
|
37
|
-
|
38
|
-
if @order.completed? || @order.next
|
39
|
-
state_callback(:after)
|
40
|
-
respond_with(@order, default_template: 'spree/api/orders/show')
|
41
|
-
else
|
42
|
-
respond_with(@order, default_template: 'spree/api/orders/could_not_transition', status: 422)
|
43
|
-
end
|
44
|
-
else
|
45
|
-
invalid_resource!(@order)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
private
|
50
|
-
def user_id
|
51
|
-
params[:order][:user_id] if params[:order]
|
52
|
-
end
|
53
|
-
|
54
|
-
def nested_params
|
55
|
-
map_nested_attributes_keys Spree::Order, params[:order] || {}
|
56
|
-
end
|
57
|
-
|
58
|
-
# Should be overriden if you have areas of your checkout that don't match
|
59
|
-
# up to a step within checkout_steps, such as a registration step
|
60
|
-
def skip_state_validation?
|
61
|
-
false
|
62
|
-
end
|
63
|
-
|
64
|
-
def load_order(lock = false)
|
65
|
-
@order = Spree::Order.lock(lock).find_by!(number: params[:id])
|
66
|
-
raise_insufficient_quantity and return if @order.insufficient_stock_lines.present?
|
67
|
-
@order.state = params[:state] if params[:state]
|
68
|
-
state_callback(:before)
|
69
|
-
end
|
70
|
-
|
71
|
-
def raise_insufficient_quantity
|
72
|
-
respond_with(@order, default_template: 'spree/api/orders/insufficient_quantity')
|
73
|
-
end
|
74
|
-
|
75
|
-
def state_callback(before_or_after = :before)
|
76
|
-
method_name = :"#{before_or_after}_#{@order.state}"
|
77
|
-
send(method_name) if respond_to?(method_name, true)
|
78
|
-
end
|
79
|
-
|
80
|
-
def after_update_attributes
|
81
|
-
if nested_params && nested_params[:coupon_code].present?
|
82
|
-
handler = Spree::PromotionHandler::Coupon.new(@order).apply
|
83
|
-
|
84
|
-
if handler.error.present?
|
85
|
-
@coupon_message = handler.error
|
86
|
-
respond_with(@order, default_template: 'spree/api/orders/could_not_apply_coupon')
|
87
|
-
return true
|
88
|
-
end
|
89
|
-
end
|
90
|
-
false
|
91
|
-
end
|
92
|
-
|
93
|
-
def order_id
|
94
|
-
super || params[:id]
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module Spree
|
2
|
-
module Api
|
3
|
-
class ClassificationsController < Spree::Api::BaseController
|
4
|
-
def update
|
5
|
-
authorize! :update, Product
|
6
|
-
authorize! :update, Taxon
|
7
|
-
classification = Spree::Classification.find_by(
|
8
|
-
:product_id => params[:product_id],
|
9
|
-
:taxon_id => params[:taxon_id]
|
10
|
-
)
|
11
|
-
# Because position we get back is 0-indexed.
|
12
|
-
# acts_as_list is 1-indexed.
|
13
|
-
classification.insert_at(params[:position].to_i + 1)
|
14
|
-
render :nothing => true
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module Spree
|
2
|
-
module Api
|
3
|
-
class CountriesController < Spree::Api::BaseController
|
4
|
-
skip_before_action :check_for_user_or_api_key
|
5
|
-
skip_before_action :authenticate_user
|
6
|
-
|
7
|
-
def index
|
8
|
-
@countries = Spree::Country.accessible_by(current_ability, :read).ransack(params[:q]).result.
|
9
|
-
includes(:states).order('name ASC').
|
10
|
-
page(params[:page]).per(params[:per_page])
|
11
|
-
country = Spree::Country.order("updated_at ASC").last
|
12
|
-
if stale?(country)
|
13
|
-
respond_with(@countries)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def show
|
18
|
-
@country = Spree::Country.accessible_by(current_ability, :read).find(params[:id])
|
19
|
-
respond_with(@country)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module Spree
|
2
|
-
module Api
|
3
|
-
class CreditCardsController < Spree::Api::BaseController
|
4
|
-
before_action :user
|
5
|
-
|
6
|
-
def index
|
7
|
-
@credit_cards = user
|
8
|
-
.credit_cards
|
9
|
-
.accessible_by(current_ability, :read)
|
10
|
-
.with_payment_profile
|
11
|
-
.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
12
|
-
respond_with(@credit_cards)
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def user
|
18
|
-
if params[:user_id].present?
|
19
|
-
@user ||= Spree::user_class.accessible_by(current_ability, :read).find(params[:user_id])
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
module Spree
|
2
|
-
module Api
|
3
|
-
class ImagesController < Spree::Api::BaseController
|
4
|
-
|
5
|
-
def index
|
6
|
-
@images = scope.images.accessible_by(current_ability, :read)
|
7
|
-
respond_with(@images)
|
8
|
-
end
|
9
|
-
|
10
|
-
def show
|
11
|
-
@image = Spree::Image.accessible_by(current_ability, :read).find(params[:id])
|
12
|
-
respond_with(@image)
|
13
|
-
end
|
14
|
-
|
15
|
-
def create
|
16
|
-
authorize! :create, Spree::Image
|
17
|
-
@image = scope.images.create(image_params)
|
18
|
-
respond_with(@image, :status => 201, :default_template => :show)
|
19
|
-
end
|
20
|
-
|
21
|
-
def update
|
22
|
-
@image = scope.images.accessible_by(current_ability, :update).find(params[:id])
|
23
|
-
@image.update_attributes(image_params)
|
24
|
-
respond_with(@image, :default_template => :show)
|
25
|
-
end
|
26
|
-
|
27
|
-
def destroy
|
28
|
-
@image = scope.images.accessible_by(current_ability, :destroy).find(params[:id])
|
29
|
-
@image.destroy
|
30
|
-
respond_with(@image, :status => 204)
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
def image_params
|
35
|
-
params.require(:image).permit(permitted_image_attributes)
|
36
|
-
end
|
37
|
-
|
38
|
-
def scope
|
39
|
-
if params[:product_id]
|
40
|
-
scope = Spree::Product.friendly.find(params[:product_id])
|
41
|
-
elsif params[:variant_id]
|
42
|
-
scope = Spree::Variant.find(params[:variant_id])
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
module Spree
|
2
|
-
module Api
|
3
|
-
class InventoryUnitsController < Spree::Api::BaseController
|
4
|
-
before_action :prepare_event, only: :update
|
5
|
-
|
6
|
-
def show
|
7
|
-
@inventory_unit = inventory_unit
|
8
|
-
respond_with(@inventory_unit)
|
9
|
-
end
|
10
|
-
|
11
|
-
def update
|
12
|
-
authorize! :update, inventory_unit.order
|
13
|
-
|
14
|
-
inventory_unit.transaction do
|
15
|
-
if inventory_unit.update_attributes(inventory_unit_params)
|
16
|
-
fire
|
17
|
-
render :show, :status => 200
|
18
|
-
else
|
19
|
-
invalid_resource!(inventory_unit)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def inventory_unit
|
27
|
-
@inventory_unit ||= Spree::InventoryUnit.accessible_by(current_ability, :read).find(params[:id])
|
28
|
-
end
|
29
|
-
|
30
|
-
def prepare_event
|
31
|
-
return unless @event = params[:fire]
|
32
|
-
|
33
|
-
can_event = "can_#{@event}?"
|
34
|
-
|
35
|
-
unless inventory_unit.respond_to?(can_event) &&
|
36
|
-
inventory_unit.send(can_event)
|
37
|
-
render :text => { :exception => "cannot transition to #{@event}" }.to_json,
|
38
|
-
:status => 200
|
39
|
-
false
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def fire
|
44
|
-
inventory_unit.send("#{@event}!") if @event
|
45
|
-
end
|
46
|
-
|
47
|
-
def inventory_unit_params
|
48
|
-
params.require(:inventory_unit).permit(permitted_inventory_unit_attributes)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
module Spree
|
2
|
-
module Api
|
3
|
-
class LineItemsController < Spree::Api::BaseController
|
4
|
-
class_attribute :line_item_options
|
5
|
-
|
6
|
-
self.line_item_options = []
|
7
|
-
|
8
|
-
def create
|
9
|
-
variant = Spree::Variant.find(params[:line_item][:variant_id])
|
10
|
-
@line_item = order.contents.add(
|
11
|
-
variant,
|
12
|
-
params[:line_item][:quantity] || 1,
|
13
|
-
line_item_params[:options] || {}
|
14
|
-
)
|
15
|
-
|
16
|
-
if @line_item.errors.empty?
|
17
|
-
respond_with(@line_item, status: 201, default_template: :show)
|
18
|
-
else
|
19
|
-
invalid_resource!(@line_item)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def update
|
24
|
-
@line_item = find_line_item
|
25
|
-
if @order.contents.update_cart(line_items_attributes)
|
26
|
-
@line_item.reload
|
27
|
-
respond_with(@line_item, default_template: :show)
|
28
|
-
else
|
29
|
-
invalid_resource!(@line_item)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def destroy
|
34
|
-
@line_item = find_line_item
|
35
|
-
variant = Spree::Variant.unscoped.find(@line_item.variant_id)
|
36
|
-
@order.contents.remove(variant, @line_item.quantity)
|
37
|
-
respond_with(@line_item, status: 204)
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
def order
|
42
|
-
@order ||= Spree::Order.includes(:line_items).find_by!(number: order_id)
|
43
|
-
authorize! :update, @order, order_token
|
44
|
-
end
|
45
|
-
|
46
|
-
def find_line_item
|
47
|
-
id = params[:id].to_i
|
48
|
-
order.line_items.detect { |line_item| line_item.id == id } or
|
49
|
-
raise ActiveRecord::RecordNotFound
|
50
|
-
end
|
51
|
-
|
52
|
-
def line_items_attributes
|
53
|
-
{line_items_attributes: {
|
54
|
-
id: params[:id],
|
55
|
-
quantity: params[:line_item][:quantity],
|
56
|
-
options: line_item_params[:options] || {}
|
57
|
-
}}
|
58
|
-
end
|
59
|
-
|
60
|
-
def line_item_params
|
61
|
-
params.require(:line_item).permit(
|
62
|
-
:quantity,
|
63
|
-
:variant_id,
|
64
|
-
options: line_item_options
|
65
|
-
)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
module Spree
|
2
|
-
module Api
|
3
|
-
class OptionTypesController < Spree::Api::BaseController
|
4
|
-
def index
|
5
|
-
if params[:ids]
|
6
|
-
@option_types = Spree::OptionType.includes(:option_values).accessible_by(current_ability, :read).where(id: params[:ids].split(','))
|
7
|
-
else
|
8
|
-
@option_types = Spree::OptionType.includes(:option_values).accessible_by(current_ability, :read).load.ransack(params[:q]).result
|
9
|
-
end
|
10
|
-
respond_with(@option_types)
|
11
|
-
end
|
12
|
-
|
13
|
-
def show
|
14
|
-
@option_type = Spree::OptionType.accessible_by(current_ability, :read).find(params[:id])
|
15
|
-
respond_with(@option_type)
|
16
|
-
end
|
17
|
-
|
18
|
-
def create
|
19
|
-
authorize! :create, Spree::OptionType
|
20
|
-
@option_type = Spree::OptionType.new(option_type_params)
|
21
|
-
if @option_type.save
|
22
|
-
render :show, :status => 201
|
23
|
-
else
|
24
|
-
invalid_resource!(@option_type)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def update
|
29
|
-
@option_type = Spree::OptionType.accessible_by(current_ability, :update).find(params[:id])
|
30
|
-
if @option_type.update_attributes(option_type_params)
|
31
|
-
render :show
|
32
|
-
else
|
33
|
-
invalid_resource!(@option_type)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def destroy
|
38
|
-
@option_type = Spree::OptionType.accessible_by(current_ability, :destroy).find(params[:id])
|
39
|
-
@option_type.destroy
|
40
|
-
render :text => nil, :status => 204
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
|
-
def option_type_params
|
45
|
-
params.require(:option_type).permit(permitted_option_type_attributes)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
module Spree
|
2
|
-
module Api
|
3
|
-
class OptionValuesController < Spree::Api::BaseController
|
4
|
-
def index
|
5
|
-
if params[:ids]
|
6
|
-
@option_values = scope.where(:id => params[:ids])
|
7
|
-
else
|
8
|
-
@option_values = scope.ransack(params[:q]).result.distinct
|
9
|
-
end
|
10
|
-
respond_with(@option_values)
|
11
|
-
end
|
12
|
-
|
13
|
-
def show
|
14
|
-
@option_value = scope.find(params[:id])
|
15
|
-
respond_with(@option_value)
|
16
|
-
end
|
17
|
-
|
18
|
-
def create
|
19
|
-
authorize! :create, Spree::OptionValue
|
20
|
-
@option_value = scope.new(option_value_params)
|
21
|
-
if @option_value.save
|
22
|
-
render :show, :status => 201
|
23
|
-
else
|
24
|
-
invalid_resource!(@option_value)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def update
|
29
|
-
@option_value = scope.accessible_by(current_ability, :update).find(params[:id])
|
30
|
-
if @option_value.update_attributes(option_value_params)
|
31
|
-
render :show
|
32
|
-
else
|
33
|
-
invalid_resource!(@option_value)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def destroy
|
38
|
-
@option_value = scope.accessible_by(current_ability, :destroy).find(params[:id])
|
39
|
-
@option_value.destroy
|
40
|
-
render :text => nil, :status => 204
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
def scope
|
46
|
-
if params[:option_type_id]
|
47
|
-
@scope ||= Spree::OptionType.find(params[:option_type_id]).option_values.accessible_by(current_ability, :read)
|
48
|
-
else
|
49
|
-
@scope ||= Spree::OptionValue.accessible_by(current_ability, :read).load
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def option_value_params
|
54
|
-
params.require(:option_value).permit(permitted_option_value_attributes)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|