goca-spree-api 3.1.14.rails.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +5 -0
- data/LICENSE +26 -0
- data/Rakefile +16 -0
- data/app/controllers/spree/api/base_controller.rb +167 -0
- 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 +148 -0
- data/app/controllers/spree/api/v1/payments_controller.rb +83 -0
- data/app/controllers/spree/api/v1/product_properties_controller.rb +70 -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 +173 -0
- data/app/models/spree/api_configuration.rb +5 -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/v1/addresses/show.v1.rabl +10 -0
- data/app/views/spree/api/v1/adjustments/show.v1.rabl +4 -0
- data/app/views/spree/api/v1/config/money.v1.rabl +2 -0
- data/app/views/spree/api/v1/config/show.v1.rabl +2 -0
- data/app/views/spree/api/v1/countries/index.v1.rabl +7 -0
- data/app/views/spree/api/v1/countries/show.v1.rabl +5 -0
- data/app/views/spree/api/v1/credit_cards/index.v1.rabl +7 -0
- data/app/views/spree/api/v1/credit_cards/show.v1.rabl +3 -0
- data/app/views/spree/api/v1/images/index.v1.rabl +4 -0
- data/app/views/spree/api/v1/images/new.v1.rabl +3 -0
- data/app/views/spree/api/v1/images/show.v1.rabl +6 -0
- data/app/views/spree/api/v1/inventory_units/show.rabl +2 -0
- data/app/views/spree/api/v1/line_items/new.v1.rabl +3 -0
- data/app/views/spree/api/v1/line_items/show.v1.rabl +15 -0
- 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/v1/option_types/show.v1.rabl +5 -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/v1/option_values/show.v1.rabl +2 -0
- data/app/views/spree/api/v1/orders/address.v1.rabl +0 -0
- data/app/views/spree/api/v1/orders/canceled.v1.rabl +0 -0
- data/app/views/spree/api/v1/orders/cart.v1.rabl +0 -0
- data/app/views/spree/api/v1/orders/complete.v1.rabl +0 -0
- data/app/views/spree/api/v1/orders/could_not_apply_coupon.v1.rabl +2 -0
- data/app/views/spree/api/v1/orders/could_not_transition.v1.rabl +3 -0
- data/app/views/spree/api/v1/orders/index.v1.rabl +7 -0
- data/app/views/spree/api/v1/orders/invalid_shipping_method.v1.rabl +2 -0
- data/app/views/spree/api/v1/orders/mine.v1.rabl +9 -0
- data/app/views/spree/api/v1/orders/order.v1.rabl +10 -0
- data/app/views/spree/api/v1/orders/payment.v1.rabl +3 -0
- data/app/views/spree/api/v1/orders/show.v1.rabl +51 -0
- data/app/views/spree/api/v1/payments/credit_over_limit.v1.rabl +2 -0
- data/app/views/spree/api/v1/payments/index.v1.rabl +7 -0
- data/app/views/spree/api/v1/payments/new.v1.rabl +5 -0
- data/app/views/spree/api/v1/payments/show.v1.rabl +2 -0
- data/app/views/spree/api/v1/payments/update_forbidden.v1.rabl +2 -0
- data/app/views/spree/api/v1/product_properties/index.v1.rabl +7 -0
- data/app/views/spree/api/v1/product_properties/new.v1.rabl +2 -0
- data/app/views/spree/api/v1/product_properties/show.v1.rabl +2 -0
- data/app/views/spree/api/v1/products/index.v1.rabl +9 -0
- data/app/views/spree/api/v1/products/new.v1.rabl +3 -0
- data/app/views/spree/api/v1/products/product.v1.rabl +1 -0
- data/app/views/spree/api/v1/products/show.v1.rabl +32 -0
- data/app/views/spree/api/v1/promotions/handler.v1.rabl +5 -0
- data/app/views/spree/api/v1/promotions/show.v1.rabl +2 -0
- data/app/views/spree/api/v1/properties/index.v1.rabl +7 -0
- data/app/views/spree/api/v1/properties/new.v1.rabl +2 -0
- data/app/views/spree/api/v1/properties/show.v1.rabl +2 -0
- data/app/views/spree/api/v1/return_authorizations/index.v1.rabl +7 -0
- data/app/views/spree/api/v1/return_authorizations/new.v1.rabl +3 -0
- data/app/views/spree/api/v1/return_authorizations/show.v1.rabl +2 -0
- data/app/views/spree/api/v1/shared/stock_location_required.v1.rabl +2 -0
- data/app/views/spree/api/v1/shipments/big.v1.rabl +48 -0
- data/app/views/spree/api/v1/shipments/cannot_ready_shipment.v1.rabl +2 -0
- data/app/views/spree/api/v1/shipments/mine.v1.rabl +9 -0
- data/app/views/spree/api/v1/shipments/show.v1.rabl +32 -0
- data/app/views/spree/api/v1/shipments/small.v1.rabl +37 -0
- data/app/views/spree/api/v1/shipping_rates/show.v1.rabl +2 -0
- data/app/views/spree/api/v1/states/index.v1.rabl +14 -0
- data/app/views/spree/api/v1/states/show.v1.rabl +2 -0
- data/app/views/spree/api/v1/stock_items/index.v1.rabl +7 -0
- data/app/views/spree/api/v1/stock_items/show.v1.rabl +5 -0
- data/app/views/spree/api/v1/stock_locations/index.v1.rabl +7 -0
- data/app/views/spree/api/v1/stock_locations/show.v1.rabl +8 -0
- data/app/views/spree/api/v1/stock_movements/index.v1.rabl +7 -0
- data/app/views/spree/api/v1/stock_movements/show.v1.rabl +5 -0
- data/app/views/spree/api/v1/stores/index.v1.rabl +4 -0
- data/app/views/spree/api/v1/stores/show.v1.rabl +2 -0
- data/app/views/spree/api/v1/taxonomies/index.v1.rabl +7 -0
- data/app/views/spree/api/v1/taxonomies/jstree.rabl +8 -0
- data/app/views/spree/api/v1/taxonomies/nested.v1.rabl +11 -0
- data/app/views/spree/api/v1/taxonomies/new.v1.rabl +3 -0
- data/app/views/spree/api/v1/taxonomies/show.v1.rabl +15 -0
- data/app/views/spree/api/v1/taxons/index.v1.rabl +12 -0
- data/app/views/spree/api/v1/taxons/jstree.rabl +8 -0
- data/app/views/spree/api/v1/taxons/new.v1.rabl +3 -0
- data/app/views/spree/api/v1/taxons/show.v1.rabl +6 -0
- data/app/views/spree/api/v1/taxons/taxons.v1.rabl +5 -0
- data/app/views/spree/api/v1/users/index.v1.rabl +7 -0
- data/app/views/spree/api/v1/users/new.v1.rabl +3 -0
- data/app/views/spree/api/v1/users/show.v1.rabl +10 -0
- data/app/views/spree/api/v1/variants/big.v1.rabl +14 -0
- data/app/views/spree/api/v1/variants/index.v1.rabl +9 -0
- data/app/views/spree/api/v1/variants/new.v1.rabl +2 -0
- data/app/views/spree/api/v1/variants/show.v1.rabl +3 -0
- data/app/views/spree/api/v1/variants/small.v1.rabl +17 -0
- data/app/views/spree/api/v1/zones/index.v1.rabl +7 -0
- data/app/views/spree/api/v1/zones/show.v1.rabl +6 -0
- data/config/initializers/metal_load_paths.rb +1 -0
- data/config/locales/en.yml +27 -0
- data/config/routes.rb +128 -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/spree/api/controller_setup.rb +20 -0
- data/lib/spree/api/engine.rb +35 -0
- data/lib/spree/api/responders/rabl_template.rb +30 -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 +2 -0
- data/script/rails +9 -0
- data/spec/fixtures/thinking-cat.jpg +0 -0
- data/spree_api.gemspec +20 -0
- metadata +221 -0
@@ -0,0 +1,60 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class UsersController < Spree::Api::BaseController
|
5
|
+
|
6
|
+
rescue_from Spree::Core::DestroyWithOrdersError, with: :error_during_processing
|
7
|
+
|
8
|
+
def index
|
9
|
+
@users = Spree.user_class.accessible_by(current_ability,:read).ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
10
|
+
respond_with(@users)
|
11
|
+
end
|
12
|
+
|
13
|
+
def show
|
14
|
+
respond_with(user)
|
15
|
+
end
|
16
|
+
|
17
|
+
def new
|
18
|
+
end
|
19
|
+
|
20
|
+
def create
|
21
|
+
authorize! :create, Spree.user_class
|
22
|
+
@user = Spree.user_class.new(user_params)
|
23
|
+
if @user.save
|
24
|
+
respond_with(@user, :status => 201, :default_template => :show)
|
25
|
+
else
|
26
|
+
invalid_resource!(@user)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def update
|
31
|
+
authorize! :update, user
|
32
|
+
if user.update_attributes(user_params)
|
33
|
+
respond_with(user, :status => 200, :default_template => :show)
|
34
|
+
else
|
35
|
+
invalid_resource!(user)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def destroy
|
40
|
+
authorize! :destroy, user
|
41
|
+
user.destroy
|
42
|
+
respond_with(user, :status => 204)
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def user
|
48
|
+
@user ||= Spree.user_class.accessible_by(current_ability, :read).find(params[:id])
|
49
|
+
end
|
50
|
+
|
51
|
+
def user_params
|
52
|
+
params.require(:user).permit(permitted_user_attributes |
|
53
|
+
[bill_address_attributes: permitted_address_attributes,
|
54
|
+
ship_address_attributes: permitted_address_attributes])
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class VariantsController < Spree::Api::BaseController
|
5
|
+
before_action :product
|
6
|
+
|
7
|
+
def create
|
8
|
+
authorize! :create, Variant
|
9
|
+
@variant = scope.new(variant_params)
|
10
|
+
if @variant.save
|
11
|
+
respond_with(@variant, status: 201, default_template: :show)
|
12
|
+
else
|
13
|
+
invalid_resource!(@variant)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def destroy
|
18
|
+
@variant = scope.accessible_by(current_ability, :destroy).find(params[:id])
|
19
|
+
@variant.destroy
|
20
|
+
respond_with(@variant, status: 204)
|
21
|
+
end
|
22
|
+
|
23
|
+
# The lazyloaded associations here are pretty much attached to which nodes
|
24
|
+
# we render on the view so we better update it any time a node is included
|
25
|
+
# or removed from the views.
|
26
|
+
def index
|
27
|
+
@variants = scope.includes({ option_values: :option_type }, :product, :default_price, :images, { stock_items: :stock_location })
|
28
|
+
.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
29
|
+
respond_with(@variants)
|
30
|
+
end
|
31
|
+
|
32
|
+
def new
|
33
|
+
end
|
34
|
+
|
35
|
+
def show
|
36
|
+
@variant = scope.includes({ option_values: :option_type }, :option_values, :product, :default_price, :images, { stock_items: :stock_location })
|
37
|
+
.find(params[:id])
|
38
|
+
respond_with(@variant)
|
39
|
+
end
|
40
|
+
|
41
|
+
def update
|
42
|
+
@variant = scope.accessible_by(current_ability, :update).find(params[:id])
|
43
|
+
if @variant.update_attributes(variant_params)
|
44
|
+
respond_with(@variant, status: 200, default_template: :show)
|
45
|
+
else
|
46
|
+
invalid_resource!(@product)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
def product
|
52
|
+
@product ||= Spree::Product.accessible_by(current_ability, :read).friendly.find(params[:product_id]) if params[:product_id]
|
53
|
+
end
|
54
|
+
|
55
|
+
def scope
|
56
|
+
if @product
|
57
|
+
variants = @product.variants_including_master
|
58
|
+
else
|
59
|
+
variants = Variant
|
60
|
+
end
|
61
|
+
|
62
|
+
if current_ability.can?(:manage, Variant) && params[:show_deleted]
|
63
|
+
variants = variants.with_deleted
|
64
|
+
end
|
65
|
+
|
66
|
+
variants.accessible_by(current_ability, :read)
|
67
|
+
end
|
68
|
+
|
69
|
+
def variant_params
|
70
|
+
params.require(:variant).permit(permitted_variant_attributes)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class ZonesController < Spree::Api::BaseController
|
5
|
+
|
6
|
+
def create
|
7
|
+
authorize! :create, Zone
|
8
|
+
@zone = Zone.new(map_nested_attributes_keys(Spree::Zone, zone_params))
|
9
|
+
if @zone.save
|
10
|
+
respond_with(@zone, :status => 201, :default_template => :show)
|
11
|
+
else
|
12
|
+
invalid_resource!(@zone)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def destroy
|
17
|
+
authorize! :destroy, zone
|
18
|
+
zone.destroy
|
19
|
+
respond_with(zone, :status => 204)
|
20
|
+
end
|
21
|
+
|
22
|
+
def index
|
23
|
+
@zones = Zone.accessible_by(current_ability, :read).order('name ASC').ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
24
|
+
respond_with(@zones)
|
25
|
+
end
|
26
|
+
|
27
|
+
def show
|
28
|
+
respond_with(zone)
|
29
|
+
end
|
30
|
+
|
31
|
+
def update
|
32
|
+
authorize! :update, zone
|
33
|
+
if zone.update_attributes(map_nested_attributes_keys(Spree::Zone, zone_params))
|
34
|
+
respond_with(zone, :status => 200, :default_template => :show)
|
35
|
+
else
|
36
|
+
invalid_resource!(zone)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
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
|
51
|
+
end
|
@@ -0,0 +1,173 @@
|
|
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
|
+
]
|
34
|
+
|
35
|
+
mattr_reader *ATTRIBUTES
|
36
|
+
|
37
|
+
def required_fields_for(model)
|
38
|
+
required_fields = model._validators.select do |field, validations|
|
39
|
+
validations.any? { |v| v.is_a?(ActiveModel::Validations::PresenceValidator) }
|
40
|
+
end.map(&:first) # get fields that are invalid
|
41
|
+
# Permalinks presence is validated, but are really automatically generated
|
42
|
+
# Therefore we shouldn't tell API clients that they MUST send one through
|
43
|
+
required_fields.map!(&:to_s).delete("permalink")
|
44
|
+
# Do not require slugs, either
|
45
|
+
required_fields.delete("slug")
|
46
|
+
required_fields
|
47
|
+
end
|
48
|
+
|
49
|
+
@@product_attributes = [
|
50
|
+
:id, :name, :description, :price, :display_price, :available_on,
|
51
|
+
:slug, :meta_description, :meta_keywords, :shipping_category_id,
|
52
|
+
:taxon_ids, :total_on_hand
|
53
|
+
]
|
54
|
+
|
55
|
+
@@product_property_attributes = [
|
56
|
+
:id, :product_id, :property_id, :value, :property_name
|
57
|
+
]
|
58
|
+
|
59
|
+
@@variant_attributes = [
|
60
|
+
:id, :name, :sku, :price, :weight, :height, :width, :depth, :is_master,
|
61
|
+
:slug, :description, :track_inventory
|
62
|
+
]
|
63
|
+
|
64
|
+
@@image_attributes = [
|
65
|
+
:id, :position, :attachment_content_type, :attachment_file_name, :type,
|
66
|
+
:attachment_updated_at, :attachment_width, :attachment_height, :alt
|
67
|
+
]
|
68
|
+
|
69
|
+
@@option_value_attributes = [
|
70
|
+
:id, :name, :presentation, :option_type_name, :option_type_id,
|
71
|
+
:option_type_presentation
|
72
|
+
]
|
73
|
+
|
74
|
+
@@order_attributes = [
|
75
|
+
:id, :number, :item_total, :total, :ship_total, :state, :adjustment_total,
|
76
|
+
:user_id, :created_at, :updated_at, :completed_at, :payment_total,
|
77
|
+
:shipment_state, :payment_state, :email, :special_instructions, :channel,
|
78
|
+
:included_tax_total, :additional_tax_total, :display_included_tax_total,
|
79
|
+
:display_additional_tax_total, :tax_total, :currency, :considered_risky,
|
80
|
+
:canceler_id
|
81
|
+
]
|
82
|
+
|
83
|
+
@@line_item_attributes = [:id, :quantity, :price, :variant_id]
|
84
|
+
|
85
|
+
@@option_type_attributes = [:id, :name, :presentation, :position]
|
86
|
+
|
87
|
+
@@payment_attributes = [
|
88
|
+
:id, :source_type, :source_id, :amount, :display_amount,
|
89
|
+
:payment_method_id, :state, :avs_response, :created_at,
|
90
|
+
:updated_at, :number
|
91
|
+
]
|
92
|
+
|
93
|
+
@@payment_method_attributes = [:id, :name, :description]
|
94
|
+
|
95
|
+
@@shipment_attributes = [:id, :tracking, :number, :cost, :shipped_at, :state]
|
96
|
+
|
97
|
+
@@taxonomy_attributes = [:id, :name]
|
98
|
+
|
99
|
+
@@taxon_attributes = [
|
100
|
+
:id, :name, :pretty_name, :permalink, :parent_id,
|
101
|
+
:taxonomy_id
|
102
|
+
]
|
103
|
+
|
104
|
+
@@inventory_unit_attributes = [
|
105
|
+
:id, :lock_version, :state, :variant_id, :shipment_id,
|
106
|
+
:return_authorization_id
|
107
|
+
]
|
108
|
+
|
109
|
+
@@return_authorization_attributes = [
|
110
|
+
:id, :number, :state, :order_id, :memo, :created_at, :updated_at
|
111
|
+
]
|
112
|
+
|
113
|
+
@@address_attributes = [
|
114
|
+
:id, :firstname, :lastname, :full_name, :address1, :address2, :city,
|
115
|
+
:zipcode, :phone, :company, :alternative_phone, :country_id, :state_id,
|
116
|
+
:state_name, :state_text
|
117
|
+
]
|
118
|
+
|
119
|
+
@@country_attributes = [:id, :iso_name, :iso, :iso3, :name, :numcode]
|
120
|
+
|
121
|
+
@@state_attributes = [:id, :name, :abbr, :country_id]
|
122
|
+
|
123
|
+
@@adjustment_attributes = [
|
124
|
+
:id, :source_type, :source_id, :adjustable_type, :adjustable_id,
|
125
|
+
:originator_type, :originator_id, :amount, :label, :mandatory,
|
126
|
+
:locked, :eligible, :created_at, :updated_at
|
127
|
+
]
|
128
|
+
|
129
|
+
@@creditcard_attributes = [
|
130
|
+
:id, :month, :year, :cc_type, :last_digits, :name,
|
131
|
+
:gateway_customer_profile_id, :gateway_payment_profile_id
|
132
|
+
]
|
133
|
+
|
134
|
+
@@payment_source_attributes = [
|
135
|
+
:id, :month, :year, :cc_type, :last_digits, :name
|
136
|
+
]
|
137
|
+
|
138
|
+
@@user_attributes = [:id, :email, :created_at, :updated_at]
|
139
|
+
|
140
|
+
@@property_attributes = [:id, :name, :presentation]
|
141
|
+
|
142
|
+
@@stock_location_attributes = [
|
143
|
+
:id, :name, :address1, :address2, :city, :state_id, :state_name,
|
144
|
+
:country_id, :zipcode, :phone, :active
|
145
|
+
]
|
146
|
+
|
147
|
+
@@stock_movement_attributes = [:id, :quantity, :stock_item_id]
|
148
|
+
|
149
|
+
@@stock_item_attributes = [
|
150
|
+
:id, :count_on_hand, :backorderable, :lock_version, :stock_location_id,
|
151
|
+
:variant_id
|
152
|
+
]
|
153
|
+
|
154
|
+
@@promotion_attributes = [
|
155
|
+
:id, :name, :description, :expires_at, :starts_at, :type, :usage_limit,
|
156
|
+
:match_policy, :code, :advertise, :path
|
157
|
+
]
|
158
|
+
|
159
|
+
@@store_attributes = [
|
160
|
+
:id, :name, :url, :meta_description, :meta_keywords, :seo_title,
|
161
|
+
:mail_from_address, :default_currency, :code, :default
|
162
|
+
]
|
163
|
+
|
164
|
+
def variant_attributes
|
165
|
+
if @current_user_roles && @current_user_roles.include?("admin")
|
166
|
+
@@variant_attributes + [:cost_price]
|
167
|
+
else
|
168
|
+
@@variant_attributes
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
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/v1/variants/small"
|
9
|
+
attributes :product_id
|
10
|
+
child(:images => :images) { extends "spree/api/v1/images/show" }
|
11
|
+
end
|
12
|
+
|
13
|
+
child :adjustments => :adjustments do
|
14
|
+
extends "spree/api/v1/adjustments/show"
|
15
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,10 @@
|
|
1
|
+
cache [I18n.locale, root_object]
|
2
|
+
attributes *order_attributes
|
3
|
+
node(:display_item_total) { |o| o.display_item_total.to_s }
|
4
|
+
node(:total_quantity) { |o| o.line_items.sum(:quantity) }
|
5
|
+
node(:display_total) { |o| o.display_total.to_s }
|
6
|
+
node(:display_ship_total) { |o| o.display_ship_total }
|
7
|
+
node(:display_tax_total) { |o| o.display_tax_total }
|
8
|
+
node(:display_adjustment_total) { |o| o.display_adjustment_total }
|
9
|
+
node(:token) { |o| o.guest_token }
|
10
|
+
node(:checkout_steps) { |o| o.checkout_steps }
|
@@ -0,0 +1,51 @@
|
|
1
|
+
object @order
|
2
|
+
extends "spree/api/v1/orders/order"
|
3
|
+
|
4
|
+
if lookup_context.find_all("spree/api/v1/orders/#{root_object.state}").present?
|
5
|
+
extends "spree/api/v1/orders/#{root_object.state}"
|
6
|
+
end
|
7
|
+
|
8
|
+
child :billing_address => :bill_address do
|
9
|
+
extends "spree/api/v1/addresses/show"
|
10
|
+
end
|
11
|
+
|
12
|
+
child :shipping_address => :ship_address do
|
13
|
+
extends "spree/api/v1/addresses/show"
|
14
|
+
end
|
15
|
+
|
16
|
+
child :line_items => :line_items do
|
17
|
+
extends "spree/api/v1/line_items/show"
|
18
|
+
end
|
19
|
+
|
20
|
+
child :payments => :payments do
|
21
|
+
attributes *payment_attributes
|
22
|
+
|
23
|
+
child :payment_method => :payment_method do
|
24
|
+
attributes :id, :name
|
25
|
+
end
|
26
|
+
|
27
|
+
child :source => :source do
|
28
|
+
if @current_user_roles.include?('admin')
|
29
|
+
attributes *payment_source_attributes + [:gateway_customer_profile_id, :gateway_payment_profile_id]
|
30
|
+
else
|
31
|
+
attributes *payment_source_attributes
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
child :shipments => :shipments do
|
37
|
+
extends "spree/api/v1/shipments/small"
|
38
|
+
end
|
39
|
+
|
40
|
+
child :adjustments => :adjustments do
|
41
|
+
extends "spree/api/v1/adjustments/show"
|
42
|
+
end
|
43
|
+
|
44
|
+
# Necessary for backend's order interface
|
45
|
+
node :permissions do
|
46
|
+
{ can_update: current_ability.can?(:update, root_object) }
|
47
|
+
end
|
48
|
+
|
49
|
+
child :valid_credit_cards => :credit_cards do
|
50
|
+
extends "spree/api/v1/credit_cards/show"
|
51
|
+
end
|