From f73c32ce4bafe28c769f328f5ecc9f1fd8c0c2f7 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 10 Mar 2021 16:44:32 +1100 Subject: [PATCH] Move rendering logic of terms to helper Preparing for a third option to display. --- app/helpers/terms_and_conditions_helper.rb | 10 ++++++++++ app/views/checkout/_form.html.haml | 3 +-- app/views/checkout/_terms_and_conditions.html.haml | 7 +++---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/helpers/terms_and_conditions_helper.rb b/app/helpers/terms_and_conditions_helper.rb index 554272dcd8..1b86ce0dbe 100644 --- a/app/helpers/terms_and_conditions_helper.rb +++ b/app/helpers/terms_and_conditions_helper.rb @@ -1,6 +1,16 @@ # frozen_string_literal: true module TermsAndConditionsHelper + def render_terms_and_conditions + if platform_terms_required? && terms_and_conditions_activated? + render("checkout/terms_and_conditions") + render("checkout/platform_terms_of_service") + elsif platform_terms_required? + render "checkout/platform_terms_of_service" + elsif terms_and_conditions_activated? + render "checkout/terms_and_conditions" + end + end + def platform_terms_required? Spree::Config.shoppers_require_tos end diff --git a/app/views/checkout/_form.html.haml b/app/views/checkout/_form.html.haml index c63ed0f93f..84601fd410 100644 --- a/app/views/checkout/_form.html.haml +++ b/app/views/checkout/_form.html.haml @@ -15,8 +15,7 @@ = render "checkout/shipping", f: f = render "checkout/payment", f: f = render "checkout/already_ordered", f: f if show_bought_items? - = render "checkout/terms_and_conditions" - = render "checkout/platform_terms_of_service" if platform_terms_required? + = render_terms_and_conditions %p %button.button.primary{ type: :submit, ng: { disabled: "terms_and_conditions_accepted == false || platform_tos_accepted == false" } } = t :checkout_send diff --git a/app/views/checkout/_terms_and_conditions.html.haml b/app/views/checkout/_terms_and_conditions.html.haml index 13c0a1986e..e84b4b9c81 100644 --- a/app/views/checkout/_terms_and_conditions.html.haml +++ b/app/views/checkout/_terms_and_conditions.html.haml @@ -1,4 +1,3 @@ -- if terms_and_conditions_activated? - %p - %input{ type: 'checkbox', id: 'accept_terms', ng: { model: "terms_and_conditions_accepted", init: "terms_and_conditions_accepted=#{terms_and_conditions_already_accepted?}" } } - %label.small{for: "accept_terms"}= t('.message_html', terms_and_conditions_link: link_to( t( '.link_text' ), current_order.distributor.terms_and_conditions.url, target: '_blank')) +%p + %input{ type: 'checkbox', id: 'accept_terms', ng: { model: "terms_and_conditions_accepted", init: "terms_and_conditions_accepted=#{terms_and_conditions_already_accepted?}" } } + %label.small{for: "accept_terms"}= t('.message_html', terms_and_conditions_link: link_to( t( '.link_text' ), current_order.distributor.terms_and_conditions.url, target: '_blank'))