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,93 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
class TaxonsController < Spree::Api::BaseController
|
4
|
+
def index
|
5
|
+
if taxonomy
|
6
|
+
@taxons = taxonomy.root.children
|
7
|
+
else
|
8
|
+
if params[:ids]
|
9
|
+
@taxons = Spree::Taxon.accessible_by(current_ability, :read).where(id: params[:ids].split(','))
|
10
|
+
else
|
11
|
+
@taxons = Spree::Taxon.accessible_by(current_ability, :read).order(:taxonomy_id, :lft).ransack(params[:q]).result
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
@taxons = @taxons.page(params[:page]).per(params[:per_page])
|
16
|
+
respond_with(@taxons)
|
17
|
+
end
|
18
|
+
|
19
|
+
def show
|
20
|
+
@taxon = taxon
|
21
|
+
respond_with(@taxon)
|
22
|
+
end
|
23
|
+
|
24
|
+
def jstree
|
25
|
+
show
|
26
|
+
end
|
27
|
+
|
28
|
+
def create
|
29
|
+
authorize! :create, Taxon
|
30
|
+
@taxon = Spree::Taxon.new(taxon_params)
|
31
|
+
@taxon.taxonomy_id = params[:taxonomy_id]
|
32
|
+
taxonomy = Spree::Taxonomy.find_by(id: params[:taxonomy_id])
|
33
|
+
|
34
|
+
if taxonomy.nil?
|
35
|
+
@taxon.errors[:taxonomy_id] = I18n.t(:invalid_taxonomy_id, scope: 'spree.api')
|
36
|
+
invalid_resource!(@taxon) and return
|
37
|
+
end
|
38
|
+
|
39
|
+
@taxon.parent_id = taxonomy.root.id unless params[:taxon][:parent_id]
|
40
|
+
|
41
|
+
if @taxon.save
|
42
|
+
respond_with(@taxon, status: 201, default_template: :show)
|
43
|
+
else
|
44
|
+
invalid_resource!(@taxon)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def update
|
49
|
+
authorize! :update, taxon
|
50
|
+
if taxon.update_attributes(taxon_params)
|
51
|
+
respond_with(taxon, status: 200, default_template: :show)
|
52
|
+
else
|
53
|
+
invalid_resource!(taxon)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def destroy
|
58
|
+
authorize! :destroy, taxon
|
59
|
+
taxon.destroy
|
60
|
+
respond_with(taxon, status: 204)
|
61
|
+
end
|
62
|
+
|
63
|
+
def products
|
64
|
+
# Returns the products sorted by their position with the classification
|
65
|
+
# Products#index does not do the sorting.
|
66
|
+
taxon = Spree::Taxon.find(params[:id])
|
67
|
+
@products = taxon.products.ransack(params[:q]).result
|
68
|
+
@products = @products.page(params[:page]).per(params[:per_page] || 500)
|
69
|
+
render "spree/api/products/index"
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def taxonomy
|
75
|
+
if params[:taxonomy_id].present?
|
76
|
+
@taxonomy ||= Spree::Taxonomy.accessible_by(current_ability, :read).find(params[:taxonomy_id])
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def taxon
|
81
|
+
@taxon ||= taxonomy.taxons.accessible_by(current_ability, :read).find(params[:id])
|
82
|
+
end
|
83
|
+
|
84
|
+
def taxon_params
|
85
|
+
if params[:taxon] && !params[:taxon].empty?
|
86
|
+
params.require(:taxon).permit(permitted_taxon_attributes)
|
87
|
+
else
|
88
|
+
{}
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
class TransferItemsController < Spree::Api::BaseController
|
4
|
+
def create
|
5
|
+
authorize! :create, TransferItem
|
6
|
+
stock_transfer = StockTransfer.accessible_by(current_ability, :update).find_by(number: params[:stock_transfer_id])
|
7
|
+
@transfer_item = stock_transfer.transfer_items.build(transfer_item_params)
|
8
|
+
if @transfer_item.save
|
9
|
+
respond_with(@transfer_item, status: 201, default_template: :show)
|
10
|
+
else
|
11
|
+
invalid_resource!(@transfer_item)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def update
|
16
|
+
authorize! :update, TransferItem
|
17
|
+
@transfer_item = TransferItem.accessible_by(current_ability, :update).find(params[:id])
|
18
|
+
if @transfer_item.update_attributes(transfer_item_params)
|
19
|
+
respond_with(@transfer_item, status: 200, default_template: :show)
|
20
|
+
else
|
21
|
+
invalid_resource!(@transfer_item)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def destroy
|
26
|
+
authorize! :destroy, TransferItem
|
27
|
+
@transfer_item = TransferItem.accessible_by(current_ability, :destroy).find(params[:id])
|
28
|
+
if @transfer_item.destroy
|
29
|
+
respond_with(@transfer_item, status: 200, default_template: :show)
|
30
|
+
else
|
31
|
+
invalid_resource!(@transfer_item)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def transfer_item_params
|
38
|
+
params.require(:transfer_item).permit(permitted_transfer_item_attributes)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
class UsersController < Spree::Api::BaseController
|
4
|
+
|
5
|
+
def index
|
6
|
+
@users = Spree.user_class.accessible_by(current_ability,:read).ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
7
|
+
respond_with(@users)
|
8
|
+
end
|
9
|
+
|
10
|
+
def show
|
11
|
+
respond_with(user)
|
12
|
+
end
|
13
|
+
|
14
|
+
def new
|
15
|
+
end
|
16
|
+
|
17
|
+
def create
|
18
|
+
authorize! :create, Spree.user_class
|
19
|
+
@user = Spree.user_class.new(user_params)
|
20
|
+
if @user.save
|
21
|
+
respond_with(@user, :status => 201, :default_template => :show)
|
22
|
+
else
|
23
|
+
invalid_resource!(@user)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def update
|
28
|
+
authorize! :update, user
|
29
|
+
if user.update_attributes(user_params)
|
30
|
+
respond_with(user, :status => 200, :default_template => :show)
|
31
|
+
else
|
32
|
+
invalid_resource!(user)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def destroy
|
37
|
+
authorize! :destroy, user
|
38
|
+
user.destroy
|
39
|
+
respond_with(user, :status => 204)
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def user
|
45
|
+
@user ||= Spree.user_class.accessible_by(current_ability, :read).find(params[:id])
|
46
|
+
end
|
47
|
+
|
48
|
+
def user_params
|
49
|
+
params.require(:user).permit(permitted_user_attributes |
|
50
|
+
[bill_address_attributes: permitted_address_attributes,
|
51
|
+
ship_address_attributes: permitted_address_attributes])
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
class VariantsController < Spree::Api::BaseController
|
4
|
+
before_action :product
|
5
|
+
|
6
|
+
def create
|
7
|
+
authorize! :create, Variant
|
8
|
+
@variant = scope.new(variant_params)
|
9
|
+
if @variant.save
|
10
|
+
respond_with(@variant, status: 201, default_template: :show)
|
11
|
+
else
|
12
|
+
invalid_resource!(@variant)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def destroy
|
17
|
+
@variant = scope.accessible_by(current_ability, :destroy).find(params[:id])
|
18
|
+
@variant.destroy
|
19
|
+
respond_with(@variant, status: 204)
|
20
|
+
end
|
21
|
+
|
22
|
+
# The lazyloaded associations here are pretty much attached to which nodes
|
23
|
+
# we render on the view so we better update it any time a node is included
|
24
|
+
# or removed from the views.
|
25
|
+
def index
|
26
|
+
@variants = scope.includes({ option_values: :option_type }, :product, :default_price, :images, { stock_items: :stock_location })
|
27
|
+
.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
28
|
+
respond_with(@variants)
|
29
|
+
end
|
30
|
+
|
31
|
+
def new
|
32
|
+
end
|
33
|
+
|
34
|
+
def show
|
35
|
+
@variant = scope.includes({ option_values: :option_type }, :option_values, :product, :default_price, :images, { stock_items: :stock_location })
|
36
|
+
.find(params[:id])
|
37
|
+
respond_with(@variant)
|
38
|
+
end
|
39
|
+
|
40
|
+
def update
|
41
|
+
@variant = scope.accessible_by(current_ability, :update).find(params[:id])
|
42
|
+
if @variant.update_attributes(variant_params)
|
43
|
+
respond_with(@variant, status: 200, default_template: :show)
|
44
|
+
else
|
45
|
+
invalid_resource!(@product)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
def product
|
51
|
+
@product ||= Spree::Product.accessible_by(current_ability, :read).friendly.find(params[:product_id]) if params[:product_id]
|
52
|
+
end
|
53
|
+
|
54
|
+
def scope
|
55
|
+
if @product
|
56
|
+
variants = @product.variants_including_master
|
57
|
+
else
|
58
|
+
variants = Variant
|
59
|
+
end
|
60
|
+
|
61
|
+
if current_ability.can?(:manage, Variant) && params[:show_deleted]
|
62
|
+
variants = variants.with_deleted
|
63
|
+
end
|
64
|
+
|
65
|
+
variants = variants.accessible_by(current_ability, :read)
|
66
|
+
variants = variants.in_stock if params[:in_stock_only] || cannot?(:view_out_of_stock, Spree::Variant)
|
67
|
+
variants
|
68
|
+
end
|
69
|
+
|
70
|
+
def variant_params
|
71
|
+
params.require(:variant).permit(permitted_variant_attributes)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
class ZonesController < Spree::Api::BaseController
|
4
|
+
|
5
|
+
def create
|
6
|
+
authorize! :create, Zone
|
7
|
+
@zone = Zone.new(map_nested_attributes_keys(Spree::Zone, zone_params))
|
8
|
+
if @zone.save
|
9
|
+
respond_with(@zone, :status => 201, :default_template => :show)
|
10
|
+
else
|
11
|
+
invalid_resource!(@zone)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def destroy
|
16
|
+
authorize! :destroy, zone
|
17
|
+
zone.destroy
|
18
|
+
respond_with(zone, :status => 204)
|
19
|
+
end
|
20
|
+
|
21
|
+
def index
|
22
|
+
@zones = Zone.accessible_by(current_ability, :read).order('name ASC').ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
23
|
+
respond_with(@zones)
|
24
|
+
end
|
25
|
+
|
26
|
+
def show
|
27
|
+
respond_with(zone)
|
28
|
+
end
|
29
|
+
|
30
|
+
def update
|
31
|
+
authorize! :update, zone
|
32
|
+
if zone.update_attributes(map_nested_attributes_keys(Spree::Zone, zone_params))
|
33
|
+
respond_with(zone, :status => 200, :default_template => :show)
|
34
|
+
else
|
35
|
+
invalid_resource!(zone)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def zone_params
|
42
|
+
params.require(:zone).permit!
|
43
|
+
end
|
44
|
+
|
45
|
+
def zone
|
46
|
+
@zone ||= Spree::Zone.accessible_by(current_ability, :read).find(params[:id])
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,190 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module ApiHelpers
|
4
|
+
ATTRIBUTES = [
|
5
|
+
:product_attributes,
|
6
|
+
:product_property_attributes,
|
7
|
+
:variant_attributes,
|
8
|
+
:image_attributes,
|
9
|
+
:option_value_attributes,
|
10
|
+
:order_attributes,
|
11
|
+
:line_item_attributes,
|
12
|
+
:option_type_attributes,
|
13
|
+
:payment_attributes,
|
14
|
+
:payment_method_attributes,
|
15
|
+
:shipment_attributes,
|
16
|
+
:taxonomy_attributes,
|
17
|
+
:taxon_attributes,
|
18
|
+
:address_attributes,
|
19
|
+
:country_attributes,
|
20
|
+
:state_attributes,
|
21
|
+
:adjustment_attributes,
|
22
|
+
:inventory_unit_attributes,
|
23
|
+
:return_authorization_attributes,
|
24
|
+
:creditcard_attributes,
|
25
|
+
:payment_source_attributes,
|
26
|
+
:user_attributes,
|
27
|
+
:property_attributes,
|
28
|
+
:stock_location_attributes,
|
29
|
+
:stock_movement_attributes,
|
30
|
+
:stock_item_attributes,
|
31
|
+
:promotion_attributes,
|
32
|
+
:store_attributes,
|
33
|
+
:store_credit_history_attributes,
|
34
|
+
:stock_transfer_attributes,
|
35
|
+
:transfer_item_attributes,
|
36
|
+
:transfer_item_variant_attributes
|
37
|
+
]
|
38
|
+
|
39
|
+
mattr_reader *ATTRIBUTES
|
40
|
+
|
41
|
+
def required_fields_for(model)
|
42
|
+
required_fields = model._validators.select do |field, validations|
|
43
|
+
validations.any? { |v| v.is_a?(ActiveModel::Validations::PresenceValidator) }
|
44
|
+
end.map(&:first) # get fields that are invalid
|
45
|
+
# Permalinks presence is validated, but are really automatically generated
|
46
|
+
# Therefore we shouldn't tell API clients that they MUST send one through
|
47
|
+
required_fields.map!(&:to_s).delete("permalink")
|
48
|
+
# Do not require slugs, either
|
49
|
+
required_fields.delete("slug")
|
50
|
+
required_fields
|
51
|
+
end
|
52
|
+
|
53
|
+
@@product_attributes = [
|
54
|
+
:id, :name, :description, :price, :display_price, :available_on,
|
55
|
+
:slug, :meta_description, :meta_keywords, :shipping_category_id,
|
56
|
+
:taxon_ids, :total_on_hand
|
57
|
+
]
|
58
|
+
|
59
|
+
@@product_property_attributes = [
|
60
|
+
:id, :product_id, :property_id, :value, :property_name
|
61
|
+
]
|
62
|
+
|
63
|
+
@@variant_attributes = [
|
64
|
+
:id, :name, :sku, :price, :weight, :height, :width, :depth, :is_master,
|
65
|
+
:slug, :description, :track_inventory
|
66
|
+
]
|
67
|
+
|
68
|
+
@@image_attributes = [
|
69
|
+
:id, :position, :attachment_content_type, :attachment_file_name, :type,
|
70
|
+
:attachment_updated_at, :attachment_width, :attachment_height, :alt
|
71
|
+
]
|
72
|
+
|
73
|
+
@@option_value_attributes = [
|
74
|
+
:id, :name, :presentation, :option_type_name, :option_type_id,
|
75
|
+
:option_type_presentation
|
76
|
+
]
|
77
|
+
|
78
|
+
@@order_attributes = [
|
79
|
+
:id, :number, :item_total, :total, :ship_total, :state, :adjustment_total,
|
80
|
+
:user_id, :created_at, :updated_at, :completed_at, :payment_total,
|
81
|
+
:shipment_state, :payment_state, :email, :special_instructions, :channel,
|
82
|
+
:included_tax_total, :additional_tax_total, :display_included_tax_total,
|
83
|
+
:display_additional_tax_total, :tax_total, :currency,
|
84
|
+
:covered_by_store_credit, :display_total_applicable_store_credit,
|
85
|
+
:order_total_after_store_credit, :display_order_total_after_store_credit,
|
86
|
+
:total_applicable_store_credit, :display_total_available_store_credit, :display_store_credit_remaining_after_capture
|
87
|
+
|
88
|
+
]
|
89
|
+
|
90
|
+
@@line_item_attributes = [:id, :quantity, :price, :variant_id]
|
91
|
+
|
92
|
+
@@option_type_attributes = [:id, :name, :presentation, :position]
|
93
|
+
|
94
|
+
@@payment_attributes = [
|
95
|
+
:id, :source_type, :source_id, :amount, :display_amount,
|
96
|
+
:payment_method_id, :response_code, :state, :avs_response, :created_at,
|
97
|
+
:updated_at
|
98
|
+
]
|
99
|
+
|
100
|
+
@@payment_method_attributes = [:id, :name, :description]
|
101
|
+
|
102
|
+
@@shipment_attributes = [:id, :tracking, :number, :cost, :shipped_at, :state]
|
103
|
+
|
104
|
+
@@taxonomy_attributes = [:id, :name]
|
105
|
+
|
106
|
+
@@taxon_attributes = [
|
107
|
+
:id, :name, :pretty_name, :permalink, :parent_id,
|
108
|
+
:taxonomy_id
|
109
|
+
]
|
110
|
+
|
111
|
+
@@inventory_unit_attributes = [
|
112
|
+
:id, :lock_version, :state, :variant_id, :shipment_id,
|
113
|
+
:return_authorization_id
|
114
|
+
]
|
115
|
+
|
116
|
+
@@return_authorization_attributes = [
|
117
|
+
:id, :number, :state, :order_id, :memo, :created_at, :updated_at
|
118
|
+
]
|
119
|
+
|
120
|
+
@@address_attributes = [
|
121
|
+
:id, :firstname, :lastname, :full_name, :address1, :address2, :city,
|
122
|
+
:zipcode, :phone, :company, :alternative_phone, :country_id, :state_id,
|
123
|
+
:state_name, :state_text
|
124
|
+
]
|
125
|
+
|
126
|
+
@@country_attributes = [:id, :iso_name, :iso, :iso3, :name, :numcode]
|
127
|
+
|
128
|
+
@@state_attributes = [:id, :name, :abbr, :country_id]
|
129
|
+
|
130
|
+
@@adjustment_attributes = [
|
131
|
+
:id, :source_type, :source_id, :adjustable_type, :adjustable_id,
|
132
|
+
:originator_type, :originator_id, :amount, :label, :mandatory, :promotion_code,
|
133
|
+
:locked, :eligible, :created_at, :updated_at
|
134
|
+
]
|
135
|
+
|
136
|
+
@@creditcard_attributes = [
|
137
|
+
:id, :month, :year, :cc_type, :last_digits, :name,
|
138
|
+
]
|
139
|
+
|
140
|
+
@@payment_source_attributes = [
|
141
|
+
:id, :month, :year, :cc_type, :last_digits, :name
|
142
|
+
]
|
143
|
+
|
144
|
+
@@user_attributes = [:id, :email, :created_at, :updated_at]
|
145
|
+
|
146
|
+
@@property_attributes = [:id, :name, :presentation]
|
147
|
+
|
148
|
+
@@stock_location_attributes = [
|
149
|
+
:id, :name, :address1, :address2, :city, :state_id, :state_name,
|
150
|
+
:country_id, :zipcode, :phone, :active
|
151
|
+
]
|
152
|
+
|
153
|
+
@@stock_movement_attributes = [:id, :quantity, :stock_item_id]
|
154
|
+
|
155
|
+
@@stock_item_attributes = [
|
156
|
+
:id, :count_on_hand, :backorderable, :lock_version, :stock_location_id,
|
157
|
+
:variant_id
|
158
|
+
]
|
159
|
+
|
160
|
+
@@promotion_attributes = [
|
161
|
+
:id, :name, :description, :expires_at, :starts_at, :type, :usage_limit,
|
162
|
+
:match_policy, :advertise, :path
|
163
|
+
]
|
164
|
+
|
165
|
+
@@store_attributes = [
|
166
|
+
:id, :name, :url, :meta_description, :meta_keywords, :seo_title,
|
167
|
+
:mail_from_address, :default_currency, :code, :default
|
168
|
+
]
|
169
|
+
|
170
|
+
@@store_credit_history_attributes = [
|
171
|
+
:display_amount, :display_user_total_amount, :display_action,
|
172
|
+
:display_event_date
|
173
|
+
]
|
174
|
+
|
175
|
+
@@stock_transfer_attributes = [:id, :number]
|
176
|
+
|
177
|
+
@@transfer_item_attributes = [:id, :expected_quantity, :received_quantity]
|
178
|
+
|
179
|
+
@@transfer_item_variant_attributes = []
|
180
|
+
|
181
|
+
def variant_attributes
|
182
|
+
if @current_user_roles && @current_user_roles.include?("admin")
|
183
|
+
@@variant_attributes + [:cost_price]
|
184
|
+
else
|
185
|
+
@@variant_attributes
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
object @line_item
|
2
|
+
cache [I18n.locale, root_object]
|
3
|
+
attributes *line_item_attributes
|
4
|
+
node(:single_display_amount) { |li| li.single_display_amount.to_s }
|
5
|
+
node(:display_amount) { |li| li.display_amount.to_s }
|
6
|
+
node(:total) { |li| li.total }
|
7
|
+
child :variant do
|
8
|
+
extends "spree/api/variants/small"
|
9
|
+
attributes :product_id
|
10
|
+
child(:images => :images) { extends "spree/api/images/show" }
|
11
|
+
end
|
12
|
+
|
13
|
+
child :adjustments => :adjustments do
|
14
|
+
extends "spree/api/adjustments/show"
|
15
|
+
end
|
File without changes
|
File without changes
|
File without changes
|