Class: Spree::Orders::Update
- Inherits:
-
Object
- Object
- Spree::Orders::Update
- Includes:
- ServiceModule::Base
- Defined in:
- app/services/spree/orders/update.rb
Overview
Admin-side order update.
Updates Order attributes plus optional line items via a flat ‘items: […]` array (matches POST shape and Store API convention). Standalone from Spree::Carts::Update (storefront).
Instance Method Summary collapse
Methods included from ServiceModule::Base
Instance Method Details
#call(order:, params: {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/services/spree/orders/update.rb', line 11 def call(order:, params: {}) @order = order @params = params.to_h.deep_symbolize_keys items_param = @params.delete(:items) ApplicationRecord.transaction do ship_address_id_before = @order.ship_address_id if @order.update(@params) process_items(items_param) if items_param else return failure(@order, @order.errors..to_sentence) end if items_param || @order.ship_address_id != ship_address_id_before build_shipments end @order.update_with_updater! end success(@order.reload) rescue ActiveRecord::RecordInvalid => e failure(e.record, e.record.errors..to_sentence) end |