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
Added `Order#quick_checkout_available?` (#12854)
Damian Legawiec2e00593dd5bc
diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rbindex 3b332a8746..aa32bf52c8 100644--- a/core/app/models/spree/order.rb+++ b/core/app/models/spree/order.rb@@ -313,10 +313,21 @@ module Spreeshipments.any?(&:backordered?)end+ # Check if the shipping address is a quick checkout address+ # quick checkout addresses are incomplete as wallet providers like Apple Pay and Google Pay+ # do not provide all the address fields until the checkout is completed (confirmed) on their side+ # @return [Boolean]def quick_checkout?shipping_address.present? && shipping_address.quick_checkout?end+ # Check if quick checkout is available for this order+ # Either fully digital or not digital at all+ # @return [Boolean]+ def quick_checkout_available?+ payment_required? && shipments.count <= 1 && (digital? || !some_digital?)+ end+# Returns the relevant zone (if any) to be used for taxation purposes.# Uses default tax zone unless there is a specific matchdef tax_zonediff --git a/core/spec/models/spree/order_spec.rb b/core/spec/models/spree/order_spec.rbindex 28aa136d11..e7920e9e63 100644--- a/core/spec/models/spree/order_spec.rb+++ b/core/spec/models/spree/order_spec.rb@@ -2136,4 +2136,56 @@ describe Spree::Order, type: :model doendendend++ describe '#quick_checkout_available?' do+ let(: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)]) }+ let(:digital_line_item) { create(:line_item, variant: digital_variant, quantity: 1, order: order) }+ let(: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++ expect(order.quick_checkout_available?).to be true+ end++ 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 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++ 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.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+ end+ endenddiff --git a/storefront/app/helpers/spree/checkout_helper.rb b/storefront/app/helpers/spree/checkout_helper.rbindex a7dc9ee1b1..46dfdd7232 100644--- a/storefront/app/helpers/spree/checkout_helper.rb+++ b/storefront/app/helpers/spree/checkout_helper.rb@@ -47,8 +47,7 @@ module Spreeenddef quick_checkout_enabled?(order)- order.payment_required? && order.shipments.count <= 1 &&- (order.digital? || !order.some_digital?) # Either fully digital or not digital at all+ order.quick_checkout_available?enddef can_use_store_credit_on_checkout?(order)diff --git a/storefront/spec/helpers/spree/checkout_helper_spec.rb b/storefront/spec/helpers/spree/checkout_helper_spec.rbindex 71dc2fb457..955484027a 100644--- a/storefront/spec/helpers/spree/checkout_helper_spec.rb+++ b/storefront/spec/helpers/spree/checkout_helper_spec.rb@@ -1,55 +1,4 @@require 'spec_helper'describe Spree::CheckoutHelper do- describe '#quick_checkout_enabled?' do- let(: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)]) }- let(:digital_line_item) { create(:line_item, variant: digital_variant, quantity: 1, order: order) }- let(: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-- expect(helper.quick_checkout_enabled?(order)).to be true- end-- it 'returns true if the order has no digital products at all' do- physical_line_item- order.update_totals-- expect(helper.quick_checkout_enabled?(order)).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-- expect(helper.quick_checkout_enabled?(order)).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(helper.quick_checkout_enabled?(order)).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(helper.quick_checkout_enabled?(order)).to be false- end- endend