Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Sweep merged 6.0 code onto canonical customer naming
Łukasz Adamczykbb2f53cf792c
diff --git a/spree/api/app/controllers/spree/api/v3/admin/orders/payments_controller.rb b/spree/api/app/controllers/spree/api/v3/admin/orders/payments_controller.rbindex 0c1e764530..a4e29e6c76 100644--- a/spree/api/app/controllers/spree/api/v3/admin/orders/payments_controller.rb+++ b/spree/api/app/controllers/spree/api/v3/admin/orders/payments_controller.rb@@ -78,9 +78,9 @@ module Spree# to that customer to prevent attaching customer A's card to# customer B's order. Refuse if no customer is assigned.def find_source!(payment_method, source_id)- raise ActiveRecord::RecordNotFound unless @parent.user+ raise ActiveRecord::RecordNotFound unless @parent.customer- @parent.user.credit_cards.find_by_prefix_id!(source_id)+ @parent.customer.credit_cards.find_by_prefix_id!(source_id)endendenddiff --git a/spree/api/app/controllers/spree/api/v3/store/carts_controller.rb b/spree/api/app/controllers/spree/api/v3/store/carts_controller.rbindex 9ada01bbe4..5296925122 100644--- a/spree/api/app/controllers/spree/api/v3/store/carts_controller.rb+++ b/spree/api/app/controllers/spree/api/v3/store/carts_controller.rb@@ -93,7 +93,7 @@ module Spreeauthorize!(:update, @cart, cart_token)require_cart_token!- result = Spree.cart_associate_service.call(guest_cart: @cart, user: current_user, guest_only: true)+ result = Spree.cart_associate_service.call(guest_cart: @cart, customer: current_user, guest_only: true)if result.success?render_cartdiff --git a/spree/core/app/models/concerns/spree/purchase/addresses.rb b/spree/core/app/models/concerns/spree/purchase/addresses.rbindex 9986110fc8..343e2fe35c 100644--- a/spree/core/app/models/concerns/spree/purchase/addresses.rb+++ b/spree/core/app/models/concerns/spree/purchase/addresses.rb@@ -88,13 +88,13 @@ module Spree## @return [void]def assign_default_addresses!- return unless user+ return unless customer- self.bill_address = user.bill_address if !bill_address_id && user.bill_address&.valid?+ self.bill_address = customer.bill_address if !bill_address_id && customer.bill_address&.valid?# Skip the ship address only for all-digital records to avoid# triggering shipping-address validations (an empty record still# gets one — items usually arrive after the address).- self.ship_address = user.ship_address if !ship_address_id && user.ship_address&.valid? && !digital?+ self.ship_address = customer.ship_address if !ship_address_id && customer.ship_address&.valid? && !digital?end# Copies the ship address onto the bill address and promotes it to the@@ -103,7 +103,7 @@ module Spree# @return [true]def clone_shipping_addressself.bill_address = ship_address if ship_address- user.bill_address = ship_address if should_assign_user_default_address?(ship_address)+ customer.bill_address = ship_address if should_assign_user_default_address?(ship_address)trueend@@ -115,7 +115,7 @@ module Spree# @return [true]def clone_billing_addressself.ship_address = bill_address if bill_address- user.ship_address = bill_address if should_assign_user_default_address?(bill_address)+ customer.ship_address = bill_address if should_assign_user_default_address?(bill_address)trueend@@ -129,7 +129,7 @@ module Spreeaddress = Spree::Address.find_by(id: id)# rubocop:disable Style/ConditionalAssignment- if address && user_id.present? && address.user_id == user_id+ if address && customer_id.present? && address.customer_id == customer_idself['bill_address_id'] = address.idelseself['bill_address_id'] = nil@@ -145,7 +145,7 @@ module Spree# @param attributes [Hash, ActionController::Parameters]def bill_address_attributes=(attributes)self.bill_address = update_or_create_address(attributes)- user.bill_address = bill_address if should_assign_user_default_address?(bill_address)+ customer.bill_address = bill_address if should_assign_user_default_address?(bill_address)end# Ownership-guarded writer — see {#bill_address_id=}.@@ -156,7 +156,7 @@ module Spreeaddress = Spree::Address.find_by(id: id)# rubocop:disable Style/ConditionalAssignment- if address && user_id.present? && address.user_id == user_id+ if address && customer_id.present? && address.customer_id == customer_idself['ship_address_id'] = address.idelseself['ship_address_id'] = nil@@ -172,7 +172,7 @@ module Spree# @param attributes [Hash, ActionController::Parameters]def ship_address_attributes=(attributes)self.ship_address = update_or_create_address(attributes)- user.ship_address = ship_address if should_assign_user_default_address?(ship_address)+ customer.ship_address = ship_address if should_assign_user_default_address?(ship_address)self.ship_address = nil if quick_checkout_address?(attributes[:quick_checkout]) && !ship_address.persisted?end@@ -184,7 +184,7 @@ module Spreeattributes.transform_values!(&:presence)attributes = attributes.to_h.symbolize_keys- default_address_scope = user ? user.addresses : ::Spree::Address.where(user_id: nil)+ default_address_scope = customer ? customer.addresses : ::Spree::Address.where(customer_id: nil)default_address = default_address_scope.find_by(id: attributes[:id])if default_address&.editable?@@ -194,7 +194,7 @@ module Spreeendattributes = attributes.except(:id, :updated_at, :created_at)- attributes[:user_id] = user&.id+ attributes[:customer_id] = customer&.idexisting_address = find_existing_address(attributes)return existing_address if existing_address@@ -217,7 +217,7 @@ module Spreeenddef should_assign_user_default_address?(address)- user.present? && address.present? && address.valid? && address.user == user && !address.quick_checkout?+ customer.present? && address.present? && address.valid? && address.customer == customer && !address.quick_checkout?endendenddiff --git a/spree/core/app/models/spree/cart.rb b/spree/core/app/models/spree/cart.rbindex c1cc71ffc9..57c32e1789 100644--- a/spree/core/app/models/spree/cart.rb+++ b/spree/core/app/models/spree/cart.rb@@ -53,7 +53,7 @@ module Spreealias display_ship_total display_delivery_totalalias_attribute :ship_total, :delivery_total- belongs_to :customer, class_name: "::#{Spree.user_class}", optional: true+ belongs_to :customer, class_name: "::#{Spree.customer_class}", optional: true# Order-parity aliases — shared Cart/Order code (services, Purchase# concerns) reads #user; the cart column is customer_id.alias_method :user, :customer@@ -210,16 +210,22 @@ module Spreerecalculate_totals!end- # Binds a signing-in user to the cart through the swappable associate- # service (same seam Order#associate_user! uses).+ # Binds a signing-in customer to the cart through the swappable associate+ # service (same seam Order#associate_customer! uses).+ def associate_customer!(customer, override_email = true)+ Spree.cart_associate_service.call(guest_cart: self, customer: customer, override_email: override_email)+ end++ # @deprecated Use {#associate_customer!}; removed in 6.1.def associate_user!(user, override_email = true)- Spree.cart_associate_service.call(guest_cart: self, user: user, override_email: override_email)+ Spree::Deprecation.warn('Spree::Cart#associate_user! is deprecated and will be removed in Spree 6.1. Use #associate_customer! instead.')+ associate_customer!(user, override_email)end# Merges another cart into this one through the swappable merge workflow# (Spree::Dependencies.cart_merge_workflow).- def merge!(other_cart, user = nil)- Spree.cart_merge_workflow.call(cart: self, other_cart: other_cart, user: user)+ def merge!(other_cart, customer = nil)+ Spree.cart_merge_workflow.call(cart: self, other_cart: other_cart, customer: customer)reloadenddiff --git a/spree/core/app/models/spree/customer_group.rb b/spree/core/app/models/spree/customer_group.rbindex 83fb290719..1ad89f9d18 100644--- a/spree/core/app/models/spree/customer_group.rb+++ b/spree/core/app/models/spree/customer_group.rb@@ -78,7 +78,7 @@ module Spreeuser_ids = Array(user_ids).map(&:to_s).uniqreturn 0 if user_ids.empty?- deleted_count = customer_group_users.where(user_id: user_ids).delete_all+ deleted_count = customer_group_users.where(customer_id: user_ids).delete_allif deleted_count > 0touch_users(user_ids)diff --git a/spree/core/app/models/spree/gateway.rb b/spree/core/app/models/spree/gateway.rbindex f6cbc833fa..9dcdf5becb 100644--- a/spree/core/app/models/spree/gateway.rb+++ b/spree/core/app/models/spree/gateway.rb@@ -96,8 +96,8 @@ module Spreeif order.completed?sources_by_order orderelse- if order.user_id- credit_cards.where(user_id: order.user_id).capturable+ if order.customer_id+ credit_cards.where(customer_id: order.customer_id).capturableelse[]enddiff --git a/spree/core/app/models/spree/gateway/bogus.rb b/spree/core/app/models/spree/gateway/bogus.rbindex 4719c904d0..bfec73bfbe 100644--- a/spree/core/app/models/spree/gateway/bogus.rb+++ b/spree/core/app/models/spree/gateway/bogus.rb@@ -101,7 +101,7 @@ module Spreestatus: 'pending',external_id: "bogus_#{SecureRandom.hex(12)}",external_data: external_data.merge('client_secret' => "bogus_secret_#{SecureRandom.hex(8)}"),- customer: order.user+ customer: order.customer)enddiff --git a/spree/core/app/models/spree/order.rb b/spree/core/app/models/spree/order.rbindex 27a65da7e0..784f9cf7e1 100644--- a/spree/core/app/models/spree/order.rb+++ b/spree/core/app/models/spree/order.rb@@ -133,7 +133,7 @@ module Spreeself.tag_list = tagsend- ASSOCIATED_USER_ATTRIBUTES = [:customer_id, :email, :bill_address_id, :ship_address_id]+ ASSOCIATED_CUSTOMER_ATTRIBUTES = [:customer_id, :email, :bill_address_id, :ship_address_id]# @deprecated Use {Spree::Purchase::PaymentProcessing#payment_methods};# removed in 6.1.@@ -481,19 +481,31 @@ module Spree# Associates the specified user with the order.# Delegates to {Spree::Carts::Associate} service.#- # @param user [Spree.customer_class] the user to associate with the order- # @param override_email [Boolean] whether to override the order email with the user's email+ # @param customer [Spree.customer_class] the customer to associate with the order+ # @param override_email [Boolean] whether to override the order email with the customer's email# @return [Spree::ServiceModule::Result]+ def associate_customer!(customer, override_email = true)+ Spree.cart_associate_service.call(guest_cart: self, customer: customer, override_email: override_email)+ end++ # @deprecated Use {#associate_customer!}; removed in 6.1.def associate_user!(user, override_email = true)- Spree.cart_associate_service.call(guest_cart: self, user: user, override_email: override_email)+ Spree::Deprecation.warn('Spree::Order#associate_user! is deprecated and will be removed in Spree 6.1. Use #associate_customer! instead.')+ associate_customer!(user, override_email)end- def disassociate_user!- nullified_attributes = ASSOCIATED_USER_ATTRIBUTES.index_with(nil)+ def disassociate_customer!+ nullified_attributes = ASSOCIATED_CUSTOMER_ATTRIBUTES.index_with(nil)update!(nullified_attributes)end+ # @deprecated Use {#disassociate_customer!}; removed in 6.1.+ def disassociate_user!+ Spree::Deprecation.warn('Spree::Order#disassociate_user! is deprecated and will be removed in Spree 6.1. Use #disassociate_customer! instead.')+ disassociate_customer!+ end+def quantity_of(variant, options = {})line_item = find_line_item_by_variant(variant, options)line_item ? line_item.quantity : 0diff --git a/spree/core/app/models/spree/order_merger.rb b/spree/core/app/models/spree/order_merger.rbindex b09b3016d1..491b1bc262 100644--- a/spree/core/app/models/spree/order_merger.rb+++ b/spree/core/app/models/spree/order_merger.rb@@ -10,7 +10,7 @@ module Spree@order = orderend- def merge!(other_order, user = nil, discard_merged: true)+ def merge!(other_order, customer = nil, discard_merged: true)handle_gift_card(other_order)other_order.line_items.each do |other_order_line_item|next unless other_order_line_item.currency == order.currency@@ -19,7 +19,7 @@ module Spreehandle_merge(current_line_item, other_order_line_item)end- set_user(user)+ set_customer(customer)clear_addresses(other_order) if discard_mergedpersist_merge@@ -44,8 +44,8 @@ module Spreeendend- def set_user(user = nil)- order.associate_user!(user) if !order.customer && !user.blank?+ def set_customer(customer = nil)+ order.associate_customer!(customer) if !order.customer && !customer.blank?enddef clear_addresses(other_order)diff --git a/spree/core/app/models/spree/payment.rb b/spree/core/app/models/spree/payment.rbindex 1800a5344d..b1da9fb3d4 100644--- a/spree/core/app/models/spree/payment.rb+++ b/spree/core/app/models/spree/payment.rb@@ -202,13 +202,13 @@ module Spreepayment_method.payment_source_class.new(source_attributes)end- if source.user_id.present? && source.user_id != owner&.user_id+ if source.customer_id.present? && source.customer_id != owner&.customer_idself.source = nilreturnendsource.payment_method_id = payment_method.id if source.respond_to?(:payment_method_id)- source.user_id = owner.user_id if owner+ source.customer_id = owner.customer_id if ownerendenddiff --git a/spree/core/app/models/spree/payment/gateway_options.rb b/spree/core/app/models/spree/payment/gateway_options.rbindex 08207a2f07..91d461e7d0 100644--- a/spree/core/app/models/spree/payment/gateway_options.rb+++ b/spree/core/app/models/spree/payment/gateway_options.rb@@ -21,7 +21,7 @@ module Spreeenddef customer_id- order.user_id+ order.customer_idenddef ipdiff --git a/spree/core/app/models/spree/price_rules/customer_group_rule.rb b/spree/core/app/models/spree/price_rules/customer_group_rule.rbindex 8c830ef5d7..269629f163 100644--- a/spree/core/app/models/spree/price_rules/customer_group_rule.rb+++ b/spree/core/app/models/spree/price_rules/customer_group_rule.rb@@ -21,7 +21,7 @@ module Spreereturn false unless context.userreturn true if preferred_customer_group_ids.empty?- user_customer_group_ids = Spree::CustomerGroupUser.where(user_id: context.user.id).pluck(:customer_group_id).map(&:to_s)+ user_customer_group_ids = Spree::CustomerGroupUser.where(customer_id: context.user.id).pluck(:customer_group_id).map(&:to_s)# Compare as strings to support both integer and UUID primary keys(preferred_customer_group_ids.map(&:to_s) & user_customer_group_ids).any?diff --git a/spree/core/app/models/spree/promotion/rules/customer_group.rb b/spree/core/app/models/spree/promotion/rules/customer_group.rbindex 379b7e3044..fd6bb0eb4d 100644--- a/spree/core/app/models/spree/promotion/rules/customer_group.rb+++ b/spree/core/app/models/spree/promotion/rules/customer_group.rb@@ -18,10 +18,10 @@ module Spreeenddef eligible?(order, _options = {})- return false unless order.user_id.present?+ return false unless order.customer_id.present?return false if preferred_customer_group_ids.empty?- user_customer_group_ids = Spree::CustomerGroupUser.where(user_id: order.user_id).pluck(:customer_group_id).map(&:to_s)+ user_customer_group_ids = Spree::CustomerGroupUser.where(customer_id: order.customer_id).pluck(:customer_group_id).map(&:to_s)(preferred_customer_group_ids.map(&:to_s) & user_customer_group_ids).any?enddiff --git a/spree/core/app/services/spree/carts/associate.rb b/spree/core/app/services/spree/carts/associate.rbindex c2e89ecbd8..4ce3df5a20 100644--- a/spree/core/app/services/spree/carts/associate.rb+++ b/spree/core/app/services/spree/carts/associate.rb@@ -3,24 +3,27 @@ module Spreeclass Associateprepend Spree::ServiceModule::Base- def call(guest_cart: nil, guest_order: nil, user: nil, override_email: true, guest_only: false)+ def call(guest_cart: nil, guest_order: nil, customer: nil, user: nil, override_email: true, guest_only: false)if guest_orderSpree::Deprecation.warn('Calling Spree::Carts::Associate with guest_order: is deprecated and will be removed in Spree 6.1. Pass guest_cart: instead.')guest_cart ||= guest_orderend- return failure(guest_cart, 'Already assigned to a user') if guest_only && guest_cart.user.present? && guest_cart.user != user+ if user && customer.nil?+ Spree::Deprecation.warn('Calling Spree::Carts::Associate with user: is deprecated and will be removed in Spree 6.1. Pass customer: instead.')+ customer = user+ end+ return failure(guest_cart, 'Already assigned to a customer') if guest_only && guest_cart.customer.present? && guest_cart.customer != customer- guest_cart.user = user- guest_cart.email = user.email if override_email+ guest_cart.customer = customer+ guest_cart.email = customer.email if override_email# Only valid saved defaults are copied — update_all below skips# validations, so a broken address-book entry must not land on the# cart. Digital-only checkouts never receive a ship address.- guest_cart.bill_address ||= user.bill_address if user.bill_address&.valid?- guest_cart.ship_address ||= user.ship_address if user.ship_address&.valid? && guest_cart.delivery_step_required?+ guest_cart.bill_address ||= customer.bill_address if customer.bill_address&.valid?+ guest_cart.ship_address ||= customer.ship_address if customer.ship_address&.valid? && guest_cart.delivery_step_required?- owner_key = guest_cart.is_a?(Spree::Cart) ? :customer_id : :user_idchanges = {- owner_key => guest_cart.user&.id,+ customer_id: guest_cart.customer&.id,email: guest_cart.email,bill_address_id: guest_cart.bill_address&.id,ship_address_id: guest_cart.ship_address&.iddiff --git a/spree/core/app/services/spree/carts/update.rb b/spree/core/app/services/spree/carts/update.rbindex 6d244c07c4..1cfb6aa635 100644--- a/spree/core/app/services/spree/carts/update.rb+++ b/spree/core/app/services/spree/carts/update.rb@@ -104,7 +104,7 @@ module Spree# customer is in checkout, blank address slots fill from their saved# defaults (assign_default_addresses! guards each slot itself).def assign_default_addresses- return unless cart.user+ return unless cart.customerreturn unless cart.email.present? || cart.ship_address_id.present?cart.assign_default_addresses!diff --git a/spree/core/app/services/spree/newsletter/link_user.rb b/spree/core/app/services/spree/newsletter/link_user.rbindex 3e8a153c27..8f01b7f9dc 100644--- a/spree/core/app/services/spree/newsletter/link_user.rb+++ b/spree/core/app/services/spree/newsletter/link_user.rb@@ -15,7 +15,7 @@ module Spreedef callreturn if subscriber.blank? || user.blank?- return if subscriber.user_id == user.id && !needs_marketing_propagation?+ return if subscriber.customer_id == user.id && !needs_marketing_propagation?link_subscriber_to_userpropagate_marketing_consent if needs_marketing_propagation?@@ -28,9 +28,9 @@ module Spreeattr_reader :subscriber, :userdef link_subscriber_to_user- return if subscriber.user_id == user.id+ return if subscriber.customer_id == user.id- return if subscriber.update(user: user)+ return if subscriber.update(customer: user)Rails.logger.warn("NewsletterSubscriber #{subscriber.id} link to user #{user.id} failed: #{subscriber.errors.full_messages.to_sentence}"diff --git a/spree/core/app/subscribers/spree/order_placed_subscriber.rb b/spree/core/app/subscribers/spree/order_placed_subscriber.rbindex 45a0cd6ebf..1edd0b1440 100644--- a/spree/core/app/subscribers/spree/order_placed_subscriber.rb+++ b/spree/core/app/subscribers/spree/order_placed_subscriber.rb@@ -18,11 +18,11 @@ module Spreedef subscribe_to_newsletter(order)return unless order.accept_marketing?- Spree::NewsletterSubscriber.subscribe(email: order.email, user: order.user, store: order.store)+ Spree::NewsletterSubscriber.subscribe(email: order.email, customer: order.customer, store: order.store)enddef create_user_record(order)- return if order.user.present?+ return if order.customer.present?return unless order.signup_for_an_account?Spree::Orders::CreateUserAccount.call(order: order, accepts_email_marketing: order.accept_marketing?)diff --git a/spree/core/app/workflows/spree/carts/merge.rb b/spree/core/app/workflows/spree/carts/merge.rbindex 4e19f4120d..b55a711663 100644--- a/spree/core/app/workflows/spree/carts/merge.rb+++ b/spree/core/app/workflows/spree/carts/merge.rb@@ -14,9 +14,9 @@ module Spree# @param cart [Spree::Cart] the surviving cart# @param other_cart [Spree::Cart, nil] the cart folded in and destroyed- # @param user [Object, nil] associated with the surviving cart when it+ # @param customer [Object, nil] associated with the surviving cart when it# has no customer yet- def perform(cart:, other_cart: nil, user: nil)+ def perform(cart:, other_cart: nil, customer: nil)superhalt!(cart) if other_cart.nil? || other_cart.id == cart.id@@ -28,7 +28,7 @@ module SpreeApplicationRecord.transaction dostep :move_line_items- step :associate_user+ step :associate_customerstep :destroy_drained_cartend@@ -74,8 +74,8 @@ module Spreeendend- def associate_user- cart.associate_user!(user) if user && cart.customer.blank?+ def associate_customer+ cart.associate_customer!(customer) if customer && cart.customer.blank?enddef destroy_drained_cartdiff --git a/spree/core/app/workflows/spree/claims/resolve.rb b/spree/core/app/workflows/spree/claims/resolve.rbindex 3acea2223f..a06a74ecd5 100644--- a/spree/core/app/workflows/spree/claims/resolve.rb+++ b/spree/core/app/workflows/spree/claims/resolve.rb@@ -112,7 +112,7 @@ module Spree@refunds = [Spree::StoreCredit.create!(store: claim.store,- user: claim.order.user,+ customer: claim.order.customer,amount: @amount_to_refund,currency: claim.currency,category: Spree::StoreCreditCategory.default_reimbursement_category,diff --git a/spree/core/app/workflows/spree/exchanges/fulfill.rb b/spree/core/app/workflows/spree/exchanges/fulfill.rbindex 9c1c06f4e1..9ce5c14f31 100644--- a/spree/core/app/workflows/spree/exchanges/fulfill.rb+++ b/spree/core/app/workflows/spree/exchanges/fulfill.rb@@ -91,7 +91,7 @@ module Spree@refunds = [Spree::StoreCredit.create!(store: exchange.store,- user: exchange.order.user,+ customer: exchange.order.customer,amount: credit_amount,currency: exchange.currency,category: Spree::StoreCreditCategory.default_reimbursement_category,diff --git a/spree/core/app/workflows/spree/returns/refund.rb b/spree/core/app/workflows/spree/returns/refund.rbindex d9f63995f0..e56a6bfdc4 100644--- a/spree/core/app/workflows/spree/returns/refund.rb+++ b/spree/core/app/workflows/spree/returns/refund.rb@@ -76,7 +76,7 @@ module Spreedef issue_store_creditcredit = Spree::StoreCredit.create!(store: return_record.store,- user: return_record.order.user,+ customer: return_record.order.customer,amount: @amount_to_refund,currency: return_record.currency,category: Spree::StoreCreditCategory.default_reimbursement_category,diff --git a/spree/core/lib/spree/core.rb b/spree/core/lib/spree/core.rbindex 88e676a51a..171130b893 100644--- a/spree/core/lib/spree/core.rb+++ b/spree/core/lib/spree/core.rb@@ -386,7 +386,7 @@ module Spreeend# Class-name strings (`'Spree::Product'`, `'Spree::Order'`,- # `Spree.user_class.to_s`, plus any registered by apps) for resources that+ # `Spree.customer_class.to_s`, plus any registered by apps) for resources that# expose tags via `acts_as_taggable_on :tags`. Used by the Admin API# `/tags` autocomplete endpoint to validate `taggable_type`. Apps extend# the list in an initializer:diff --git a/spree/core/spec/models/spree/cart_spec.rb b/spree/core/spec/models/spree/cart_spec.rbindex 5f4d9c16e2..bd8bf15b2e 100644--- a/spree/core/spec/models/spree/cart_spec.rb+++ b/spree/core/spec/models/spree/cart_spec.rb@@ -308,7 +308,7 @@ describe Spree::Cart, type: :model doother_cart = create(:cart, store: store)workflow = class_double(Spree::Carts::Merge).as_stubbed_const- expect(workflow).to receive(:call).with(cart: cart, other_cart: other_cart, user: nil)+ expect(workflow).to receive(:call).with(cart: cart, other_cart: other_cart, customer: nil)cart.merge!(other_cart)enddiff --git a/spree/core/spec/models/spree/order/checkout_spec.rb b/spree/core/spec/models/spree/order/checkout_spec.rbindex 4d929a263a..583447222b 100644--- a/spree/core/spec/models/spree/order/checkout_spec.rb+++ b/spree/core/spec/models/spree/order/checkout_spec.rb@@ -53,7 +53,7 @@ describe Spree::Order, type: :model dolet(:accept_marketing) { true }it 'subscribes to newsletter', :events do- expect(Spree::NewsletterSubscriber).to receive(:subscribe).with(email: order.email, user: order.user, store: order.store)+ expect(Spree::NewsletterSubscriber).to receive(:subscribe).with(email: order.email, customer: order.customer, store: order.store)order.finalize!endenddiff --git a/spree/core/spec/models/spree/payment/gateway_options_spec.rb b/spree/core/spec/models/spree/payment/gateway_options_spec.rbindex 05e7155ed4..f9caf98342 100644--- a/spree/core/spec/models/spree/payment/gateway_options_spec.rb+++ b/spree/core/spec/models/spree/payment/gateway_options_spec.rb@@ -24,7 +24,7 @@ RSpec.describe Spree::Payment::GatewayOptions, type: :model dodouble(Spree::Order,email: '[email protected]',- user_id: 144,+ customer_id: 144,last_ip_address: '0.0.0.0',number: 'R1444',ship_total: '12.44'.to_d,diff --git a/spree/core/spec/services/spree/carts/associate_spec.rb b/spree/core/spec/services/spree/carts/associate_spec.rbindex 3273605cb7..cc11993edf 100644--- a/spree/core/spec/services/spree/carts/associate_spec.rb+++ b/spree/core/spec/services/spree/carts/associate_spec.rb@@ -2,7 +2,7 @@ require 'spec_helper'module Spreedescribe Carts::Associate do- subject { described_class.call(guest_cart: cart, user: user) }+ subject { described_class.call(guest_cart: cart, customer: user) }let(:user) { create(:user) }@@ -19,7 +19,7 @@ module Spreeuser.update!(bill_address: create(:address, user: user), ship_address: create(:address, user: user))cart_with_items = create(:cart_with_line_items, customer: nil)- described_class.call(guest_cart: cart_with_items, user: user)+ described_class.call(guest_cart: cart_with_items, customer: user)expect(cart_with_items.reload.bill_address_id).to eq(user.bill_address_id)expect(cart_with_items.ship_address_id).to eq(user.ship_address_id)@@ -52,7 +52,7 @@ module Spreeendcontext 'with guest_only: true' do- subject { described_class.call(guest_cart: cart, user: user, guest_only: true) }+ subject { described_class.call(guest_cart: cart, customer: user, guest_only: true) }it 'returns failure' doexpect(subject).to be_failure@@ -60,5 +60,30 @@ module Spreeendendend++ context 'when a guest order is given' do+ let(:order) { create(:order, customer: nil) }++ # Explicitly covers the Order owner path — the service persists via+ # update_all (raw columns, no alias), keyed off customer_id for both types.+ it 'assigns the order to the customer' do+ result = described_class.call(guest_cart: order, customer: user)++ expect(result).to be_success+ expect(order.reload.customer).to eq(user)+ end+ end++ context 'with the deprecated user: keyword' do+ let(:cart) { create(:cart, customer: nil) }++ it 'warns and still assigns the customer' do+ expect(Spree::Deprecation).to receive(:warn).at_least(:once)++ described_class.call(guest_cart: cart, user: user)++ expect(cart.reload.customer).to eq(user)+ end+ endendenddiff --git a/spree/core/spec/services/spree/newsletter/subscribe_spec.rb b/spree/core/spec/services/spree/newsletter/subscribe_spec.rbindex 59596ababa..59caa0b589 100644--- a/spree/core/spec/services/spree/newsletter/subscribe_spec.rb+++ b/spree/core/spec/services/spree/newsletter/subscribe_spec.rb@@ -123,7 +123,7 @@ module Spreelet(:user) { create(:user, email: email, accepts_email_marketing: false) }it 'links the existing subscriber to the user and preserves consent' do- expect(service.user).to eq(user)+ expect(service.customer).to eq(user)expect(user.reload.accepts_email_marketing).to eq(true)endend@@ -150,7 +150,7 @@ module Spreelet(:user) { create(:user, email: email, accepts_email_marketing: false) }it 'links and verifies the existing subscriber' do- expect(service.user).to eq(user)+ expect(service.customer).to eq(user)expect(service.reload).to be_verifiedexpect(user.reload.accepts_email_marketing).to eq(true)enddiff --git a/spree/core/spec/subscribers/spree/order_placed_subscriber_spec.rb b/spree/core/spec/subscribers/spree/order_placed_subscriber_spec.rbnew file mode 100644index 0000000000..841d074f21--- /dev/null+++ b/spree/core/spec/subscribers/spree/order_placed_subscriber_spec.rb@@ -0,0 +1,44 @@+# frozen_string_literal: true++require 'spec_helper'++RSpec.describe Spree::OrderPlacedSubscriber do+ let(:store) { @default_store }+ let(:subscriber) { described_class.new }+ let(:customer) { create(:user, email: '[email protected]') }+ let(:order) { create(:order, store: store, customer: customer, email: customer.email) }++ def mock_event(record)+ double('Event', payload: { 'id' => record.prefixed_id })+ end++ before { allow_any_instance_of(Spree::Order).to receive(:consider_risk) }++ describe '#handle newsletter subscription on order.placed' do+ context 'when the order opted into marketing' do+ before { order.update!(accept_marketing: true) }++ it 'subscribes the order customer via customer:' do+ expect(Spree::NewsletterSubscriber).to receive(:subscribe).+ with(email: order.email, customer: customer, store: store)++ subscriber.handle(mock_event(order))+ end++ it 'creates the subscriber without raising' do+ expect { subscriber.handle(mock_event(order)) }.+ to change { Spree::NewsletterSubscriber.for_store(store).count }.by(1)+ end+ end++ context 'when the order did not opt into marketing' do+ before { order.update!(accept_marketing: false) }++ it 'does not subscribe' do+ expect(Spree::NewsletterSubscriber).not_to receive(:subscribe)++ subscriber.handle(mock_event(order))+ end+ end+ end+end