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
Fix payment methods display when payment_sources are available
Szymon Iwacz1421cd521d67
diff --git a/frontend/app/assets/javascripts/spree/frontend/checkout/payment.js b/frontend/app/assets/javascripts/spree/frontend/checkout/payment.jsindex 5ecbbcee2a..6fa7f98fc5 100644--- a/frontend/app/assets/javascripts/spree/frontend/checkout/payment.js+++ b/frontend/app/assets/javascripts/spree/frontend/checkout/payment.js@@ -8,20 +8,7 @@ Spree.ready(function ($) {Spree.onPayment = function () {if ($('#checkout_form_payment').length) {if ($('#existing_cards').length) {- $('#existing_cards').hide()$('#payment-methods').hide()- $("#payment-method-fields label[data-type='card']").click(function() {- $('#existing_cards').show()- $('.payment-sources').show()- $('.existing-cc-radio').first().prop('checked', true)- })- $("#payment-method-fields label:not([data-type='card'])").click(function() {- $('#existing_cards').hide()- $('#payment-methods').hide()- $('.payment-sources').hide()- $('.existing-cc-radio').prop('checked', false)- $('#use_existing_card_no').prop('checked', false)- })$('.existing-cc-radio').click(function () {$(this).prop('checked', true)$('#use_existing_card_no').prop('checked', false)@@ -60,11 +47,26 @@ Spree.ready(function ($) {}$('input[type="radio"][name="order[payments_attributes][][payment_method_id]"]').click(function () {+ $('#payment-methods').hide()+ $('.payment-sources').hide()Spree.enableSave()- if ($('#payment_method_' + this.value).find('fieldset').children().length == 0) {- $('.payment-sources').hide()- } else {- $('.payment-sources').show()+ if ($('#payment_method_' + this.value).find('fieldset').children().length !== 0) {+ if (this.closest('label').dataset.type === 'card') {+ if ($('#existing_cards').length) {+ $('.existing-cc-radio').first().prop('checked', true);+ $('#use_existing_card_no').prop('checked', false)+ $('#use_existing_card_yes').prop('checked', true)+ $('#existing_cards').show();+ $('#payment-methods').hide();+ $('.payment-sources').show()+ }+ } else {+ $('.existing-cc-radio').prop('checked', false);+ $('#use_existing_card_no').prop('checked', false);+ $('#existing_cards').hide();+ $('#payment-methods').show();+ $('.payment-sources').show()+ }}$('#payment-methods li').hide()if (this.checked) {diff --git a/frontend/app/views/spree/checkout/_payment.html.erb b/frontend/app/views/spree/checkout/_payment.html.erbindex 78bd2e9a65..e8dd5cb914 100644--- a/frontend/app/views/spree/checkout/_payment.html.erb+++ b/frontend/app/views/spree/checkout/_payment.html.erb@@ -4,7 +4,6 @@</p><div data-hook="checkout_payment_step">-<%= render partial: 'spree/checkout/payment/storecredit' %><ul id="payment-method-fields" class="list-unstyled position-relative" data-hook>@@ -22,25 +21,7 @@</ul><div class="payment-sources">- <% if @payment_sources.present? %>- <div id="existing_cards" class="payment-sources-existing-cards">- <%= radio_button_tag 'use_existing_card', 'yes', true, class: 'd-none' %>- <div class="form-group" data-hook="existing_cards">- <div class="d-flex flex-column payment-sources-list">- <% @payment_sources.each do |card| %>- <%= render partial: 'credit_card', locals: { card: card } %>- <% end %>- <div>- <label class="form-check-label spree-radio-label col-6 mb-2">- <%= radio_button_tag 'use_existing_card', 'no' %>- <span class="spree-radio-label-custom-input"></span>- <span><%= Spree.t(:add_new_credit_card) %></span>- </label>- </div>- </div>- </div>- </div>- <% end %>+ <%= render partial: 'payment_sources' %><ul id="payment-methods" class="list-unstyled position-relative mb-0 payment-sources-add-form" data-hook><% checkout_available_payment_methods.each do |method| %>diff --git a/frontend/app/views/spree/checkout/_payment_sources.html.erb b/frontend/app/views/spree/checkout/_payment_sources.html.erbnew file mode 100644index 0000000000..502cf85f0c--- /dev/null+++ b/frontend/app/views/spree/checkout/_payment_sources.html.erb@@ -0,0 +1,19 @@+<% if @payment_sources.present? %>+ <div id="existing_cards" class="payment-sources-existing-cards" style="display:none;">+ <%= radio_button_tag 'use_existing_card', 'yes', true, class: 'd-none' %>+ <div class="form-group" data-hook="existing_cards">+ <div class="d-flex flex-column payment-sources-list">+ <% @payment_sources.each do |card| %>+ <%= render partial: 'credit_card', locals: { card: card } %>+ <% end %>+ <div>+ <label class="form-check-label spree-radio-label col-6 mb-2">+ <%= radio_button_tag 'use_existing_card', 'no' %>+ <span class="spree-radio-label-custom-input"></span>+ <span><%= Spree.t(:add_new_credit_card) %></span>+ </label>+ </div>+ </div>+ </div>+ </div>+<% end %>