Class: Spree::Api::V3::Admin::PricesController
- Inherits:
-
ResourceController
- Object
- ActionController::API
- BaseController
- ResourceController
- Spree::Api::V3::Admin::PricesController
- Includes:
- BulkOperations
- Defined in:
- app/controllers/spree/api/v3/admin/prices_controller.rb
Overview
Admin CRUD for ‘Spree::Price`. Covers both base prices (`price_list_id: nil`) and price-list overrides under one resource, filtered via Ransack predicates on the index.
Constant Summary
Constants inherited from BaseController
BaseController::RATE_LIMIT_RESPONSE
Constants included from Idempotent
Idempotent::IDEMPOTENCY_HEADER, Idempotent::IDEMPOTENCY_TTL, Idempotent::MAX_KEY_LENGTH, Idempotent::MUTATING_METHODS
Constants included from ErrorHandler
Constants included from JwtAuthentication
JwtAuthentication::JWT_AUDIENCE_ADMIN, JwtAuthentication::JWT_AUDIENCE_STORE, JwtAuthentication::JWT_ISSUER, JwtAuthentication::USER_TYPE_ADMIN, JwtAuthentication::USER_TYPE_CUSTOMER
Instance Method Summary collapse
-
#bulk_destroy ⇒ void
Soft-deletes the listed prices.
-
#bulk_upsert ⇒ void
Bulk-upserts prices on the unique-key triple ‘(variant_id, currency, price_list_id)`.
Methods included from BulkOperations
#bulk_add_tags, #bulk_remove_tags
Methods inherited from ResourceController
#create, #destroy, #index, #show, #update
Methods included from Spree::Api::V3::ApiKeyAuthentication
#authenticate_api_key!, #authenticate_secret_key!
Methods included from JwtAuthentication
#authenticate_user, #require_authentication!
Instance Method Details
#bulk_destroy ⇒ void
This method returns an undefined value.
Soft-deletes the listed prices.
45 46 47 48 49 50 51 52 |
# File 'app/controllers/spree/api/v3/admin/prices_controller.rb', line 45 def bulk_destroy :destroy, Spree::Price destroy_scope = scope.where(id: decode_ids(params[:ids])) destroyed = destroy_scope.count(&:destroy) render json: { price_count: destroyed } end |
#bulk_upsert ⇒ void
This method returns an undefined value.
Bulk-upserts prices on the unique-key triple ‘(variant_id, currency, price_list_id)`.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/controllers/spree/api/v3/admin/prices_controller.rb', line 20 def bulk_upsert :create, Spree::Price :update, Spree::Price rows = Array(params[:prices]).map { |row| decode_price_row(row) } invalid = rows.each_with_index.filter_map do |row, idx| missing = %i[variant_id currency].reject { |k| row[k].present? } { index: idx, missing: missing } if missing.any? end if invalid.any? return render_error( code: 'invalid_prices', message: 'Each row must include variant_id and currency.', status: :unprocessable_content, details: { rows: invalid } ) end result = Spree::Prices::BulkUpsert.call(rows: rows) render json: result.value end |