diff --git a/app/furniture/marketplace/marketplace.rb b/app/furniture/marketplace/marketplace.rb index 605abec60..6f9466041 100644 --- a/app/furniture/marketplace/marketplace.rb +++ b/app/furniture/marketplace/marketplace.rb @@ -15,6 +15,8 @@ class Marketplace < Furniture has_many :delivery_areas, inverse_of: :marketplace, dependent: :destroy + has_many :order_notification_methods, inverse_of: :marketplace, dependent: :destroy + setting :notify_emails setting :stripe_account alias_method :vendor_stripe_account, :stripe_account diff --git a/app/furniture/marketplace/order/received_mailer.rb b/app/furniture/marketplace/order/received_mailer.rb index a6755dafb..dc70908fc 100644 --- a/app/furniture/marketplace/order/received_mailer.rb +++ b/app/furniture/marketplace/order/received_mailer.rb @@ -2,7 +2,7 @@ class Marketplace class Order class ReceivedMailer < Mailer def to - order.marketplace.notify_emails.split(",") + order.marketplace.notify_emails.split(",") + order.marketplace.order_notification_methods.map(&:contact_location) end end end diff --git a/app/furniture/marketplace/order_notification_method.rb b/app/furniture/marketplace/order_notification_method.rb new file mode 100644 index 000000000..dd5fe3fa3 --- /dev/null +++ b/app/furniture/marketplace/order_notification_method.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +class Marketplace + class OrderNotificationMethod < Record + self.table_name = :marketplace_order_notification_methods + location(parent: :marketplace) + belongs_to :marketplace, inverse_of: :order_notification_methods + + has_encrypted :contact_location + validates :contact_location, presence: true + end +end diff --git a/db/migrate/20230615002110_add_marketplace_order_notification_methods.rb b/db/migrate/20230615002110_add_marketplace_order_notification_methods.rb new file mode 100644 index 000000000..0664ca9c1 --- /dev/null +++ b/db/migrate/20230615002110_add_marketplace_order_notification_methods.rb @@ -0,0 +1,10 @@ +class AddMarketplaceOrderNotificationMethods < ActiveRecord::Migration[7.0] + def change + create_table :marketplace_order_notification_methods, id: :uuid do |t| + t.references :marketplace, type: :uuid, foreign_key: {to_table: :furnitures} + t.string :contact_method, default: :email, null: false + t.string :contact_location_ciphertext, null: false + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 951aeb394..5d7d2f8be 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_05_18_014356) do +ActiveRecord::Schema[7.0].define(version: 2023_06_15_002110) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -139,6 +139,15 @@ t.index ["marketplace_id"], name: "index_marketplace_delivery_areas_on_marketplace_id" end + create_table "marketplace_order_notification_methods", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.uuid "marketplace_id" + t.string "contact_method", default: "email", null: false + t.string "contact_location_ciphertext", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["marketplace_id"], name: "index_marketplace_order_notification_methods_on_marketplace_id" + end + create_table "marketplace_orders", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "marketplace_id" t.datetime "created_at", null: false @@ -270,6 +279,7 @@ add_foreign_key "marketplace_cart_products", "marketplace_orders", column: "cart_id" add_foreign_key "marketplace_cart_products", "marketplace_products", column: "product_id" add_foreign_key "marketplace_delivery_areas", "furnitures", column: "marketplace_id" + add_foreign_key "marketplace_order_notification_methods", "furnitures", column: "marketplace_id" add_foreign_key "marketplace_orders", "marketplace_delivery_areas", column: "delivery_area_id" add_foreign_key "marketplace_orders", "marketplace_shoppers", column: "shopper_id" add_foreign_key "marketplace_product_tax_rates", "marketplace_products", column: "product_id"