mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-19 04:49:15 +00:00
Allow fast checkout without re-accepting old terms
We did that for the shop's terms already and now do it for the platform terms as well.
This commit is contained in:
@@ -23,6 +23,19 @@ module TermsAndConditionsHelper
|
||||
current_order.distributor.terms_and_conditions.file?
|
||||
end
|
||||
|
||||
def all_terms_and_conditions_already_accepted?
|
||||
platform_tos_already_accepted? && terms_and_conditions_already_accepted?
|
||||
end
|
||||
|
||||
def platform_tos_already_accepted?
|
||||
customer_terms_and_conditions_accepted_at = spree_current_user&.
|
||||
customer_of(current_order.distributor)&.terms_and_conditions_accepted_at
|
||||
|
||||
customer_terms_and_conditions_accepted_at.present? &&
|
||||
(customer_terms_and_conditions_accepted_at >
|
||||
TermsOfServiceFile.updated_at)
|
||||
end
|
||||
|
||||
def terms_and_conditions_already_accepted?
|
||||
customer_terms_and_conditions_accepted_at = spree_current_user&.
|
||||
customer_of(current_order.distributor)&.terms_and_conditions_accepted_at
|
||||
|
||||
@@ -13,4 +13,10 @@ class TermsOfServiceFile < ApplicationRecord
|
||||
def self.current_url
|
||||
current&.attachment&.url || Spree::Config.footer_tos_url
|
||||
end
|
||||
|
||||
# If no file has been uploaded, we don't know when the old terms have
|
||||
# been updated last. So we return the most recent possible update time.
|
||||
def self.updated_at
|
||||
current&.updated_at || Time.zone.now
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
%p
|
||||
%input{ type: 'checkbox', id: 'accept_terms', ng: { model: "terms_and_conditions_accepted", init: "terms_and_conditions_accepted=false" } }
|
||||
%input{ type: 'checkbox', id: 'accept_terms', ng: { model: "terms_and_conditions_accepted", init: "terms_and_conditions_accepted = #{all_terms_and_conditions_already_accepted?}" } }
|
||||
%label.small{for: "accept_terms"}
|
||||
= t('.message_html', terms_and_conditions_link: link_to( t(".terms_and_conditions"), current_order.distributor.terms_and_conditions.url, target: '_blank'), tos_link: link_to_platform_terms)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
%p
|
||||
%input{ type: "checkbox", id: "platform_tos_accepted", ng: { model: "platform_tos_accepted", init: "platform_tos_accepted = false" } }
|
||||
%input{ type: "checkbox", id: "platform_tos_accepted", ng: { model: "platform_tos_accepted", init: "platform_tos_accepted = #{platform_tos_already_accepted?}" } }
|
||||
%label.small{for: "platform_tos_accepted"}
|
||||
= t(".message_html", tos_link: link_to_platform_terms)
|
||||
|
||||
Reference in New Issue
Block a user