solidus_api 1.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of solidus_api might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/CHANGELOG.md +1 -0
- data/Gemfile +5 -0
- data/LICENSE +27 -0
- data/Rakefile +16 -0
- data/app/controllers/spree/api/addresses_controller.rb +43 -0
- data/app/controllers/spree/api/base_controller.rb +189 -0
- data/app/controllers/spree/api/checkouts_controller.rb +133 -0
- data/app/controllers/spree/api/classifications_controller.rb +18 -0
- data/app/controllers/spree/api/config_controller.rb +6 -0
- data/app/controllers/spree/api/countries_controller.rb +23 -0
- data/app/controllers/spree/api/credit_cards_controller.rb +25 -0
- data/app/controllers/spree/api/images_controller.rb +47 -0
- data/app/controllers/spree/api/inventory_units_controller.rb +52 -0
- data/app/controllers/spree/api/line_items_controller.rb +74 -0
- data/app/controllers/spree/api/option_types_controller.rb +49 -0
- data/app/controllers/spree/api/option_values_controller.rb +58 -0
- data/app/controllers/spree/api/orders_controller.rb +155 -0
- data/app/controllers/spree/api/payments_controller.rb +81 -0
- data/app/controllers/spree/api/product_properties_controller.rb +72 -0
- data/app/controllers/spree/api/products_controller.rb +129 -0
- data/app/controllers/spree/api/promotions_controller.rb +26 -0
- data/app/controllers/spree/api/properties_controller.rb +71 -0
- data/app/controllers/spree/api/return_authorizations_controller.rb +71 -0
- data/app/controllers/spree/api/shipments_controller.rb +172 -0
- data/app/controllers/spree/api/states_controller.rb +35 -0
- data/app/controllers/spree/api/stock_items_controller.rb +84 -0
- data/app/controllers/spree/api/stock_locations_controller.rb +50 -0
- data/app/controllers/spree/api/stock_movements_controller.rb +42 -0
- data/app/controllers/spree/api/stock_transfers_controller.rb +19 -0
- data/app/controllers/spree/api/store_credit_events_controller.rb +9 -0
- data/app/controllers/spree/api/stores_controller.rb +55 -0
- data/app/controllers/spree/api/taxonomies_controller.rb +64 -0
- data/app/controllers/spree/api/taxons_controller.rb +93 -0
- data/app/controllers/spree/api/transfer_items_controller.rb +42 -0
- data/app/controllers/spree/api/users_controller.rb +56 -0
- data/app/controllers/spree/api/variants_controller.rb +75 -0
- data/app/controllers/spree/api/zones_controller.rb +50 -0
- data/app/helpers/spree/api/api_helpers.rb +190 -0
- data/app/models/spree/api_configuration.rb +5 -0
- data/app/models/spree/option_value_decorator.rb +9 -0
- data/app/views/spree/api/addresses/show.v1.rabl +10 -0
- data/app/views/spree/api/adjustments/show.v1.rabl +4 -0
- data/app/views/spree/api/config/money.v1.rabl +2 -0
- data/app/views/spree/api/config/show.v1.rabl +2 -0
- data/app/views/spree/api/countries/index.v1.rabl +7 -0
- data/app/views/spree/api/countries/show.v1.rabl +5 -0
- data/app/views/spree/api/credit_cards/index.v1.rabl +7 -0
- data/app/views/spree/api/credit_cards/show.v1.rabl +3 -0
- data/app/views/spree/api/errors/gateway_error.v1.rabl +2 -0
- data/app/views/spree/api/errors/invalid_api_key.v1.rabl +2 -0
- data/app/views/spree/api/errors/invalid_resource.v1.rabl +3 -0
- data/app/views/spree/api/errors/must_specify_api_key.v1.rabl +2 -0
- data/app/views/spree/api/errors/not_found.v1.rabl +2 -0
- data/app/views/spree/api/errors/unauthorized.v1.rabl +2 -0
- data/app/views/spree/api/errors/variant_not_in_stock_transfer.v1.rabl +2 -0
- data/app/views/spree/api/images/index.v1.rabl +4 -0
- data/app/views/spree/api/images/show.v1.rabl +6 -0
- data/app/views/spree/api/inventory_units/show.rabl +2 -0
- data/app/views/spree/api/line_items/new.v1.rabl +3 -0
- data/app/views/spree/api/line_items/show.v1.rabl +15 -0
- data/app/views/spree/api/option_types/index.v1.rabl +3 -0
- data/app/views/spree/api/option_types/show.v1.rabl +5 -0
- data/app/views/spree/api/option_values/index.v1.rabl +3 -0
- data/app/views/spree/api/option_values/show.v1.rabl +2 -0
- data/app/views/spree/api/orders/address.v1.rabl +0 -0
- data/app/views/spree/api/orders/canceled.v1.rabl +0 -0
- data/app/views/spree/api/orders/cart.v1.rabl +0 -0
- data/app/views/spree/api/orders/complete.v1.rabl +0 -0
- data/app/views/spree/api/orders/could_not_apply_coupon.v1.rabl +2 -0
- data/app/views/spree/api/orders/could_not_transition.v1.rabl +3 -0
- data/app/views/spree/api/orders/expected_total_mismatch.v1.rabl +2 -0
- data/app/views/spree/api/orders/index.v1.rabl +7 -0
- data/app/views/spree/api/orders/invalid_shipping_method.v1.rabl +2 -0
- data/app/views/spree/api/orders/mine.v1.rabl +9 -0
- data/app/views/spree/api/orders/order.v1.rabl +9 -0
- data/app/views/spree/api/orders/payment.v1.rabl +3 -0
- data/app/views/spree/api/orders/show.v1.rabl +52 -0
- data/app/views/spree/api/payments/credit_over_limit.v1.rabl +2 -0
- data/app/views/spree/api/payments/index.v1.rabl +7 -0
- data/app/views/spree/api/payments/new.v1.rabl +5 -0
- data/app/views/spree/api/payments/show.v1.rabl +2 -0
- data/app/views/spree/api/payments/update_forbidden.v1.rabl +2 -0
- data/app/views/spree/api/product_properties/index.v1.rabl +7 -0
- data/app/views/spree/api/product_properties/new.v1.rabl +2 -0
- data/app/views/spree/api/product_properties/show.v1.rabl +2 -0
- data/app/views/spree/api/products/index.v1.rabl +9 -0
- data/app/views/spree/api/products/new.v1.rabl +3 -0
- data/app/views/spree/api/products/product.v1.rabl +1 -0
- data/app/views/spree/api/products/show.v1.rabl +31 -0
- data/app/views/spree/api/promotions/handler.v1.rabl +5 -0
- data/app/views/spree/api/promotions/show.v1.rabl +2 -0
- data/app/views/spree/api/properties/index.v1.rabl +7 -0
- data/app/views/spree/api/properties/new.v1.rabl +2 -0
- data/app/views/spree/api/properties/show.v1.rabl +2 -0
- data/app/views/spree/api/return_authorizations/index.v1.rabl +7 -0
- data/app/views/spree/api/return_authorizations/new.v1.rabl +3 -0
- data/app/views/spree/api/return_authorizations/show.v1.rabl +2 -0
- data/app/views/spree/api/shared/stock_location_required.v1.rabl +2 -0
- data/app/views/spree/api/shipments/big.v1.rabl +48 -0
- data/app/views/spree/api/shipments/cannot_ready_shipment.v1.rabl +2 -0
- data/app/views/spree/api/shipments/mine.v1.rabl +9 -0
- data/app/views/spree/api/shipments/show.v1.rabl +32 -0
- data/app/views/spree/api/shipments/small.v1.rabl +37 -0
- data/app/views/spree/api/shipping_rates/show.v1.rabl +2 -0
- data/app/views/spree/api/states/index.v1.rabl +14 -0
- data/app/views/spree/api/states/show.v1.rabl +2 -0
- data/app/views/spree/api/stock_items/index.v1.rabl +7 -0
- data/app/views/spree/api/stock_items/show.v1.rabl +5 -0
- data/app/views/spree/api/stock_locations/index.v1.rabl +7 -0
- data/app/views/spree/api/stock_locations/show.v1.rabl +8 -0
- data/app/views/spree/api/stock_movements/index.v1.rabl +7 -0
- data/app/views/spree/api/stock_movements/show.v1.rabl +5 -0
- data/app/views/spree/api/stock_transfers/receive.v1.rabl +5 -0
- data/app/views/spree/api/store_credit_events/mine.v1.rabl +10 -0
- data/app/views/spree/api/stores/index.v1.rabl +4 -0
- data/app/views/spree/api/stores/show.v1.rabl +2 -0
- data/app/views/spree/api/taxonomies/index.v1.rabl +7 -0
- data/app/views/spree/api/taxonomies/jstree.rabl +8 -0
- data/app/views/spree/api/taxonomies/nested.v1.rabl +11 -0
- data/app/views/spree/api/taxonomies/new.v1.rabl +3 -0
- data/app/views/spree/api/taxonomies/show.v1.rabl +15 -0
- data/app/views/spree/api/taxons/index.v1.rabl +12 -0
- data/app/views/spree/api/taxons/jstree.rabl +8 -0
- data/app/views/spree/api/taxons/new.v1.rabl +3 -0
- data/app/views/spree/api/taxons/show.v1.rabl +6 -0
- data/app/views/spree/api/taxons/taxons.v1.rabl +5 -0
- data/app/views/spree/api/transfer_items/show.v1.rabl +6 -0
- data/app/views/spree/api/users/index.v1.rabl +7 -0
- data/app/views/spree/api/users/new.v1.rabl +3 -0
- data/app/views/spree/api/users/show.v1.rabl +10 -0
- data/app/views/spree/api/variants/big.v1.rabl +17 -0
- data/app/views/spree/api/variants/index.v1.rabl +9 -0
- data/app/views/spree/api/variants/new.v1.rabl +2 -0
- data/app/views/spree/api/variants/show.v1.rabl +3 -0
- data/app/views/spree/api/variants/small.v1.rabl +17 -0
- data/app/views/spree/api/zones/index.v1.rabl +7 -0
- data/app/views/spree/api/zones/show.v1.rabl +6 -0
- data/config/initializers/metal_load_paths.rb +1 -0
- data/config/locales/en.yml +29 -0
- data/config/routes.rb +139 -0
- data/db/migrate/20100107141738_add_api_key_to_spree_users.rb +7 -0
- data/db/migrate/20120411123334_resize_api_key_field.rb +7 -0
- data/db/migrate/20120530054546_rename_api_key_to_spree_api_key.rb +7 -0
- data/db/migrate/20131017162334_add_index_to_user_spree_api_key.rb +7 -0
- data/lib/solidus_api.rb +1 -0
- data/lib/spree/api/engine.rb +38 -0
- data/lib/spree/api/responders/rabl_template.rb +31 -0
- data/lib/spree/api/responders.rb +11 -0
- data/lib/spree/api/testing_support/caching.rb +10 -0
- data/lib/spree/api/testing_support/helpers.rb +44 -0
- data/lib/spree/api/testing_support/setup.rb +16 -0
- data/lib/spree/api.rb +10 -0
- data/lib/spree_api.rb +3 -0
- data/script/rails +9 -0
- data/solidus_api.gemspec +21 -0
- data/spec/controllers/spree/api/addresses_controller_spec.rb +56 -0
- data/spec/controllers/spree/api/base_controller_spec.rb +164 -0
- data/spec/controllers/spree/api/checkouts_controller_spec.rb +386 -0
- data/spec/controllers/spree/api/classifications_controller_spec.rb +48 -0
- data/spec/controllers/spree/api/config_controller_spec.rb +23 -0
- data/spec/controllers/spree/api/countries_controller_spec.rb +48 -0
- data/spec/controllers/spree/api/credit_cards_controller_spec.rb +80 -0
- data/spec/controllers/spree/api/images_controller_spec.rb +93 -0
- data/spec/controllers/spree/api/inventory_units_controller_spec.rb +50 -0
- data/spec/controllers/spree/api/line_items_controller_spec.rb +186 -0
- data/spec/controllers/spree/api/option_types_controller_spec.rb +116 -0
- data/spec/controllers/spree/api/option_values_controller_spec.rb +135 -0
- data/spec/controllers/spree/api/orders_controller_spec.rb +759 -0
- data/spec/controllers/spree/api/payments_controller_spec.rb +254 -0
- data/spec/controllers/spree/api/product_properties_controller_spec.rb +116 -0
- data/spec/controllers/spree/api/products_controller_spec.rb +454 -0
- data/spec/controllers/spree/api/promotion_application_spec.rb +50 -0
- data/spec/controllers/spree/api/promotions_controller_spec.rb +64 -0
- data/spec/controllers/spree/api/properties_controller_spec.rb +102 -0
- data/spec/controllers/spree/api/return_authorizations_controller_spec.rb +173 -0
- data/spec/controllers/spree/api/shipments_controller_spec.rb +252 -0
- data/spec/controllers/spree/api/states_controller_spec.rb +82 -0
- data/spec/controllers/spree/api/stock_items_controller_spec.rb +307 -0
- data/spec/controllers/spree/api/stock_locations_controller_spec.rb +172 -0
- data/spec/controllers/spree/api/stock_movements_controller_spec.rb +84 -0
- data/spec/controllers/spree/api/stock_transfers_controller_spec.rb +83 -0
- data/spec/controllers/spree/api/store_credit_events_controller_spec.rb +68 -0
- data/spec/controllers/spree/api/stores_controller_spec.rb +133 -0
- data/spec/controllers/spree/api/taxonomies_controller_spec.rb +114 -0
- data/spec/controllers/spree/api/taxons_controller_spec.rb +177 -0
- data/spec/controllers/spree/api/transfer_items_controller_spec.rb +152 -0
- data/spec/controllers/spree/api/unauthenticated_products_controller_spec.rb +26 -0
- data/spec/controllers/spree/api/users_controller_spec.rb +153 -0
- data/spec/controllers/spree/api/variants_controller_spec.rb +235 -0
- data/spec/controllers/spree/api/zones_controller_spec.rb +115 -0
- data/spec/features/checkout_spec.rb +187 -0
- data/spec/fixtures/thinking-cat.jpg +0 -0
- data/spec/models/spree/legacy_user_spec.rb +45 -0
- data/spec/requests/rabl_cache_spec.rb +32 -0
- data/spec/shared_examples/protect_product_actions.rb +17 -0
- data/spec/spec_helper.rb +60 -0
- data/spec/support/controller_hacks.rb +38 -0
- data/spec/support/database_cleaner.rb +14 -0
- data/spec/support/have_attributes_matcher.rb +13 -0
- metadata +334 -0
@@ -0,0 +1,71 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
class PropertiesController < Spree::Api::BaseController
|
4
|
+
|
5
|
+
before_action :find_property, only: [:show, :update, :destroy]
|
6
|
+
|
7
|
+
def index
|
8
|
+
@properties = Spree::Property.accessible_by(current_ability, :read)
|
9
|
+
|
10
|
+
if params[:ids]
|
11
|
+
ids = params[:ids].split(",").flatten
|
12
|
+
@properties = @properties.where(:id => ids)
|
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
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
class ReturnAuthorizationsController < Spree::Api::BaseController
|
4
|
+
before_filter :load_order
|
5
|
+
around_filter :lock_order, only: [:create, :update, :destroy, :add, :receive, :cancel]
|
6
|
+
|
7
|
+
def create
|
8
|
+
authorize! :create, ReturnAuthorization
|
9
|
+
@return_authorization = @order.return_authorizations.build(return_authorization_params)
|
10
|
+
if @return_authorization.save
|
11
|
+
respond_with(@return_authorization, status: 201, default_template: :show)
|
12
|
+
else
|
13
|
+
invalid_resource!(@return_authorization)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def destroy
|
18
|
+
@return_authorization = @order.return_authorizations.accessible_by(current_ability, :destroy).find(params[:id])
|
19
|
+
@return_authorization.destroy
|
20
|
+
respond_with(@return_authorization, status: 204)
|
21
|
+
end
|
22
|
+
|
23
|
+
def index
|
24
|
+
authorize! :admin, ReturnAuthorization
|
25
|
+
@return_authorizations = @order.return_authorizations.accessible_by(current_ability, :read).
|
26
|
+
ransack(params[:q]).result.
|
27
|
+
page(params[:page]).per(params[:per_page])
|
28
|
+
respond_with(@return_authorizations)
|
29
|
+
end
|
30
|
+
|
31
|
+
def new
|
32
|
+
authorize! :admin, ReturnAuthorization
|
33
|
+
end
|
34
|
+
|
35
|
+
def show
|
36
|
+
authorize! :admin, ReturnAuthorization
|
37
|
+
@return_authorization = @order.return_authorizations.accessible_by(current_ability, :read).find(params[:id])
|
38
|
+
respond_with(@return_authorization)
|
39
|
+
end
|
40
|
+
|
41
|
+
def update
|
42
|
+
@return_authorization = @order.return_authorizations.accessible_by(current_ability, :update).find(params[:id])
|
43
|
+
if @return_authorization.update_attributes(return_authorization_params)
|
44
|
+
respond_with(@return_authorization, default_template: :show)
|
45
|
+
else
|
46
|
+
invalid_resource!(@return_authorization)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def cancel
|
51
|
+
@return_authorization = @order.return_authorizations.accessible_by(current_ability, :update).find(params[:id])
|
52
|
+
if @return_authorization.cancel
|
53
|
+
respond_with @return_authorization, default_template: :show
|
54
|
+
else
|
55
|
+
invalid_resource!(@return_authorization)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def load_order
|
62
|
+
@order ||= Spree::Order.find_by!(number: order_id)
|
63
|
+
authorize! :read, @order
|
64
|
+
end
|
65
|
+
|
66
|
+
def return_authorization_params
|
67
|
+
params.require(:return_authorization).permit(permitted_return_authorization_attributes)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,172 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
class ShipmentsController < Spree::Api::BaseController
|
4
|
+
before_filter :find_order_on_create, only: :create
|
5
|
+
before_filter :find_shipment, only: [:update, :ship, :ready, :add, :remove]
|
6
|
+
before_action :load_transfer_params, only: [:transfer_to_location, :transfer_to_shipment]
|
7
|
+
around_filter :lock_order, except: [:mine]
|
8
|
+
before_filter :update_shipment, only: [:ship, :ready, :add, :remove]
|
9
|
+
|
10
|
+
def mine
|
11
|
+
if current_api_user
|
12
|
+
@shipments = Spree::Shipment
|
13
|
+
.reverse_chronological
|
14
|
+
.joins(:order)
|
15
|
+
.where(spree_orders: {user_id: current_api_user.id})
|
16
|
+
.includes(mine_includes)
|
17
|
+
.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
18
|
+
else
|
19
|
+
render "spree/api/errors/unauthorized", status: :unauthorized
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def create
|
24
|
+
# TODO Can remove conditional here once deprecated #find_order is removed.
|
25
|
+
unless @order.present?
|
26
|
+
@order = Spree::Order.find_by!(number: params[:shipment][:order_id])
|
27
|
+
authorize! :read, @order
|
28
|
+
end
|
29
|
+
authorize! :create, Shipment
|
30
|
+
quantity = params[:quantity].to_i
|
31
|
+
@shipment = @order.shipments.create(stock_location_id: params.fetch(:stock_location_id))
|
32
|
+
@order.contents.add(variant, quantity, {shipment: @shipment})
|
33
|
+
|
34
|
+
@shipment.save!
|
35
|
+
|
36
|
+
respond_with(@shipment.reload, default_template: :show)
|
37
|
+
end
|
38
|
+
|
39
|
+
def update
|
40
|
+
@shipment.update_attributes_and_order(shipment_params)
|
41
|
+
|
42
|
+
respond_with(@shipment.reload, default_template: :show)
|
43
|
+
end
|
44
|
+
|
45
|
+
def ready
|
46
|
+
unless @shipment.ready?
|
47
|
+
if @shipment.can_ready?
|
48
|
+
@shipment.ready!
|
49
|
+
else
|
50
|
+
render 'spree/api/shipments/cannot_ready_shipment', status: 422 and return
|
51
|
+
end
|
52
|
+
end
|
53
|
+
respond_with(@shipment, default_template: :show)
|
54
|
+
end
|
55
|
+
|
56
|
+
def ship
|
57
|
+
authorize! :ship, @shipment
|
58
|
+
unless @shipment.shipped?
|
59
|
+
@shipment.suppress_mailer = (params[:send_mailer] == 'false')
|
60
|
+
@shipment.ship!
|
61
|
+
end
|
62
|
+
respond_with(@shipment, default_template: :show)
|
63
|
+
end
|
64
|
+
|
65
|
+
def add
|
66
|
+
quantity = params[:quantity].to_i
|
67
|
+
|
68
|
+
@shipment.order.contents.add(variant, quantity, {shipment: @shipment})
|
69
|
+
|
70
|
+
respond_with(@shipment, default_template: :show)
|
71
|
+
end
|
72
|
+
|
73
|
+
def remove
|
74
|
+
quantity = params[:quantity].to_i
|
75
|
+
|
76
|
+
@shipment.order.contents.remove(variant, quantity, {shipment: @shipment})
|
77
|
+
@shipment.reload if @shipment.persisted?
|
78
|
+
respond_with(@shipment, default_template: :show)
|
79
|
+
end
|
80
|
+
|
81
|
+
def transfer_to_location
|
82
|
+
@stock_location = Spree::StockLocation.find(params[:stock_location_id])
|
83
|
+
@original_shipment.transfer_to_location(@variant, @quantity, @stock_location)
|
84
|
+
render json: {success: true, message: Spree.t(:shipment_transfer_success)}, status: 201
|
85
|
+
end
|
86
|
+
|
87
|
+
def transfer_to_shipment
|
88
|
+
@target_shipment = Spree::Shipment.find_by!(number: params[:target_shipment_number])
|
89
|
+
@original_shipment.transfer_to_shipment(@variant, @quantity, @target_shipment)
|
90
|
+
render json: {success: true, message: Spree.t(:shipment_transfer_success)}, status: 201
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
|
95
|
+
def load_transfer_params
|
96
|
+
@original_shipment = Spree::Shipment.where(number: params[:original_shipment_number]).first
|
97
|
+
@order = @original_shipment.order
|
98
|
+
@variant = Spree::Variant.find(params[:variant_id])
|
99
|
+
@quantity = params[:quantity].to_i
|
100
|
+
authorize! :read, @original_shipment
|
101
|
+
authorize! :create, Shipment
|
102
|
+
end
|
103
|
+
|
104
|
+
def find_order_on_create
|
105
|
+
# TODO Can remove conditional here once deprecated #find_order is removed.
|
106
|
+
unless @order.present?
|
107
|
+
@order = Spree::Order.find_by!(number: params[:shipment][:order_id])
|
108
|
+
authorize! :read, @order
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def find_shipment
|
113
|
+
if @order.present?
|
114
|
+
@shipment = @order.shipments.accessible_by(current_ability, :update).find_by!(number: params[:id])
|
115
|
+
else
|
116
|
+
@shipment = Spree::Shipment.accessible_by(current_ability, :update).readonly(false).find_by!(number: params[:id])
|
117
|
+
@order = @shipment.order
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def update_shipment
|
122
|
+
@shipment.update_attributes(shipment_params)
|
123
|
+
@shipment.reload
|
124
|
+
end
|
125
|
+
|
126
|
+
def shipment_params
|
127
|
+
if params[:shipment] && !params[:shipment].empty?
|
128
|
+
params.require(:shipment).permit(permitted_shipment_attributes)
|
129
|
+
else
|
130
|
+
{}
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def variant
|
135
|
+
@variant ||= Spree::Variant.unscoped.find(params.fetch(:variant_id))
|
136
|
+
end
|
137
|
+
|
138
|
+
def mine_includes
|
139
|
+
{
|
140
|
+
order: {
|
141
|
+
bill_address: {
|
142
|
+
state: {},
|
143
|
+
country: {},
|
144
|
+
},
|
145
|
+
ship_address: {
|
146
|
+
state: {},
|
147
|
+
country: {},
|
148
|
+
},
|
149
|
+
adjustments: {},
|
150
|
+
payments: {
|
151
|
+
order: {},
|
152
|
+
payment_method: {},
|
153
|
+
},
|
154
|
+
},
|
155
|
+
inventory_units: {
|
156
|
+
line_item: {
|
157
|
+
product: {},
|
158
|
+
variant: {},
|
159
|
+
},
|
160
|
+
variant: {
|
161
|
+
product: {},
|
162
|
+
default_price: {},
|
163
|
+
option_values: {
|
164
|
+
option_type: {},
|
165
|
+
},
|
166
|
+
},
|
167
|
+
},
|
168
|
+
}
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
@@ -0,0 +1,35 @@
|
|
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
|
+
respond_with(@states)
|
17
|
+
end
|
18
|
+
|
19
|
+
def show
|
20
|
+
@state = scope.find(params[:id])
|
21
|
+
respond_with(@state)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
def scope
|
26
|
+
if params[:country_id]
|
27
|
+
@country = Country.accessible_by(current_ability, :read).find(params[:country_id])
|
28
|
+
return @country.states.accessible_by(current_ability, :read)
|
29
|
+
else
|
30
|
+
return State.accessible_by(current_ability, :read)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
class StockItemsController < Spree::Api::BaseController
|
4
|
+
before_filter :load_stock_location, only: [:index, :show, :create]
|
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, StockItem
|
18
|
+
|
19
|
+
@stock_item = scope.new(stock_item_params)
|
20
|
+
|
21
|
+
Spree::StockItem.transaction do
|
22
|
+
if @stock_item.save
|
23
|
+
adjust_stock_item_count_on_hand(count_on_hand_adjustment)
|
24
|
+
respond_with(@stock_item, status: 201, default_template: :show)
|
25
|
+
else
|
26
|
+
invalid_resource!(@stock_item)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def update
|
32
|
+
@stock_item = StockItem.accessible_by(current_ability, :update).find(params[:id])
|
33
|
+
@stock_location = @stock_item.stock_location
|
34
|
+
|
35
|
+
adjustment = count_on_hand_adjustment
|
36
|
+
params[:stock_item].delete(:count_on_hand)
|
37
|
+
adjustment -= @stock_item.count_on_hand if params[:stock_item][:force]
|
38
|
+
|
39
|
+
Spree::StockItem.transaction do
|
40
|
+
if @stock_item.update_attributes(stock_item_params)
|
41
|
+
adjust_stock_item_count_on_hand(adjustment)
|
42
|
+
respond_with(@stock_item, status: 200, default_template: :show)
|
43
|
+
else
|
44
|
+
invalid_resource!(@stock_item)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def destroy
|
50
|
+
@stock_item = StockItem.accessible_by(current_ability, :destroy).find(params[:id])
|
51
|
+
@stock_item.destroy
|
52
|
+
respond_with(@stock_item, status: 204)
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def load_stock_location
|
58
|
+
render 'spree/api/shared/stock_location_required', status: 422 and return unless params[:stock_location_id]
|
59
|
+
@stock_location ||= StockLocation.accessible_by(current_ability, action_name.to_sym).find(params[:stock_location_id])
|
60
|
+
end
|
61
|
+
|
62
|
+
def scope
|
63
|
+
includes = {:variant => [{ :option_values => :option_type }, :product] }
|
64
|
+
@stock_location.stock_items.accessible_by(current_ability, :read).includes(includes)
|
65
|
+
end
|
66
|
+
|
67
|
+
def stock_item_params
|
68
|
+
params.require(:stock_item).permit(permitted_stock_item_attributes)
|
69
|
+
end
|
70
|
+
|
71
|
+
def count_on_hand_adjustment
|
72
|
+
params[:stock_item][:count_on_hand].to_i
|
73
|
+
end
|
74
|
+
|
75
|
+
def adjust_stock_item_count_on_hand(count_on_hand_adjustment)
|
76
|
+
if @stock_item.count_on_hand + count_on_hand_adjustment < 0
|
77
|
+
raise StockLocation::InvalidMovementError.new(Spree.t(:stock_not_below_zero))
|
78
|
+
end
|
79
|
+
@stock_movement = @stock_location.move(@stock_item.variant, count_on_hand_adjustment, current_api_user)
|
80
|
+
@stock_item = @stock_movement.stock_item
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
class StockLocationsController < Spree::Api::BaseController
|
4
|
+
def index
|
5
|
+
authorize! :read, StockLocation
|
6
|
+
@stock_locations = 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, StockLocation
|
16
|
+
@stock_location = 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 ||= 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
|
@@ -0,0 +1,42 @@
|
|
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, 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, 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
|
+
@stock_location ||= StockLocation.accessible_by(current_ability, :read).find(params[:stock_location_id])
|
31
|
+
end
|
32
|
+
|
33
|
+
def scope
|
34
|
+
@stock_location.stock_movements.accessible_by(current_ability, :read)
|
35
|
+
end
|
36
|
+
|
37
|
+
def stock_movement_params
|
38
|
+
params.require(:stock_movement).permit(permitted_stock_movement_attributes)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
class StockTransfersController < Spree::Api::BaseController
|
4
|
+
def receive
|
5
|
+
authorize! :update, TransferItem
|
6
|
+
@stock_transfer = Spree::StockTransfer.accessible_by(current_ability, :update).find_by!(number: params[:id])
|
7
|
+
variant = Spree::Variant.accessible_by(current_ability, :show).find(params[:variant_id])
|
8
|
+
@transfer_item = @stock_transfer.transfer_items.find_by(variant: variant)
|
9
|
+
if @transfer_item.nil?
|
10
|
+
render "spree/api/errors/variant_not_in_stock_transfer", status: 422
|
11
|
+
elsif @transfer_item.update_attributes(received_quantity: @transfer_item.received_quantity + 1)
|
12
|
+
render 'spree/api/stock_transfers/receive', status: 200
|
13
|
+
else
|
14
|
+
invalid_resource!(@transfer_item)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
class Spree::Api::StoreCreditEventsController < Spree::Api::BaseController
|
2
|
+
def mine
|
3
|
+
if current_api_user
|
4
|
+
@store_credit_events = current_api_user.store_credit_events.exposed_events.page(params[:page]).per(params[:per_page]).reverse_chronological
|
5
|
+
else
|
6
|
+
render "spree/api/errors/unauthorized", status: :unauthorized
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
class StoresController < Spree::Api::BaseController
|
4
|
+
|
5
|
+
before_filter :get_store, except: [:index, :create]
|
6
|
+
|
7
|
+
def index
|
8
|
+
authorize! :read, Store
|
9
|
+
@stores = Store.accessible_by(current_ability, :read).all
|
10
|
+
respond_with(@stores)
|
11
|
+
end
|
12
|
+
|
13
|
+
def create
|
14
|
+
authorize! :create, Store
|
15
|
+
@store = 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 = 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
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
class TaxonomiesController < Spree::Api::BaseController
|
4
|
+
|
5
|
+
def index
|
6
|
+
respond_with(taxonomies)
|
7
|
+
end
|
8
|
+
|
9
|
+
def show
|
10
|
+
respond_with(taxonomy)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Because JSTree wants parameters in a *slightly* different format
|
14
|
+
def jstree
|
15
|
+
show
|
16
|
+
end
|
17
|
+
|
18
|
+
def create
|
19
|
+
authorize! :create, Taxonomy
|
20
|
+
@taxonomy = Taxonomy.new(taxonomy_params)
|
21
|
+
if @taxonomy.save
|
22
|
+
respond_with(@taxonomy, :status => 201, :default_template => :show)
|
23
|
+
else
|
24
|
+
invalid_resource!(@taxonomy)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def update
|
29
|
+
authorize! :update, taxonomy
|
30
|
+
if taxonomy.update_attributes(taxonomy_params)
|
31
|
+
respond_with(taxonomy, :status => 200, :default_template => :show)
|
32
|
+
else
|
33
|
+
invalid_resource!(taxonomy)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def destroy
|
38
|
+
authorize! :destroy, taxonomy
|
39
|
+
taxonomy.destroy
|
40
|
+
respond_with(taxonomy, :status => 204)
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
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
|
+
|
51
|
+
def taxonomy
|
52
|
+
@taxonomy ||= Taxonomy.accessible_by(current_ability, :read).find(params[:id])
|
53
|
+
end
|
54
|
+
|
55
|
+
def taxonomy_params
|
56
|
+
if params[:taxonomy] && !params[:taxonomy].empty?
|
57
|
+
params.require(:taxonomy).permit(permitted_taxonomy_attributes)
|
58
|
+
else
|
59
|
+
{}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|