From 4d64bf6ecefd918d4a1873e47ab4f7c5b63e0c77 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Mon, 7 Sep 2020 14:58:23 +0100 Subject: [PATCH] Add column to customers table to register last time enterprise terms and conditions were accepted so customer doesnt have to accept terms on all checkouts but only when the enterprise updates the terms file --- app/views/checkout/_terms_and_conditions.html.haml | 4 +++- ...0555_add_customer_terms_and_conditions_accepted.rb | 5 +++++ db/schema.rb | 11 ++++++----- 3 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 db/migrate/20200907140555_add_customer_terms_and_conditions_accepted.rb diff --git a/app/views/checkout/_terms_and_conditions.html.haml b/app/views/checkout/_terms_and_conditions.html.haml index 6bafd6bbb7..0352ce804f 100644 --- a/app/views/checkout/_terms_and_conditions.html.haml +++ b/app/views/checkout/_terms_and_conditions.html.haml @@ -1,5 +1,7 @@ - terms_and_conditions_activated = current_order.distributor.terms_and_conditions.file? +- customer_terms_and_conditions_accepted_at = spree_current_user.customer_of(current_order.distributor).andand.terms_and_conditions_accepted_at +- terms_and_conditions_already_accepted = customer_terms_and_conditions_accepted_at.present? && (customer_terms_and_conditions_accepted_at > current_order.distributor.terms_and_conditions_updated_at) - if terms_and_conditions_activated %p - %input{ type: 'checkbox', id: 'accept_terms', ng: { model: "terms_and_conditions_accepted", init: "terms_and_conditions_activated=#{terms_and_conditions_activated}" } } + %input{ type: 'checkbox', id: 'accept_terms', ng: { model: "terms_and_conditions_accepted", init: "terms_and_conditions_activated=#{terms_and_conditions_activated}; 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')) diff --git a/db/migrate/20200907140555_add_customer_terms_and_conditions_accepted.rb b/db/migrate/20200907140555_add_customer_terms_and_conditions_accepted.rb new file mode 100644 index 0000000000..c48b1c19f2 --- /dev/null +++ b/db/migrate/20200907140555_add_customer_terms_and_conditions_accepted.rb @@ -0,0 +1,5 @@ +class AddCustomerTermsAndConditionsAccepted < ActiveRecord::Migration + def change + add_column :customers, :terms_and_conditions_accepted_at, :datetime + end +end diff --git a/db/schema.rb b/db/schema.rb index 5f982a1216..30247daf3a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -47,16 +47,17 @@ ActiveRecord::Schema.define(version: 20200912190210) do add_index "coordinator_fees", ["order_cycle_id"], name: "index_coordinator_fees_on_order_cycle_id", using: :btree create_table "customers", force: true do |t| - t.string "email", null: false - t.integer "enterprise_id", null: false + t.string "email", null: false + t.integer "enterprise_id", null: false t.string "code" t.integer "user_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.integer "bill_address_id" t.integer "ship_address_id" t.string "name" - t.boolean "allow_charges", default: false, null: false + t.boolean "allow_charges", default: false, null: false + t.datetime "terms_and_conditions_accepted_at" end add_index "customers", ["bill_address_id"], name: "index_customers_on_bill_address_id", using: :btree