Class: Spree::Api::V3::Store::Carts::FulfillmentsController

Inherits:
BaseController show all
Includes:
CartResolvable, OrderLock
Defined in:
app/controllers/spree/api/v3/store/carts/fulfillments_controller.rb

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

ErrorHandler::ERROR_CODES

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

Methods included from ApiKeyAuthentication

#authenticate_api_key!, #authenticate_secret_key!

Methods included from JwtAuthentication

#authenticate_user, #require_authentication!

Instance Method Details

#indexObject

GET /api/v3/store/carts/:cart_id/fulfillments



13
14
15
16
17
18
19
# File 'app/controllers/spree/api/v3/store/carts/fulfillments_controller.rb', line 13

def index
  fulfillments = @cart.shipments.includes(shipping_rates: :shipping_method)
  render json: {
    data: fulfillments.map { |s| Spree.api.fulfillment_serializer.new(s, params: serializer_params).to_h },
    meta: { count: fulfillments.size }
  }
end

#updateObject

PATCH /api/v3/store/carts/:cart_id/fulfillments/:id Select a delivery rate for a specific fulfillment



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/spree/api/v3/store/carts/fulfillments_controller.rb', line 23

def update
  with_order_lock do
    fulfillment = @cart.shipments.find_by_prefix_id!(params[:id])

    if permitted_params[:selected_delivery_rate_id].present?
      delivery_rate = fulfillment.shipping_rates.find_by_prefix_id!(permitted_params[:selected_delivery_rate_id])
      fulfillment.selected_shipping_rate_id = delivery_rate.id
      fulfillment.save!
    end

    # Auto-advance (e.g. delivery → payment) after rate selection.
    # Temporary — Spree 6 removes the checkout state machine.
    try_advance

    render_cart
  end
end