mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Per review comment, Use named value on voucher submit button to distinguish between submission types
The voucher apply button is inside form that has another a submit button, it leads to a weird situation where either one will submit the whole payments page form. Adding a named parameter on the voucher apply button means we can distinguish between the two by checking for the presence of params[:apply_voucher].
This commit is contained in:
committed by
Maikel Linke
parent
92bcd937dc
commit
b80274f49d
@@ -30,11 +30,7 @@ class SplitCheckoutController < ::BaseController
|
||||
end
|
||||
|
||||
def update
|
||||
if add_voucher
|
||||
return render_voucher_section_or_redirect
|
||||
elsif @order.errors.present?
|
||||
return render_error
|
||||
end
|
||||
return process_voucher if params[:apply_voucher].present?
|
||||
|
||||
if confirm_order || update_order
|
||||
return if performed?
|
||||
@@ -206,8 +202,19 @@ class SplitCheckoutController < ::BaseController
|
||||
selected_shipping_method.first.require_ship_address == false
|
||||
end
|
||||
|
||||
def process_voucher
|
||||
if add_voucher
|
||||
render_voucher_section_or_redirect
|
||||
elsif @order.errors.present?
|
||||
render_error
|
||||
end
|
||||
end
|
||||
|
||||
def add_voucher
|
||||
return unless payment_step? && params.dig(:order, :voucher_code).present?
|
||||
if params.dig(:order, :voucher_code).blank?
|
||||
@order.errors.add(:voucher, I18n.t('split_checkout.errors.voucher_not_found'))
|
||||
return false
|
||||
end
|
||||
|
||||
# Fetch Voucher
|
||||
voucher = Voucher.find_by(code: params[:order][:voucher_code], enterprise: @order.distributor)
|
||||
|
||||
@@ -16,4 +16,4 @@
|
||||
= t("split_checkout.step2.voucher.warning_forfeit_remaining_amount")
|
||||
- else
|
||||
= text_field_tag "[order][voucher_code]", params.dig(:order, :voucher_code), data: { action: "input->toggle-button-disabled#inputIsChanged", }, placeholder: t("split_checkout.step2.voucher.placeholder") , class: "voucher"
|
||||
= submit_tag t("split_checkout.step2.voucher.apply"), disabled: true, class: "button cancel voucher", "data-disable-with": false, data: { "toggle-button-disabled-target": "button" }
|
||||
= submit_tag t("split_checkout.step2.voucher.apply"), name: "apply_voucher", disabled: true, class: "button cancel voucher", "data-disable-with": false, data: { "toggle-button-disabled-target": "button" }
|
||||
|
||||
@@ -242,6 +242,7 @@ describe SplitCheckoutController, type: :controller do
|
||||
describe "adding a voucher" do
|
||||
let(:checkout_params) do
|
||||
{
|
||||
apply_voucher: "true",
|
||||
order: {
|
||||
voucher_code: voucher.code
|
||||
}
|
||||
@@ -261,6 +262,7 @@ describe SplitCheckoutController, type: :controller do
|
||||
context "when voucher doesn't exist" do
|
||||
let(:checkout_params) do
|
||||
{
|
||||
apply_voucher: "true",
|
||||
order: {
|
||||
voucher_code: "non_voucher"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user