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
@@ -1,69 +0,0 @@
|
|
1
|
-
module Spree
|
2
|
-
module Api
|
3
|
-
class ReturnAuthorizationsController < Spree::Api::BaseController
|
4
|
-
|
5
|
-
def create
|
6
|
-
authorize! :create, Spree::ReturnAuthorization
|
7
|
-
@return_authorization = order.return_authorizations.build(return_authorization_params)
|
8
|
-
if @return_authorization.save
|
9
|
-
respond_with(@return_authorization, status: 201, default_template: :show)
|
10
|
-
else
|
11
|
-
invalid_resource!(@return_authorization)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def destroy
|
16
|
-
@return_authorization = order.return_authorizations.accessible_by(current_ability, :destroy).find(params[:id])
|
17
|
-
@return_authorization.destroy
|
18
|
-
respond_with(@return_authorization, status: 204)
|
19
|
-
end
|
20
|
-
|
21
|
-
def index
|
22
|
-
authorize! :admin, Spree::ReturnAuthorization
|
23
|
-
@return_authorizations = order.return_authorizations.accessible_by(current_ability, :read).
|
24
|
-
ransack(params[:q]).result.
|
25
|
-
page(params[:page]).per(params[:per_page])
|
26
|
-
respond_with(@return_authorizations)
|
27
|
-
end
|
28
|
-
|
29
|
-
def new
|
30
|
-
authorize! :admin, Spree::ReturnAuthorization
|
31
|
-
end
|
32
|
-
|
33
|
-
def show
|
34
|
-
authorize! :admin, Spree::ReturnAuthorization
|
35
|
-
@return_authorization = order.return_authorizations.accessible_by(current_ability, :read).find(params[:id])
|
36
|
-
respond_with(@return_authorization)
|
37
|
-
end
|
38
|
-
|
39
|
-
def update
|
40
|
-
@return_authorization = order.return_authorizations.accessible_by(current_ability, :update).find(params[:id])
|
41
|
-
if @return_authorization.update_attributes(return_authorization_params)
|
42
|
-
respond_with(@return_authorization, default_template: :show)
|
43
|
-
else
|
44
|
-
invalid_resource!(@return_authorization)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def cancel
|
49
|
-
@return_authorization = order.return_authorizations.accessible_by(current_ability, :update).find(params[:id])
|
50
|
-
if @return_authorization.cancel
|
51
|
-
respond_with @return_authorization, default_template: :show
|
52
|
-
else
|
53
|
-
invalid_resource!(@return_authorization)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
private
|
58
|
-
|
59
|
-
def order
|
60
|
-
@order ||= Spree::Order.find_by!(number: order_id)
|
61
|
-
authorize! :read, @order
|
62
|
-
end
|
63
|
-
|
64
|
-
def return_authorization_params
|
65
|
-
params.require(:return_authorization).permit(permitted_return_authorization_attributes)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,149 +0,0 @@
|
|
1
|
-
module Spree
|
2
|
-
module Api
|
3
|
-
class ShipmentsController < Spree::Api::BaseController
|
4
|
-
|
5
|
-
before_action :find_and_update_shipment, only: [:ship, :ready, :add, :remove]
|
6
|
-
before_action :load_transfer_params, only: [:transfer_to_location, :transfer_to_shipment]
|
7
|
-
|
8
|
-
def mine
|
9
|
-
if current_api_user.persisted?
|
10
|
-
@shipments = Spree::Shipment
|
11
|
-
.reverse_chronological
|
12
|
-
.joins(:order)
|
13
|
-
.where(spree_orders: {user_id: current_api_user.id})
|
14
|
-
.includes(mine_includes)
|
15
|
-
.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
16
|
-
else
|
17
|
-
render "spree/api/errors/unauthorized", status: :unauthorized
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def create
|
22
|
-
@order = Spree::Order.find_by!(number: params.fetch(:shipment).fetch(:order_id))
|
23
|
-
authorize! :read, @order
|
24
|
-
authorize! :create, Shipment
|
25
|
-
quantity = params[:quantity].to_i
|
26
|
-
@shipment = @order.shipments.create(stock_location_id: params.fetch(:stock_location_id))
|
27
|
-
@order.contents.add(variant, quantity, {shipment: @shipment})
|
28
|
-
|
29
|
-
@shipment.save!
|
30
|
-
|
31
|
-
respond_with(@shipment.reload, default_template: :show)
|
32
|
-
end
|
33
|
-
|
34
|
-
def update
|
35
|
-
@shipment = Spree::Shipment.accessible_by(current_ability, :update).readonly(false).friendly.find(params[:id])
|
36
|
-
@shipment.update_attributes_and_order(shipment_params)
|
37
|
-
|
38
|
-
respond_with(@shipment.reload, default_template: :show)
|
39
|
-
end
|
40
|
-
|
41
|
-
def ready
|
42
|
-
unless @shipment.ready?
|
43
|
-
if @shipment.can_ready?
|
44
|
-
@shipment.ready!
|
45
|
-
else
|
46
|
-
render 'spree/api/shipments/cannot_ready_shipment', status: 422 and return
|
47
|
-
end
|
48
|
-
end
|
49
|
-
respond_with(@shipment, default_template: :show)
|
50
|
-
end
|
51
|
-
|
52
|
-
def ship
|
53
|
-
unless @shipment.shipped?
|
54
|
-
@shipment.ship!
|
55
|
-
end
|
56
|
-
respond_with(@shipment, default_template: :show)
|
57
|
-
end
|
58
|
-
|
59
|
-
def add
|
60
|
-
quantity = params[:quantity].to_i
|
61
|
-
|
62
|
-
@shipment.order.contents.add(variant, quantity, {shipment: @shipment})
|
63
|
-
|
64
|
-
respond_with(@shipment, default_template: :show)
|
65
|
-
end
|
66
|
-
|
67
|
-
def remove
|
68
|
-
quantity = params[:quantity].to_i
|
69
|
-
|
70
|
-
@shipment.order.contents.remove(variant, quantity, {shipment: @shipment})
|
71
|
-
@shipment.reload if @shipment.persisted?
|
72
|
-
respond_with(@shipment, default_template: :show)
|
73
|
-
end
|
74
|
-
|
75
|
-
def transfer_to_location
|
76
|
-
@stock_location = Spree::StockLocation.find(params[:stock_location_id])
|
77
|
-
@original_shipment.transfer_to_location(@variant, @quantity, @stock_location)
|
78
|
-
render json: {success: true, message: Spree.t(:shipment_transfer_success)}, status: 201
|
79
|
-
end
|
80
|
-
|
81
|
-
def transfer_to_shipment
|
82
|
-
@target_shipment = Spree::Shipment.friendly.find(params[:target_shipment_number])
|
83
|
-
@original_shipment.transfer_to_shipment(@variant, @quantity, @target_shipment)
|
84
|
-
render json: {success: true, message: Spree.t(:shipment_transfer_success)}, status: 201
|
85
|
-
end
|
86
|
-
|
87
|
-
private
|
88
|
-
|
89
|
-
def load_transfer_params
|
90
|
-
@original_shipment = Spree::Shipment.friendly.find(params[:original_shipment_number])
|
91
|
-
@variant = Spree::Variant.find(params[:variant_id])
|
92
|
-
@quantity = params[:quantity].to_i
|
93
|
-
authorize! :read, @original_shipment
|
94
|
-
authorize! :create, Shipment
|
95
|
-
end
|
96
|
-
|
97
|
-
def find_and_update_shipment
|
98
|
-
@shipment = Spree::Shipment.accessible_by(current_ability, :update).readonly(false).friendly.find(params[:id])
|
99
|
-
@shipment.update_attributes(shipment_params)
|
100
|
-
@shipment.reload
|
101
|
-
end
|
102
|
-
|
103
|
-
def shipment_params
|
104
|
-
if params[:shipment] && !params[:shipment].empty?
|
105
|
-
params.require(:shipment).permit(permitted_shipment_attributes)
|
106
|
-
else
|
107
|
-
{}
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
def variant
|
112
|
-
@variant ||= Spree::Variant.unscoped.find(params.fetch(:variant_id))
|
113
|
-
end
|
114
|
-
|
115
|
-
def mine_includes
|
116
|
-
{
|
117
|
-
order: {
|
118
|
-
bill_address: {
|
119
|
-
state: {},
|
120
|
-
country: {},
|
121
|
-
},
|
122
|
-
ship_address: {
|
123
|
-
state: {},
|
124
|
-
country: {},
|
125
|
-
},
|
126
|
-
adjustments: {},
|
127
|
-
payments: {
|
128
|
-
order: {},
|
129
|
-
payment_method: {},
|
130
|
-
},
|
131
|
-
},
|
132
|
-
inventory_units: {
|
133
|
-
line_item: {
|
134
|
-
product: {},
|
135
|
-
variant: {},
|
136
|
-
},
|
137
|
-
variant: {
|
138
|
-
product: {},
|
139
|
-
default_price: {},
|
140
|
-
option_values: {
|
141
|
-
option_type: {},
|
142
|
-
},
|
143
|
-
},
|
144
|
-
},
|
145
|
-
}
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
module Spree
|
2
|
-
module Api
|
3
|
-
class StatesController < Spree::Api::BaseController
|
4
|
-
skip_before_action :set_expiry
|
5
|
-
skip_before_action :check_for_user_or_api_key
|
6
|
-
skip_before_action :authenticate_user
|
7
|
-
|
8
|
-
def index
|
9
|
-
@states = scope.ransack(params[:q]).result.
|
10
|
-
includes(:country).order('name ASC')
|
11
|
-
|
12
|
-
if params[:page] || params[:per_page]
|
13
|
-
@states = @states.page(params[:page]).per(params[:per_page])
|
14
|
-
end
|
15
|
-
|
16
|
-
state = @states.last
|
17
|
-
if stale?(state)
|
18
|
-
respond_with(@states)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def show
|
23
|
-
@state = scope.find(params[:id])
|
24
|
-
respond_with(@state)
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
def scope
|
29
|
-
if params[:country_id]
|
30
|
-
@country = Spree::Country.accessible_by(current_ability, :read).find(params[:country_id])
|
31
|
-
return @country.states.accessible_by(current_ability, :read)
|
32
|
-
else
|
33
|
-
return Spree::State.accessible_by(current_ability, :read)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,75 +0,0 @@
|
|
1
|
-
module Spree
|
2
|
-
module Api
|
3
|
-
class StockItemsController < Spree::Api::BaseController
|
4
|
-
before_action :stock_location, except: [:update, :destroy]
|
5
|
-
|
6
|
-
def index
|
7
|
-
@stock_items = scope.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
8
|
-
respond_with(@stock_items)
|
9
|
-
end
|
10
|
-
|
11
|
-
def show
|
12
|
-
@stock_item = scope.find(params[:id])
|
13
|
-
respond_with(@stock_item)
|
14
|
-
end
|
15
|
-
|
16
|
-
def create
|
17
|
-
authorize! :create, Spree::StockItem
|
18
|
-
|
19
|
-
count_on_hand = 0
|
20
|
-
if params[:stock_item].has_key?(:count_on_hand)
|
21
|
-
count_on_hand = params[:stock_item][:count_on_hand].to_i
|
22
|
-
end
|
23
|
-
|
24
|
-
@stock_item = scope.new(stock_item_params)
|
25
|
-
if @stock_item.save
|
26
|
-
@stock_item.adjust_count_on_hand(count_on_hand)
|
27
|
-
respond_with(@stock_item, status: 201, default_template: :show)
|
28
|
-
else
|
29
|
-
invalid_resource!(@stock_item)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def update
|
34
|
-
@stock_item = Spree::StockItem.accessible_by(current_ability, :update).find(params[:id])
|
35
|
-
|
36
|
-
count_on_hand = 0
|
37
|
-
if params[:stock_item].has_key?(:count_on_hand)
|
38
|
-
count_on_hand = params[:stock_item][:count_on_hand].to_i
|
39
|
-
params[:stock_item].delete(:count_on_hand)
|
40
|
-
end
|
41
|
-
|
42
|
-
updated = params[:stock_item][:force] ? @stock_item.set_count_on_hand(count_on_hand)
|
43
|
-
: @stock_item.adjust_count_on_hand(count_on_hand)
|
44
|
-
|
45
|
-
if updated
|
46
|
-
respond_with(@stock_item, status: 200, default_template: :show)
|
47
|
-
else
|
48
|
-
invalid_resource!(@stock_item)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def destroy
|
53
|
-
@stock_item = Spree::StockItem.accessible_by(current_ability, :destroy).find(params[:id])
|
54
|
-
@stock_item.destroy
|
55
|
-
respond_with(@stock_item, status: 204)
|
56
|
-
end
|
57
|
-
|
58
|
-
private
|
59
|
-
|
60
|
-
def stock_location
|
61
|
-
render 'spree/api/shared/stock_location_required', status: 422 and return unless params[:stock_location_id]
|
62
|
-
@stock_location ||= Spree::StockLocation.accessible_by(current_ability, :read).find(params[:stock_location_id])
|
63
|
-
end
|
64
|
-
|
65
|
-
def scope
|
66
|
-
includes = {:variant => [{ :option_values => :option_type }, :product] }
|
67
|
-
@stock_location.stock_items.accessible_by(current_ability, :read).includes(includes)
|
68
|
-
end
|
69
|
-
|
70
|
-
def stock_item_params
|
71
|
-
params.require(:stock_item).permit(permitted_stock_item_attributes)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
module Spree
|
2
|
-
module Api
|
3
|
-
class StockLocationsController < Spree::Api::BaseController
|
4
|
-
def index
|
5
|
-
authorize! :read, Spree::StockLocation
|
6
|
-
@stock_locations = Spree::StockLocation.accessible_by(current_ability, :read).order('name ASC').ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
7
|
-
respond_with(@stock_locations)
|
8
|
-
end
|
9
|
-
|
10
|
-
def show
|
11
|
-
respond_with(stock_location)
|
12
|
-
end
|
13
|
-
|
14
|
-
def create
|
15
|
-
authorize! :create, Spree::StockLocation
|
16
|
-
@stock_location = Spree::StockLocation.new(stock_location_params)
|
17
|
-
if @stock_location.save
|
18
|
-
respond_with(@stock_location, status: 201, default_template: :show)
|
19
|
-
else
|
20
|
-
invalid_resource!(@stock_location)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def update
|
25
|
-
authorize! :update, stock_location
|
26
|
-
if stock_location.update_attributes(stock_location_params)
|
27
|
-
respond_with(stock_location, status: 200, default_template: :show)
|
28
|
-
else
|
29
|
-
invalid_resource!(stock_location)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def destroy
|
34
|
-
authorize! :destroy, stock_location
|
35
|
-
stock_location.destroy
|
36
|
-
respond_with(stock_location, :status => 204)
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
|
41
|
-
def stock_location
|
42
|
-
@stock_location ||= Spree::StockLocation.accessible_by(current_ability, :read).find(params[:id])
|
43
|
-
end
|
44
|
-
|
45
|
-
def stock_location_params
|
46
|
-
params.require(:stock_location).permit(permitted_stock_location_attributes)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
module Spree
|
2
|
-
module Api
|
3
|
-
class StockMovementsController < Spree::Api::BaseController
|
4
|
-
before_action :stock_location, except: [:update, :destroy]
|
5
|
-
|
6
|
-
def index
|
7
|
-
authorize! :read, Spree::StockMovement
|
8
|
-
@stock_movements = scope.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
9
|
-
respond_with(@stock_movements)
|
10
|
-
end
|
11
|
-
|
12
|
-
def show
|
13
|
-
@stock_movement = scope.find(params[:id])
|
14
|
-
respond_with(@stock_movement)
|
15
|
-
end
|
16
|
-
|
17
|
-
def create
|
18
|
-
authorize! :create, Spree::StockMovement
|
19
|
-
@stock_movement = scope.new(stock_movement_params)
|
20
|
-
if @stock_movement.save
|
21
|
-
respond_with(@stock_movement, status: 201, default_template: :show)
|
22
|
-
else
|
23
|
-
invalid_resource!(@stock_movement)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def stock_location
|
30
|
-
render 'spree/api/shared/stock_location_required', status: 422 and return unless params[:stock_location_id]
|
31
|
-
@stock_location ||= Spree::StockLocation.accessible_by(current_ability, :read).find(params[:stock_location_id])
|
32
|
-
end
|
33
|
-
|
34
|
-
def scope
|
35
|
-
@stock_location.stock_movements.accessible_by(current_ability, :read)
|
36
|
-
end
|
37
|
-
|
38
|
-
def stock_movement_params
|
39
|
-
params.require(:stock_movement).permit(permitted_stock_movement_attributes)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
module Spree
|
2
|
-
module Api
|
3
|
-
class StoresController < Spree::Api::BaseController
|
4
|
-
|
5
|
-
before_action :get_store, except: [:index, :create]
|
6
|
-
|
7
|
-
def index
|
8
|
-
authorize! :read, Spree::Store
|
9
|
-
@stores = Spree::Store.accessible_by(current_ability, :read).all
|
10
|
-
respond_with(@stores)
|
11
|
-
end
|
12
|
-
|
13
|
-
def create
|
14
|
-
authorize! :create, Spree::Store
|
15
|
-
@store = Spree::Store.new(store_params)
|
16
|
-
@store.code = params[:store][:code]
|
17
|
-
if @store.save
|
18
|
-
respond_with(@store, status: 201, default_template: :show)
|
19
|
-
else
|
20
|
-
invalid_resource!(@store)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def update
|
25
|
-
authorize! :update, @store
|
26
|
-
if @store.update_attributes(store_params)
|
27
|
-
respond_with(@store, status: 200, default_template: :show)
|
28
|
-
else
|
29
|
-
invalid_resource!(@store)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def show
|
34
|
-
authorize! :read, @store
|
35
|
-
respond_with(@store)
|
36
|
-
end
|
37
|
-
|
38
|
-
def destroy
|
39
|
-
authorize! :destroy, @store
|
40
|
-
@store.destroy
|
41
|
-
respond_with(@store, status: 204)
|
42
|
-
end
|
43
|
-
|
44
|
-
private
|
45
|
-
|
46
|
-
def get_store
|
47
|
-
@store = Spree::Store.find(params[:id])
|
48
|
-
end
|
49
|
-
|
50
|
-
def store_params
|
51
|
-
params.require(:store).permit(permitted_store_attributes)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|