diff --git a/app/controllers/api/v1/customers_controller.rb b/app/controllers/api/v1/customers_controller.rb index 5353c6d39f..4e3efb75b8 100644 --- a/app/controllers/api/v1/customers_controller.rb +++ b/app/controllers/api/v1/customers_controller.rb @@ -8,6 +8,10 @@ module Api include AddressTransformation include ExtraFields + wrap_parameters :customer, include: + Customer.attribute_names + + [:billing_address, :shipping_address] + skip_authorization_check only: :index before_action :authorize_action, only: [:show, :update, :destroy] @@ -88,7 +92,8 @@ module Api attributes = params.require(:customer).permit( :email, :enterprise_id, :code, :first_name, :last_name, - :billing_address, shipping_address: [ + :billing_address, + shipping_address: [ :phone, :latitude, :longitude, :first_name, :last_name, :street_address_1, :street_address_2, diff --git a/app/models/customer.rb b/app/models/customer.rb index 476dbc95f8..b514c0e1d0 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -25,11 +25,13 @@ class Customer < ApplicationRecord before_destroy :update_orders_and_delete_canceled_subscriptions belongs_to :bill_address, class_name: "Spree::Address", optional: true - alias_attribute :billing_address, :bill_address + alias_method :billing_address, :bill_address + alias_method :billing_address=, :bill_address= accepts_nested_attributes_for :bill_address belongs_to :ship_address, class_name: "Spree::Address", optional: true - alias_attribute :shipping_address, :ship_address + alias_method :shipping_address, :ship_address + alias_method :shipping_address=, :ship_address= accepts_nested_attributes_for :ship_address validates :code, uniqueness: { scope: :enterprise_id, allow_nil: true } diff --git a/app/models/spree/order.rb b/app/models/spree/order.rb index 0ba30064c5..160041bfff 100644 --- a/app/models/spree/order.rb +++ b/app/models/spree/order.rb @@ -35,10 +35,12 @@ module Spree belongs_to :created_by, class_name: "Spree::User", optional: true belongs_to :bill_address, class_name: 'Spree::Address', optional: true - alias_attribute :billing_address, :bill_address + alias_method :billing_address, :bill_address + alias_method :billing_address=, :bill_address= belongs_to :ship_address, class_name: 'Spree::Address', optional: true - alias_attribute :shipping_address, :ship_address + alias_method :shipping_address, :ship_address + alias_method :shipping_address=, :ship_address= has_many :state_changes, as: :stateful, dependent: :destroy has_many :line_items, -> { diff --git a/app/models/subscription.rb b/app/models/subscription.rb index 4509c1ac75..8e2df44bd6 100644 --- a/app/models/subscription.rb +++ b/app/models/subscription.rb @@ -24,8 +24,10 @@ class Subscription < ApplicationRecord has_many :proxy_orders, dependent: :destroy has_many :orders, through: :proxy_orders - alias_attribute :billing_address, :bill_address - alias_attribute :shipping_address, :ship_address + alias_method :billing_address, :bill_address + alias_method :billing_address=, :bill_address= + alias_method :shipping_address, :ship_address + alias_method :shipping_address=, :ship_address= accepts_nested_attributes_for :subscription_line_items, allow_destroy: true accepts_nested_attributes_for :bill_address, :ship_address diff --git a/config/environments/test.rb b/config/environments/test.rb index 8c7562aee0..9fd47d1c3e 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -79,9 +79,6 @@ Rails.application.configure do "Passing the class as positional argument", - # Spree::Order model aliases `bill_address`, but `bill_address` is not an attribute. Starting in Rails 7.2, alias_attribute with non-attribute targets will raise. Use `alias_method :billing_address, :bill_address` or define the method manually. (called from initialize at app/models/spree/order.rb:188) - "alias_attribute with non-attribute targets will raise", - # Spree::CreditCard model aliases `cc_type` and has a method called `cc_type=` defined. Starting in Rails 7.2 `brand=` will not be calling `cc_type=` anymore. You may want to additionally define `brand=` to preserve the current behavior. "model aliases",