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
Quick checkout: do not require shipping address for fully digital ord… (#12856)
Damian Legawiec56dbad0f3cdb
diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rbindex aa32bf52c8..9407346980 100644--- a/core/app/models/spree/order.rb+++ b/core/app/models/spree/order.rb@@ -325,7 +325,14 @@ module Spree# Either fully digital or not digital at all# @return [Boolean]def quick_checkout_available?- payment_required? && shipments.count <= 1 && (digital? || !some_digital?)+ payment_required? && shipments.count <= 1 && (digital? || !some_digital? || !delivery_required?)+ end++ # Check if quick checkout requires an address collection+ # If the order is digital or not delivery required, then we don't need to collect an address+ # @return [Boolean]+ def quick_checkout_require_address?+ !digital? && delivery_required?end# Returns the relevant zone (if any) to be used for taxation purposes.diff --git a/core/spec/models/spree/order_spec.rb b/core/spec/models/spree/order_spec.rbindex e7920e9e63..d28c5c2fca 100644--- a/core/spec/models/spree/order_spec.rb+++ b/core/spec/models/spree/order_spec.rb@@ -2137,7 +2137,7 @@ describe Spree::Order, type: :model doendend- describe '#quick_checkout_available?' do+ context 'quick checkout' dolet(:digital_shipping_method) { create(:digital_shipping_method) }let(:digital_product) { create(:product, shipping_category: digital_shipping_method.shipping_categories.first) }let(:digital_variant) { create(:variant, product: digital_product, digitals: [create(:digital)]) }@@ -2145,47 +2145,86 @@ describe Spree::Order, type: :model dolet(:physical_line_item) { create(:line_item, quantity: 1, order: order) }let(:order) { create(:order) }- it 'returns true if the order is fully digital' do- digital_line_item- order.update_totals+ describe '#quick_checkout?' do+ it 'returns false if the order has no shipping address' do+ expect(order.quick_checkout?).to be false+ end++ it 'returns false if the order has a shipping address but it is not a quick checkout address' do+ order.shipping_address = create(:address)+ expect(order.quick_checkout?).to be false+ end- expect(order.quick_checkout_available?).to be true+ it 'returns true if the order has a quick checkout shipping address' do+ order.shipping_address = create(:address, quick_checkout: true)+ expect(order.quick_checkout?).to be true+ endend- it 'returns true if the order has no digital products at all' do- physical_line_item- order.update_totals+ describe '#quick_checkout_available?' do+ it 'returns true if the order is fully digital' do+ digital_line_item+ order.update_totals- expect(order.quick_checkout_available?).to be true- end+ expect(order.quick_checkout_available?).to be true+ end- it 'returns false if the order has physical products and some digital products' do- physical_line_item- digital_line_item- order.update_totals+ it 'returns true if the order has no digital products at all' do+ physical_line_item+ order.update_totals- expect(order.quick_checkout_available?).to be false- end+ expect(order.quick_checkout_available?).to be true+ end++ it 'returns false if the order has physical products and some digital products' do+ physical_line_item+ digital_line_item+ order.update_totals- it 'returns false if order has many shipments' do- physical_line_item- digital_line_item- order.update_totals- order.create_proposed_shipments+ expect(order.quick_checkout_available?).to be false+ end++ it 'returns false if order has many shipments' do+ physical_line_item+ digital_line_item+ order.update_totals+ order.create_proposed_shipments- expect(order.shipments.count).to eq(2)+ expect(order.shipments.count).to eq(2)- expect(order.quick_checkout_available?).to be false+ expect(order.quick_checkout_available?).to be false+ end++ it 'returns false if order does not require payment' do+ physical_line_item.update(price: 0)+ order.update_totals++ expect(order.total).to eq(0)+ expect(order.payment_required?).to be false++ expect(order.quick_checkout_available?).to be false+ endend- it 'returns false if order does not require payment' do- physical_line_item.update(price: 0)- order.update_totals+ describe '#quick_checkout_require_address?' do+ let(:order) { create(:order) }- expect(order.total).to eq(0)- expect(order.payment_required?).to be false+ it 'returns true if the order is not digital and delivery is required' do+ expect(order.quick_checkout_require_address?).to be true+ end- expect(order.quick_checkout_available?).to be false+ it 'returns false if the order is digital' do+ digital_line_item+ order.update_totals++ expect(order.quick_checkout_require_address?).to be false+ end++ it 'returns false if the order does not require delivery' do+ allow(order).to receive(:delivery_required?).and_return(false)++ expect(order.quick_checkout_require_address?).to be false+ endendendenddiff --git a/storefront/spec/controllers/spree/checkout_controller_spec.rb b/storefront/spec/controllers/spree/checkout_controller_spec.rbindex 326d5564e7..57ddda6523 100644--- a/storefront/spec/controllers/spree/checkout_controller_spec.rb+++ b/storefront/spec/controllers/spree/checkout_controller_spec.rb@@ -1295,7 +1295,7 @@ describe Spree::CheckoutController, type: :controller doexpect(response).to redirect_to spree.checkout_path(order.token)expect(order.reload.payments.count).to eq(1)- expect(order.payments.first).to be_invalid+ expect(order.payments.first.state).to eq('invalid')expect(order.payments.first.source).to eq(store_credit)expect(order.payments.first.payment_method).to eq(payment_method)expect(order.payments.first.amount).to eq(12.34)