Add a checkbox to checkout to tick for Terms and Conditions

Checkout button should be disabled if checkbox is not ticked
This commit is contained in:
Luis Ramos
2020-09-05 19:33:27 +01:00
parent 6b826423c1
commit 85096a997f
4 changed files with 12 additions and 4 deletions

View File

@@ -16,6 +16,6 @@
= render "checkout/already_ordered", f: f if show_bought_items?
= render "checkout/terms_and_conditions", f: f
%p
%button.button.primary{type: :submit}
%button.button.primary{ type: :submit, ng: { disabled: "terms_and_conditions_activated && !terms_and_conditions_accepted" } }
= t :checkout_send
/ {{ checkout.$valid }}

View File

@@ -1,2 +1,5 @@
%p.small
= t('.message_html', terms_and_conditions_link: link_to( t( '.link_text' ), current_order.distributor.terms_and_conditions.url, target: '_blank')) if current_order.distributor.terms_and_conditions.file?
- terms_and_conditions_activated = current_order.distributor.terms_and_conditions.file?
- if terms_and_conditions_activated
%p.small
%input{ type: 'checkbox', id: 'accept_terms', ng: { model: "terms_and_conditions_accepted", init: "terms_and_conditions_activated=#{terms_and_conditions_activated}" } }
%label{for: "accept_terms"}= t('.message_html', terms_and_conditions_link: link_to( t( '.link_text' ), current_order.distributor.terms_and_conditions.url, target: '_blank'))

View File

@@ -57,7 +57,7 @@ class OrderFactory
bill_address: order_address,
ship_address: order_address
)
order.line_items.create( variant_id: first_variant.id, quantity: 5 )
order.line_items.create(variant_id: first_variant.id, quantity: 5)
order.payments.create(payment_method_id: first_payment_method_id)
order
end

View File

@@ -138,6 +138,11 @@ feature "As a consumer I want to check out my cart", js: true do
it "shows a link to the terms and conditions" do
visit checkout_path
expect(page).to have_link("Terms of Service", href: order.distributor.terms_and_conditions.url)
expect(page).to have_button("Place order now", disabled: true)
check "accept_terms"
expect(page).to have_button("Place order now", disabled: false)
end
end