From 794ad35ab6e4f632b394c9394ca11a677ba827d5 Mon Sep 17 00:00:00 2001 From: Lawrence <46209705+luwiee@users.noreply.github.com> Date: Sun, 26 Apr 2026 18:44:09 +0800 Subject: [PATCH] Allow temporary_address to be set via the checkout API (#2845) `Spree::Order` has long supported a transient `temporary_address` attribute that, when set, suppresses persisting the order's address to the user's address book on transition out of the address step. The model already has a regression spec for this behavior (`core/spec/models/spree/order/checkout_spec.rb`). The checkout API never permitted the attribute, so API consumers had no way to opt out of address-book persistence (#2845). This adds it to `Spree::PermittedAttributes.checkout_address_attributes`. Default behavior is unchanged: the attribute defaults to `nil`/falsey, and `persist_user_address!` continues to call `persist_order_address` when it isn't explicitly set to a truthy value. --- api/spec/requests/spree/api/checkouts_spec.rb | 14 ++++++++++++++ core/lib/spree/permitted_attributes.rb | 1 + 2 files changed, 15 insertions(+) diff --git a/api/spec/requests/spree/api/checkouts_spec.rb b/api/spec/requests/spree/api/checkouts_spec.rb index c5b5e29105f..1986a87b9f2 100644 --- a/api/spec/requests/spree/api/checkouts_spec.rb +++ b/api/spec/requests/spree/api/checkouts_spec.rb @@ -109,6 +109,20 @@ module Spree::Api expect(response.status).to eq(200) end + # Regression test for https://github.com/solidusio/solidus/issues/2845 + it "does not persist the address to the user's address book when temporary_address is set" do + expect_any_instance_of(Spree.user_class).not_to receive(:persist_order_address) + + put spree.api_checkout_path(order), + params: {order_token: order.guest_token, order: { + temporary_address: true, + bill_address_attributes: address, + ship_address_attributes: address + }} + + expect(response.status).to eq(200) + end + # Regression Spec for https://github.com/spree/spree/issues/5389 and https://github.com/spree/spree/issues/5880 it "can update addresses but not transition to delivery w/o shipping setup" do Spree::ShippingMethod.all.find_each(&:destroy) diff --git a/core/lib/spree/permitted_attributes.rb b/core/lib/spree/permitted_attributes.rb index 7a3f9c54aeb..7536ba32959 100644 --- a/core/lib/spree/permitted_attributes.rb +++ b/core/lib/spree/permitted_attributes.rb @@ -153,6 +153,7 @@ module PermittedAttributes @@checkout_address_attributes = [ :use_billing, :use_shipping, + :temporary_address, :email, bill_address_attributes: address_attributes, ship_address_attributes: address_attributes