Skip to content

armgit / spree

Public Imported from GitHub
0

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.

Fixed: guest checkout disallowed if channel prices hidden is set ON

Damian Legawiecc3402166d6a4
diff --git a/spree/core/app/models/concerns/spree/purchase/lifecycle.rb b/spree/core/app/models/concerns/spree/purchase/lifecycle.rb
index 679fb84435..2945fd4680 100644
--- a/spree/core/app/models/concerns/spree/purchase/lifecycle.rb
+++ b/spree/core/app/models/concerns/spree/purchase/lifecycle.rb
@@ -36,14 +36,17 @@ module Spree
fulfillment_items.any?(&:backordered?)
end
+ # A +prices_hidden+ channel also disallows guest completion regardless
+ # of the +guest_checkout+ flag — prices are withheld from guests, and a
+ # buyer who cannot see prices cannot meaningfully place an order.
+ #
# @return [Boolean]
def guest_checkout_disallowed?
return false if customer.present?
+ return false if channel.blank?
+ return true if channel.storefront_prices_hidden?
- resolved_channel = channel || store&.default_channel
- return false unless resolved_channel.respond_to?(:guest_checkout_enabled?)
-
- !resolved_channel.guest_checkout_enabled?
+ !channel.resolved_guest_checkout
end
end
end
diff --git a/spree/core/spec/models/concerns/spree/purchase/lifecycle_spec.rb b/spree/core/spec/models/concerns/spree/purchase/lifecycle_spec.rb
index fb74f61431..848d4510af 100644
--- a/spree/core/spec/models/concerns/spree/purchase/lifecycle_spec.rb
+++ b/spree/core/spec/models/concerns/spree/purchase/lifecycle_spec.rb
@@ -43,16 +43,26 @@ RSpec.shared_examples 'a purchase lifecycle host' do
expect(new_record(customer: create(:user)).guest_checkout_disallowed?).to be(false)
end
- it 'follows the channel guest-checkout flag for guests' do
+ it 'follows the channel guest-checkout setting for guests' do
record = new_record
record.valid? # resolve the default channel
- allow(record.channel).to receive(:guest_checkout_enabled?).and_return(false)
+ record.channel.preferred_guest_checkout = false
expect(record.guest_checkout_disallowed?).to be(true)
- allow(record.channel).to receive(:guest_checkout_enabled?).and_return(true)
+ record.channel.preferred_guest_checkout = true
expect(record.guest_checkout_disallowed?).to be(false)
end
+
+ it 'blocks guests on a prices_hidden channel even when guest checkout is on' do
+ record = new_record
+ record.valid? # resolve the default channel
+
+ record.channel.preferred_guest_checkout = true
+ record.channel.preferred_storefront_access = 'prices_hidden'
+
+ expect(record.guest_checkout_disallowed?).to be(true)
+ end
end
end