Skip to content

Commit

Permalink
Use named value on voucher submit button to distinguish between submi…
Browse files Browse the repository at this point in the history
…ssion types
  • Loading branch information
Matt-Yorkley committed May 1, 2023
1 parent 52b4dc1 commit 695b7fa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
19 changes: 13 additions & 6 deletions app/controllers/split_checkout_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ def edit
end

def update
if add_voucher
return render_voucher_section
elsif @order.errors.present?
return render_error
end
return process_voucher if params[:apply_voucher].present?

if confirm_order || update_order
return if performed?
Expand Down Expand Up @@ -196,8 +192,19 @@ def shipping_method_ship_address_not_required?
selected_shipping_method.first.require_ship_address == false
end

def process_voucher
if add_voucher
render_voucher_section
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)
Expand Down
2 changes: 1 addition & 1 deletion app/views/split_checkout/_voucher_section.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,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: { "toggle-button-disabled-target": "button" }, id: "testdisable"
= submit_tag t("split_checkout.step2.voucher.apply"), name: "apply_voucher", disabled: true, class: "button cancel voucher", data: { "toggle-button-disabled-target": "button" }, id: "testdisable"

0 comments on commit 695b7fa

Please sign in to comment.