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
@@ -0,0 +1,126 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class ProductsController < Spree::Api::BaseController
|
5
|
+
|
6
|
+
def index
|
7
|
+
if params[:ids]
|
8
|
+
@products = product_scope.where(id: params[:ids].split(",").flatten)
|
9
|
+
else
|
10
|
+
@products = product_scope.ransack(params[:q]).result
|
11
|
+
end
|
12
|
+
|
13
|
+
@products = @products.distinct.page(params[:page]).per(params[:per_page])
|
14
|
+
expires_in 15.minutes, :public => true
|
15
|
+
headers['Surrogate-Control'] = "max-age=#{15.minutes}"
|
16
|
+
respond_with(@products)
|
17
|
+
end
|
18
|
+
|
19
|
+
def show
|
20
|
+
@product = find_product(params[:id])
|
21
|
+
expires_in 15.minutes, :public => true
|
22
|
+
headers['Surrogate-Control'] = "max-age=#{15.minutes}"
|
23
|
+
headers['Surrogate-Key'] = "product_id=1"
|
24
|
+
respond_with(@product)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Takes besides the products attributes either an array of variants or
|
28
|
+
# an array of option types.
|
29
|
+
#
|
30
|
+
# By submitting an array of variants the option types will be created
|
31
|
+
# using the *name* key in options hash. e.g
|
32
|
+
#
|
33
|
+
# product: {
|
34
|
+
# ...
|
35
|
+
# variants: {
|
36
|
+
# price: 19.99,
|
37
|
+
# sku: "hey_you",
|
38
|
+
# options: [
|
39
|
+
# { name: "size", value: "small" },
|
40
|
+
# { name: "color", value: "black" }
|
41
|
+
# ]
|
42
|
+
# }
|
43
|
+
# }
|
44
|
+
#
|
45
|
+
# Or just pass in the option types hash:
|
46
|
+
#
|
47
|
+
# product: {
|
48
|
+
# ...
|
49
|
+
# option_types: ['size', 'color']
|
50
|
+
# }
|
51
|
+
#
|
52
|
+
# By passing the shipping category name you can fetch or create that
|
53
|
+
# shipping category on the fly. e.g.
|
54
|
+
#
|
55
|
+
# product: {
|
56
|
+
# ...
|
57
|
+
# shipping_category: "Free Shipping Items"
|
58
|
+
# }
|
59
|
+
#
|
60
|
+
def create
|
61
|
+
authorize! :create, Product
|
62
|
+
params[:product][:available_on] ||= Time.current
|
63
|
+
set_up_shipping_category
|
64
|
+
|
65
|
+
options = { variants_attrs: variants_params, options_attrs: option_types_params }
|
66
|
+
@product = Core::Importer::Product.new(nil, product_params, options).create
|
67
|
+
|
68
|
+
if @product.persisted?
|
69
|
+
respond_with(@product, :status => 201, :default_template => :show)
|
70
|
+
else
|
71
|
+
invalid_resource!(@product)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def update
|
76
|
+
@product = find_product(params[:id])
|
77
|
+
authorize! :update, @product
|
78
|
+
|
79
|
+
options = { variants_attrs: variants_params, options_attrs: option_types_params }
|
80
|
+
@product = Core::Importer::Product.new(@product, product_params, options).update
|
81
|
+
|
82
|
+
if @product.errors.empty?
|
83
|
+
respond_with(@product.reload, :status => 200, :default_template => :show)
|
84
|
+
else
|
85
|
+
invalid_resource!(@product)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def destroy
|
90
|
+
@product = find_product(params[:id])
|
91
|
+
authorize! :destroy, @product
|
92
|
+
@product.destroy
|
93
|
+
respond_with(@product, :status => 204)
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
def product_params
|
98
|
+
params.require(:product).permit(permitted_product_attributes)
|
99
|
+
end
|
100
|
+
|
101
|
+
def variants_params
|
102
|
+
variants_key = if params[:product].has_key? :variants
|
103
|
+
:variants
|
104
|
+
else
|
105
|
+
:variants_attributes
|
106
|
+
end
|
107
|
+
|
108
|
+
params.require(:product).permit(
|
109
|
+
variants_key => [permitted_variant_attributes, :id],
|
110
|
+
).delete(variants_key) || []
|
111
|
+
end
|
112
|
+
|
113
|
+
def option_types_params
|
114
|
+
params[:product].fetch(:option_types, [])
|
115
|
+
end
|
116
|
+
|
117
|
+
def set_up_shipping_category
|
118
|
+
if shipping_category = params[:product].delete(:shipping_category)
|
119
|
+
id = ShippingCategory.find_or_create_by(name: shipping_category).id
|
120
|
+
params[:product][:shipping_category_id] = id
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class PromotionsController < Spree::Api::BaseController
|
5
|
+
before_action :requires_admin
|
6
|
+
before_action :load_promotion
|
7
|
+
|
8
|
+
def show
|
9
|
+
if @promotion
|
10
|
+
respond_with(@promotion, default_template: :show)
|
11
|
+
else
|
12
|
+
raise ActiveRecord::RecordNotFound
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def requires_admin
|
18
|
+
return if @current_user_roles.include?("admin")
|
19
|
+
unauthorized and return
|
20
|
+
end
|
21
|
+
|
22
|
+
def load_promotion
|
23
|
+
@promotion = Spree::Promotion.find_by_id(params[:id]) || Spree::Promotion.with_coupon_code(params[:id])
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class PropertiesController < Spree::Api::BaseController
|
5
|
+
|
6
|
+
before_action :find_property, only: [:show, :update, :destroy]
|
7
|
+
|
8
|
+
def index
|
9
|
+
@properties = Spree::Property.accessible_by(current_ability, :read)
|
10
|
+
|
11
|
+
if params[:ids]
|
12
|
+
@properties = @properties.where(id: params[:ids].split(",").flatten)
|
13
|
+
else
|
14
|
+
@properties = @properties.ransack(params[:q]).result
|
15
|
+
end
|
16
|
+
|
17
|
+
@properties = @properties.page(params[:page]).per(params[:per_page])
|
18
|
+
respond_with(@properties)
|
19
|
+
end
|
20
|
+
|
21
|
+
def show
|
22
|
+
respond_with(@property)
|
23
|
+
end
|
24
|
+
|
25
|
+
def new
|
26
|
+
end
|
27
|
+
|
28
|
+
def create
|
29
|
+
authorize! :create, Property
|
30
|
+
@property = Spree::Property.new(property_params)
|
31
|
+
if @property.save
|
32
|
+
respond_with(@property, status: 201, default_template: :show)
|
33
|
+
else
|
34
|
+
invalid_resource!(@property)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def update
|
39
|
+
if @property
|
40
|
+
authorize! :update, @property
|
41
|
+
@property.update_attributes(property_params)
|
42
|
+
respond_with(@property, status: 200, default_template: :show)
|
43
|
+
else
|
44
|
+
invalid_resource!(@property)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def destroy
|
49
|
+
if @property
|
50
|
+
authorize! :destroy, @property
|
51
|
+
@property.destroy
|
52
|
+
respond_with(@property, status: 204)
|
53
|
+
else
|
54
|
+
invalid_resource!(@property)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def find_property
|
61
|
+
@property = Spree::Property.accessible_by(current_ability, :read).find(params[:id])
|
62
|
+
rescue ActiveRecord::RecordNotFound
|
63
|
+
@property = Spree::Property.accessible_by(current_ability, :read).find_by!(name: params[:id])
|
64
|
+
end
|
65
|
+
|
66
|
+
def property_params
|
67
|
+
params.require(:property).permit(permitted_property_attributes)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class ReturnAuthorizationsController < Spree::Api::BaseController
|
5
|
+
|
6
|
+
def create
|
7
|
+
authorize! :create, ReturnAuthorization
|
8
|
+
@return_authorization = order.return_authorizations.build(return_authorization_params)
|
9
|
+
if @return_authorization.save
|
10
|
+
respond_with(@return_authorization, status: 201, default_template: :show)
|
11
|
+
else
|
12
|
+
invalid_resource!(@return_authorization)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def destroy
|
17
|
+
@return_authorization = order.return_authorizations.accessible_by(current_ability, :destroy).find(params[:id])
|
18
|
+
@return_authorization.destroy
|
19
|
+
respond_with(@return_authorization, status: 204)
|
20
|
+
end
|
21
|
+
|
22
|
+
def index
|
23
|
+
authorize! :admin, ReturnAuthorization
|
24
|
+
@return_authorizations = order.return_authorizations.accessible_by(current_ability, :read).
|
25
|
+
ransack(params[:q]).result.
|
26
|
+
page(params[:page]).per(params[:per_page])
|
27
|
+
respond_with(@return_authorizations)
|
28
|
+
end
|
29
|
+
|
30
|
+
def new
|
31
|
+
authorize! :admin, ReturnAuthorization
|
32
|
+
end
|
33
|
+
|
34
|
+
def show
|
35
|
+
authorize! :admin, ReturnAuthorization
|
36
|
+
@return_authorization = order.return_authorizations.accessible_by(current_ability, :read).find(params[:id])
|
37
|
+
respond_with(@return_authorization)
|
38
|
+
end
|
39
|
+
|
40
|
+
def update
|
41
|
+
@return_authorization = order.return_authorizations.accessible_by(current_ability, :update).find(params[:id])
|
42
|
+
if @return_authorization.update_attributes(return_authorization_params)
|
43
|
+
respond_with(@return_authorization, default_template: :show)
|
44
|
+
else
|
45
|
+
invalid_resource!(@return_authorization)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def cancel
|
50
|
+
@return_authorization = order.return_authorizations.accessible_by(current_ability, :update).find(params[:id])
|
51
|
+
if @return_authorization.cancel
|
52
|
+
respond_with @return_authorization, default_template: :show
|
53
|
+
else
|
54
|
+
invalid_resource!(@return_authorization)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def order
|
61
|
+
@order ||= Spree::Order.find_by!(number: order_id)
|
62
|
+
authorize! :read, @order
|
63
|
+
end
|
64
|
+
|
65
|
+
def return_authorization_params
|
66
|
+
params.require(:return_authorization).permit(permitted_return_authorization_attributes)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,163 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class ShipmentsController < Spree::Api::BaseController
|
5
|
+
|
6
|
+
before_action :find_and_update_shipment, only: [:ship, :ready, :add, :remove]
|
7
|
+
before_action :load_transfer_params, only: [:transfer_to_location, :transfer_to_shipment]
|
8
|
+
|
9
|
+
def mine
|
10
|
+
if current_api_user.persisted?
|
11
|
+
@shipments = Spree::Shipment
|
12
|
+
.reverse_chronological
|
13
|
+
.joins(:order)
|
14
|
+
.where(spree_orders: {user_id: current_api_user.id})
|
15
|
+
.includes(mine_includes)
|
16
|
+
.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
17
|
+
else
|
18
|
+
render "spree/api/errors/unauthorized", status: :unauthorized
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def create
|
23
|
+
@order = Spree::Order.find_by!(number: params.fetch(:shipment).fetch(:order_id))
|
24
|
+
authorize! :read, @order
|
25
|
+
authorize! :create, Shipment
|
26
|
+
quantity = params[:quantity].to_i
|
27
|
+
@shipment = @order.shipments.create(stock_location_id: params.fetch(:stock_location_id))
|
28
|
+
@order.contents.add(variant, quantity, {shipment: @shipment})
|
29
|
+
|
30
|
+
@shipment.save!
|
31
|
+
|
32
|
+
respond_with(@shipment.reload, default_template: :show)
|
33
|
+
end
|
34
|
+
|
35
|
+
def update
|
36
|
+
@shipment = Spree::Shipment.accessible_by(current_ability, :update).readonly(false).friendly.find(params[:id])
|
37
|
+
@shipment.update_attributes_and_order(shipment_params)
|
38
|
+
|
39
|
+
respond_with(@shipment.reload, default_template: :show)
|
40
|
+
end
|
41
|
+
|
42
|
+
def ready
|
43
|
+
unless @shipment.ready?
|
44
|
+
if @shipment.can_ready?
|
45
|
+
@shipment.ready!
|
46
|
+
else
|
47
|
+
render 'spree/api/v1/shipments/cannot_ready_shipment', status: 422 and return
|
48
|
+
end
|
49
|
+
end
|
50
|
+
respond_with(@shipment, default_template: :show)
|
51
|
+
end
|
52
|
+
|
53
|
+
def ship
|
54
|
+
unless @shipment.shipped?
|
55
|
+
@shipment.ship!
|
56
|
+
end
|
57
|
+
respond_with(@shipment, default_template: :show)
|
58
|
+
end
|
59
|
+
|
60
|
+
def add
|
61
|
+
quantity = params[:quantity].to_i
|
62
|
+
|
63
|
+
@shipment.order.contents.add(variant, quantity, {shipment: @shipment})
|
64
|
+
|
65
|
+
respond_with(@shipment, default_template: :show)
|
66
|
+
end
|
67
|
+
|
68
|
+
def remove
|
69
|
+
quantity = params[:quantity].to_i
|
70
|
+
|
71
|
+
@shipment.order.contents.remove(variant, quantity, {shipment: @shipment})
|
72
|
+
@shipment.reload if @shipment.persisted?
|
73
|
+
respond_with(@shipment, default_template: :show)
|
74
|
+
end
|
75
|
+
|
76
|
+
def transfer_to_location
|
77
|
+
@stock_location = Spree::StockLocation.find(params[:stock_location_id])
|
78
|
+
|
79
|
+
unless @quantity > 0
|
80
|
+
unprocessable_entity('ArgumentError')
|
81
|
+
return
|
82
|
+
end
|
83
|
+
|
84
|
+
@original_shipment.transfer_to_location(@variant, @quantity, @stock_location)
|
85
|
+
render json: {success: true, message: Spree.t(:shipment_transfer_success)}, status: 201
|
86
|
+
end
|
87
|
+
|
88
|
+
def transfer_to_shipment
|
89
|
+
@target_shipment = Spree::Shipment.friendly.find(params[:target_shipment_number])
|
90
|
+
|
91
|
+
if @quantity < 0 || @target_shipment == @original_shipment
|
92
|
+
unprocessable_entity('ArgumentError')
|
93
|
+
return
|
94
|
+
end
|
95
|
+
|
96
|
+
@original_shipment.transfer_to_shipment(@variant, @quantity, @target_shipment)
|
97
|
+
render json: {success: true, message: Spree.t(:shipment_transfer_success)}, status: 201
|
98
|
+
end
|
99
|
+
|
100
|
+
private
|
101
|
+
|
102
|
+
def load_transfer_params
|
103
|
+
@original_shipment = Spree::Shipment.friendly.find(params[:original_shipment_number])
|
104
|
+
@variant = Spree::Variant.find(params[:variant_id])
|
105
|
+
@quantity = params[:quantity].to_i
|
106
|
+
authorize! :read, @original_shipment
|
107
|
+
authorize! :create, Shipment
|
108
|
+
end
|
109
|
+
|
110
|
+
def find_and_update_shipment
|
111
|
+
@shipment = Spree::Shipment.accessible_by(current_ability, :update).readonly(false).friendly.find(params[:id])
|
112
|
+
@shipment.update_attributes(shipment_params)
|
113
|
+
@shipment.reload
|
114
|
+
end
|
115
|
+
|
116
|
+
def shipment_params
|
117
|
+
if params[:shipment] && !params[:shipment].empty?
|
118
|
+
params.require(:shipment).permit(permitted_shipment_attributes)
|
119
|
+
else
|
120
|
+
{}
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def variant
|
125
|
+
@variant ||= Spree::Variant.unscoped.find(params.fetch(:variant_id))
|
126
|
+
end
|
127
|
+
|
128
|
+
def mine_includes
|
129
|
+
{
|
130
|
+
order: {
|
131
|
+
bill_address: {
|
132
|
+
state: {},
|
133
|
+
country: {},
|
134
|
+
},
|
135
|
+
ship_address: {
|
136
|
+
state: {},
|
137
|
+
country: {},
|
138
|
+
},
|
139
|
+
adjustments: {},
|
140
|
+
payments: {
|
141
|
+
order: {},
|
142
|
+
payment_method: {},
|
143
|
+
},
|
144
|
+
},
|
145
|
+
inventory_units: {
|
146
|
+
line_item: {
|
147
|
+
product: {},
|
148
|
+
variant: {},
|
149
|
+
},
|
150
|
+
variant: {
|
151
|
+
product: {},
|
152
|
+
default_price: {},
|
153
|
+
option_values: {
|
154
|
+
option_type: {},
|
155
|
+
},
|
156
|
+
},
|
157
|
+
},
|
158
|
+
}
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|