Let people choose which payment methods are available to customers on order cycles

This commit is contained in:
Cillian O'Ruanaidh
2022-10-07 17:14:11 +01:00
parent 5718f9f00c
commit 4e6d64c0a1
18 changed files with 789 additions and 340 deletions

View File

@@ -10,8 +10,6 @@
%fieldset.no-border-bottom
%legend{ align: 'center'}= t('.checkout_options')
= hidden_field_tag "order_cycle[selected_distributor_shipping_method_ids][]", ""
.row
.three.columns
 
@@ -19,10 +17,12 @@
%table.checkout-options
%thead
%tr
%th{ colspan: 2 }= t('.shipping_methods')
%th{ colspan: 2 }
= t('.shipping_methods')
= hidden_field_tag "order_cycle[selected_distributor_shipping_method_ids][]", ""
- @order_cycle.distributors.each do |distributor|
- distributor_shipping_methods = @order_cycle.attachable_distributor_shipping_methods.where("distributor_id = ?", distributor.id).includes(:shipping_method)
%tr{ "data-controller": "select-all" }
%tr{ class: "distributor-#{distributor.id}-shipping-methods", "data-controller": "select-all" }
%td.text-center
- if distributor_shipping_methods.many?
%label
@@ -48,17 +48,36 @@
%p
= t('.no_shipping_methods')
%tr
%th{ colspan: 2 }= t('.payment_methods')
%tr
%td
%td
- if @order_cycle.attachable_payment_methods.available(:both).any?
%ul
- @order_cycle.attachable_payment_methods.available(:both).each do |payment_method|
%li= payment_method.name
- else
%p
= t('.no_payment_methods')
%th{ colspan: 2 }
= t('.payment_methods')
= hidden_field_tag "order_cycle[selected_distributor_payment_method_ids][]", ""
- @order_cycle.distributors.each do |distributor|
- distributor_payment_methods = @order_cycle.attachable_distributor_payment_methods.where("distributor_id = ?", distributor.id).includes(:payment_method)
%tr{ class: "distributor-#{distributor.id}-payment-methods", "data-controller": "select-all" }
%td.text-center
- if distributor_payment_methods.many?
%label
= check_box_tag nil, nil, nil, { "data-action": "change->select-all#toggleAll", "data-select-all-target": "all" }
= t(".select_all")
%td
%em= distributor.name
- distributor_payment_methods.each do |distributor_payment_method|
%p
%label{ class: ("disabled" if distributor_payment_methods.one? || !distributor_payment_method.payment_method.frontend?) }
= check_box_tag "order_cycle[selected_distributor_payment_method_ids][]",
distributor_payment_method.id,
@order_cycle.distributor_payment_methods.include?(distributor_payment_method),
id: "order_cycle_selected_distributor_payment_method_ids_#{distributor_payment_method.id}",
data: ({ "action" => "change->select-all#toggleCheckbox", "select-all-target" => "checkbox" } if distributor_payment_method.payment_method.frontend?)
= distributor_payment_method.payment_method.name
- distributor.payment_methods.inactive_or_backend.each do |payment_method|
%label.disabled
= check_box_tag nil, nil, false, disabled: true
= payment_method.name
= "(#{t('.back_end')})"
- if distributor.payment_methods.available.none?
%p
= t('.no_payment_methods')
%div#save-bar
%div.container