diff --git a/app/assets/javascripts/templates/partials/contact.html.haml b/app/assets/javascripts/templates/partials/contact.html.haml index 58c8c4a64d..c601f47fd7 100644 --- a/app/assets/javascripts/templates/partials/contact.html.haml +++ b/app/assets/javascripts/templates/partials/contact.html.haml @@ -1,8 +1,12 @@ %div.contact-container - %div.modal-centered{"ng-if" => "::enterprise.email_address || enterprise.website || enterprise.phone"} + %div.modal-centered{"ng-if" => "::enterprise.email_address || enterprise.website || enterprise.phone || enterprise.whatsapp_phone"} %p.modal-header {{'contact' | t}} %p{"ng-if" => "::enterprise.phone", "ng-bind" => "::enterprise.phone"} + %p{"ng-if" => "::enterprise.whatsapp_phone"} + %img{ src: image_path("/map_icons/social-logos/whatsapp.svg") } + %a{"ng-href" => "{{::enterprise.whatsapp_url}}", target: "_blank", "ng-bind" => "::enterprise.whatsapp_phone"} + %p{"ng-if" => "::enterprise.email_address"} %a{"ng-href" => "{{::enterprise.email_address | stripUrl}}", target: "_blank", mailto: true} %span.obfuscatedEmail.email{"ng-bind" => "::enterprise.email_address | stripUrl"} diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index aa7edfc960..5d7892f3ee 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -312,6 +312,10 @@ class Enterprise < ApplicationRecord correct_instagram_url self[:instagram] end + def whatsapp_url + correct_whatsapp_url self[:whatsapp_phone] + end + def inventory_variants if prefers_product_selection_from_inventory_only? Spree::Variant.visible_for(self) @@ -448,6 +452,10 @@ class Enterprise < ApplicationRecord url&.sub(%r{(https?://)?}, '') end + def correct_whatsapp_url(phone_number) + phone_number && "https://wa.me/" + phone_number.tr('+ ', '') + end + def correct_instagram_url(url) url && strip_url(url).sub(%r{www.instagram.com/}, '').delete("@") end diff --git a/app/serializers/api/cached_enterprise_serializer.rb b/app/serializers/api/cached_enterprise_serializer.rb index ef6b37c9cf..bef58f0c77 100644 --- a/app/serializers/api/cached_enterprise_serializer.rb +++ b/app/serializers/api/cached_enterprise_serializer.rb @@ -14,9 +14,9 @@ module Api attributes :name, :id, :description, :latitude, :longitude, :long_description, :website, :instagram, :linkedin, :twitter, - :facebook, :is_primary_producer, :is_distributor, :phone, :visible, - :email_address, :hash, :logo, :promo_image, :path, :pickup, :delivery, - :icon, :icon_font, :producer_icon_font, :category + :facebook, :is_primary_producer, :is_distributor, :phone, :whatsapp_phone, + :whatsapp_url, :visible, :email_address, :hash, :logo, :promo_image, :path, :pickup, + :delivery, :icon, :icon_font, :producer_icon_font, :category attributes :taxons, :supplied_taxons diff --git a/app/serializers/api/enterprise_shopfront_serializer.rb b/app/serializers/api/enterprise_shopfront_serializer.rb index 894152778f..ae0e30ff66 100644 --- a/app/serializers/api/enterprise_shopfront_serializer.rb +++ b/app/serializers/api/enterprise_shopfront_serializer.rb @@ -7,9 +7,9 @@ module Api attributes :name, :id, :description, :latitude, :longitude, :long_description, :website, :instagram, :linkedin, :twitter, :facebook, :is_primary_producer, :is_distributor, - :phone, :visible, :email_address, :hash, :logo, :promo_image, :path, :category, - :active, :producers, :orders_close_at, :hubs, :taxons, :supplied_taxons, :pickup, - :delivery, :preferred_product_low_stock_display + :phone, :whatsapp_phone, :whatsapp_url, :visible, :email_address, :hash, :logo, + :promo_image, :path, :category, :active, :producers, :orders_close_at, :hubs, + :taxons, :supplied_taxons, :pickup, :delivery, :preferred_product_low_stock_display has_one :address, serializer: Api::AddressSerializer has_many :supplied_properties, serializer: Api::PropertySerializer diff --git a/app/services/permitted_attributes/enterprise.rb b/app/services/permitted_attributes/enterprise.rb index 2c7346eaf7..5aff8fbb76 100644 --- a/app/services/permitted_attributes/enterprise.rb +++ b/app/services/permitted_attributes/enterprise.rb @@ -25,10 +25,10 @@ module PermittedAttributes def self.basic_permitted_attributes [ :id, :name, :visible, :permalink, :owner_id, :contact_name, :email_address, :phone, - :is_primary_producer, :sells, :website, :facebook, :instagram, :linkedin, :twitter, - :description, :long_description, :logo, :promo_image, :terms_and_conditions, - :allow_guest_orders, :allow_order_changes, :require_login, :enable_subscriptions, - :abn, :acn, :charges_sales_tax, :display_invoice_logo, :invoice_text, + :whatsapp_phone, :is_primary_producer, :sells, :website, :facebook, :instagram, :linkedin, + :twitter, :description, :long_description, :logo, :promo_image, :terms_and_conditions, + :allow_guest_orders, :allow_order_changes, :require_login, :enable_subscriptions, :abn, + :acn, :charges_sales_tax, :display_invoice_logo, :invoice_text, :preferred_product_selection_from_inventory_only, :preferred_shopfront_message, :preferred_shopfront_closed_message, :preferred_shopfront_taxon_order, :preferred_shopfront_producer_order, :preferred_shopfront_order_cycle_order, diff --git a/app/views/admin/enterprises/form/_contact.html.haml b/app/views/admin/enterprises/form/_contact.html.haml index 61f7eb341d..cfcc19a417 100644 --- a/app/views/admin/enterprises/form/_contact.html.haml +++ b/app/views/admin/enterprises/form/_contact.html.haml @@ -15,6 +15,13 @@ = f.label :phone, t('.phone') .omega.eight.columns = f.text_field :phone, { placeholder: t('.phone_placeholder') } +.row + .alpha.three.columns + = f.label :whatsapp_phone, t('.whatsapp_phone') + %div{'ofn-with-tip' => t('.whatsapp_phone_tip')} + %a= t('admin.whats_this') + .omega.eight.columns + = f.text_field :whatsapp_phone, { placeholder: t('.whatsapp_phone_placeholder') } .row .alpha.three.columns = f.label :website, t('.website') diff --git a/app/views/producers/_fat.html.haml b/app/views/producers/_fat.html.haml index 54e7c7298a..4f10a189fb 100644 --- a/app/views/producers/_fat.html.haml +++ b/app/views/producers/_fat.html.haml @@ -38,6 +38,11 @@ = t :producers_contact_phone %span{"ng-bind" => "::producer.phone"} + %p.word-wrap{"ng-if" => "::producer.whatsapp_phone"} + %a{"ng-href" => "{{::producer.whatsapp_url}}", target: "_blank"} + %img{ src: image_pack_path("social-logos/whatsapp.svg") } + %span{"ng-bind" => "::producer.whatsapp_phone"} + %p.word-wrap{"ng-if" => "::producer.email_address"} %a{"ng-href" => "{{::producer.email_address | stripUrl}}", target: "_blank", mailto: true} %span.obfuscatedEmail.email{"ng-bind" => "::producer.email_address | stripUrl"} diff --git a/app/views/registration/steps/_contact.html.haml b/app/views/registration/steps/_contact.html.haml index eed9c25c73..370101ada3 100644 --- a/app/views/registration/steps/_contact.html.haml +++ b/app/views/registration/steps/_contact.html.haml @@ -24,6 +24,10 @@ .small-12.columns.field %label{ for: 'enterprise_phone' }= t(".phone_field")+":" %input.chunky.small-12.columns{ id: 'enterprise_phone', name: 'phone', placeholder: "{{'registration.steps.contact.phone_field_placeholder' | t}}", ng: { model: 'enterprise.phone' } } + .row + .small-12.columns.field + %label{ "for" => 'enterprise_whatsapp_phone', 'data-toggle' => "tooltip", 'title' => "{{'registration.steps.contact.whatsapp_phone_tooltip' | t}}" }= t(".whatsapp_phone_field")+":" + %input.chunky.small-12.columns{ id: 'enterprise_whatsapp_phone', name: 'whatsapp_phone', placeholder: "{{'registration.steps.contact.whatsapp_phone_field_placeholder' | t}}", ng: { model: 'enterprise.whatsapp_phone' } } .small-12.medium-12.large-5.hide-for-small-only .row.buttons diff --git a/app/views/shopping_shared/tabs/_contact.html.haml b/app/views/shopping_shared/tabs/_contact.html.haml index cf8cf6da5f..cbad4a1966 100644 --- a/app/views/shopping_shared/tabs/_contact.html.haml +++ b/app/views/shopping_shared/tabs/_contact.html.haml @@ -18,7 +18,7 @@ = current_distributor.address.zipcode .small-12.large-4.columns - - if current_distributor.website || current_distributor.email_address || current_distributor.phone + - if current_distributor.website || current_distributor.email_address || current_distributor.phone || current_distributor.whatsapp_phone %div.center .header = t :shopping_contact_web @@ -26,6 +26,11 @@ - if current_distributor.phone.present? = current_distributor.phone %br + - if current_distributor.whatsapp_phone.present? + %a{href: current_distributor.whatsapp_url, target: "_blank" } + %img{ src: image_pack_path("social-logos/whatsapp.svg") } + = current_distributor.whatsapp_phone + %br - if current_distributor.website.present? %a{href: "http://#{current_distributor.website}", target: "_blank" } = current_distributor.website diff --git a/app/webpacker/images/social-logos/whatsapp.svg b/app/webpacker/images/social-logos/whatsapp.svg new file mode 100644 index 0000000000..ca946b5520 --- /dev/null +++ b/app/webpacker/images/social-logos/whatsapp.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 80b27b4a2f..59c0faed04 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -888,6 +888,9 @@ en: email_address_tip: "This email address will be displayed in your public profile" phone: Phone phone_placeholder: eg. 98 7654 3210 + whatsapp_phone: WhatsApp phone number + whatsapp_phone_placeholder: eg. +61 4 9876 5432 + whatsapp_phone_tip: "This number will be displayed in your public profile to be opened as a WhatsApp link." website: Website website_placeholder: eg. www.truffles.com enterprise_fees: @@ -2339,7 +2342,10 @@ See the %{link} to find out more about %{sitename}'s features and to start using contact_field_placeholder: "Contact Name" contact_field_required: "You need to enter a primary contact." phone_field: "Phone number" + whatsapp_phone_field: "WhatsApp phone number" + whatsapp_phone_tooltip: "This number will be displayed in your public profile to be opened as a WhatsApp link." phone_field_placeholder: "eg. (03) 1234 5678" + whatsapp_phone_field_placeholder: "eg. +61 4 1234 5678" type: title: "Type" headline: "Last step to add %{enterprise}!" diff --git a/db/migrate/20220603140943_add_whatsapp_phone_to_enterprises.rb b/db/migrate/20220603140943_add_whatsapp_phone_to_enterprises.rb new file mode 100644 index 0000000000..e830ca4d5d --- /dev/null +++ b/db/migrate/20220603140943_add_whatsapp_phone_to_enterprises.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddWhatsappPhoneToEnterprises < ActiveRecord::Migration[6.1] + def change + add_column :enterprises, :whatsapp_phone, :string, limit: 255 + end +end diff --git a/db/schema.rb b/db/schema.rb index acee8ae142..9494745876 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -241,6 +241,7 @@ ActiveRecord::Schema.define(version: 2022_06_21_230907) do t.integer "business_address_id" t.boolean "show_customer_names_to_suppliers", default: false, null: false t.string "visible", limit: 255, default: "public", null: false + t.string "whatsapp_phone", limit: 255 t.index ["address_id"], name: "index_enterprises_on_address_id" t.index ["is_primary_producer", "sells"], name: "index_enterprises_on_is_primary_producer_and_sells" t.index ["name"], name: "index_enterprises_on_name", unique: true diff --git a/public/map_icons/social-logos/whatsapp.svg b/public/map_icons/social-logos/whatsapp.svg new file mode 100644 index 0000000000..ca946b5520 --- /dev/null +++ b/public/map_icons/social-logos/whatsapp.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file