This commit is contained in:
Nicolas Bally 2019-03-26 10:36:34 +01:00
parent 2ef3e0b868
commit 43efa30250
17 changed files with 227 additions and 23 deletions

View File

@ -0,0 +1,26 @@
class Public::ContactProductsController < ApplicationController
layout :get_public_layout
def new
session[:product_ids] = [] if !session[:product_ids]
session[:product_ids] << params[:token]
session[:product_ids] = session[:product_ids].uniq
redirect_to new_public_contact_path(:raison_id => 4)
end
def destroy
session[:product_ids] = [] if !session[:product_ids]
session[:product_ids].delete(params[:id])
redirect_to new_public_contact_path(:raison_id => 4)
end
end

View File

@ -6,11 +6,19 @@ class Public::ContactsController < ApplicationController
end
def new
@contact = Contact.new(:raison_id => params[:raison_id], :survey_set_id => params[:id])
@contact = Contact.new(:raison_id => params[:raison_id], :survey_set_id => params[:id], :provenance_id => 3)
session[:product_qtes] = session[:product_qtes] || {}
if @contact.raison_id == 4 and session[:product_ids] and session[:product_ids].size > 0
session[:product_ids].each do |token|
@contact.contact_products << ContactProduct.new(:d_product => DProduct.find(token), :qte => session[:product_qtes][token])
if @contact.raison_id == 3 and session[:order_document_ids] and session[:order_document_ids].size > 0
session[:order_document_ids].each do |token|
@contact.document_orders << DocumentOrder.new(:data_file => DataFile.find_by_token(token))
end
end
@ -19,12 +27,20 @@ class Public::ContactsController < ApplicationController
def create
@contact = Contact.new(params.require(:contact).permit!)
if @contact.raison_id == 4
@contact.contact_products.each do |contact_product|
session[:product_qtes][contact_product.d_product_id.to_s] = contact_product.qte
end
end
if @contact.save
if @contact.raison_id == 3
@contact.notes = session[:order_document_ids].join(",")
session[:order_document_ids] = []
if @contact.raison_id == 4
@contact.notes = session[:product_ids].join(",")
session[:product_ids] = []
end
@contact.save
QuestionMailer.send_contact(@contact).deliver

View File

@ -3,12 +3,40 @@ class Contact < ActiveRecord::Base
belongs_to :admin
has_many :contact_actions
validates :name, :presence => true
validates :email, :presence => true, :format => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
#validates :email, :presence => true, :if => :email_needed?
validates :email, :format => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :if => :email_needed?
#validates :message, :presence => true
validates :phone, :presence => true
#validates :phone, :presence => true
has_many :contact_files
validates :address, :presence => true, :if => :address_needed?
validates :cp, :presence => true, :if => :address_needed?
validates :city, :presence => true, :if => :address_needed?
has_many :contact_products
has_many :d_products, :through => :contact_products
accepts_nested_attributes_for :contact_products
def email_needed?
true if self.email?
end
def address_needed?
true if self.raison_id == 4
end
before_validation do
if (true or ((raison_id == 4 )) and !self.email? and !self.phone?)
errors.add(:email, "Vous devez indiquer votre numéro de téléphone et/ou votre email")
errors.add(:phone, "Vous devez indiquer votre numéro de téléphone et/ou votre email")
end
end
@ -31,8 +59,8 @@ class Contact < ActiveRecord::Base
:provenance_id => self.provenance_id
}
api_url = "https://groupe-payre.fr/admin/contacts/api"
#api_url ="http://localhost:3030/admin/contacts/api"
#api_url = "https://groupe-payre.fr/admin/contacts/api"
api_url ="http://localhost:3030/admin/contacts/api"
@c = Curl::Easy.new(api_url) do |curl|
curl.verbose = true

View File

@ -0,0 +1,6 @@
class ContactProduct < ActiveRecord::Base
belongs_to :contact
belongs_to :d_product
validates :qte, :presence => true
end

View File

@ -9,6 +9,10 @@
=form.input :name, :label => "Nom :"
=form.input :description, :label => "Description :"
=form.input :orderable, :label => "Demande de devis en ligne ?"
=form.input :unit, :label => "Unité :"
.actions

View File

@ -4,6 +4,31 @@
=f.inputs do
=f.hidden_field :provenance_id
=f.hidden_field :raison_id
-if @contact.raison_id == 4
-p_ids = []
%table
=f.semantic_fields_for :contact_products do |f|
%tr
%td
=f.hidden_field :d_product_id
=image_tag f.object.d_product.icon.file.url
%td
=f.input :qte, :label => "Quantité souhaitée (#{f.object.d_product.unit}) :"
-p_ids << f.object.d_product_id
=link_to "supprimer ce produit", public_contact_product_path(:id => f.object.d_product_id), :method => :delete
-if p_ids.size < DProduct.where(:orderable => true).where("icon_id is not null").count.to_i
%h3
Demander un devis pour les produits suivants également :
#products
-DProduct.where(:orderable => true).where("icon_id is not null").where("id not in (?)", p_ids).order(:name).each do |d_product|
=link_to new_public_contact_product_path(:token => d_product.id) do
=image_tag d_product.icon.file.url
%table{:style => "border-collapse:collapse;width:100%;"}
@ -21,6 +46,22 @@
%td{:colspan => 2}
=f.input :corporate, :label => false, :placeholder => qit("contact organisation","Organisation*")
-if @contact.raison_id == 4
%tr
%td{:colspan => 2}
=f.input :address, :label => false, :placeholder => "Adresse*"
%tr
%td{:colspan => 2}
=f.input :address2, :label => false, :placeholder => "Adresse (suite)"
%tr
%td{:style => "width:50%;vertical-align:top;padding-right:6px;"}
=f.input :cp, :label => false, :placeholder => "Code postal*"
%td{:style => "width:50%;vertical-align:top;padding-left:6px;"}
=f.input :city, :label => false, :placeholder => "Ville*"
%tr
%td{:style => "width:50%;vertical-align:top;padding-right:6px;"}

View File

@ -1,7 +1,17 @@
.submit{:style => "color:white;text-align:left;min-height:300px;"}
%h3 Merci pour votre message !
-if @contact.raison_id == 4
.submit{:style => "text-align:left;min-height:300px;"}
%p Nous mettons tout en œuvre pour vous répondre dans les meilleurs délais.
%h3 Merci pour votre demande !
%p Nous mettons tout en œuvre pour vous répondre dans les meilleurs délais.
-else
.submit{:style => "color:white;text-align:left;min-height:300px;"}
%h3 Merci pour votre message !
%p Nous mettons tout en œuvre pour vous répondre dans les meilleurs délais.

View File

@ -2,6 +2,5 @@
$("#contact_form").html("<%= escape_javascript(render(:partial => "inline_thank")) %>");
<% else %>
$("#form").html("<%= escape_javascript(render(:partial => "thank")) %>");
<% end %>

View File

@ -1,10 +1,14 @@
-if !@new_site
.contact_page
%h1 Contacter 3P
#form=render :partial => "form"
%h1 Demander un devis
#contact_form
#form=render :partial => "form"
:scss
.submit{
color:black !important;
}
-else
-if @contact.raison_id == 3

View File

@ -17,4 +17,7 @@
.render_block
=render @d_product.blocks.find_by_lang_site_id(@lang.id)
.add_product_to_cart
=link_to "Demander un devis pour ce produit !", new_public_contact_product_path(:token => @d_product.id), :class => "btn btn-primary"

View File

@ -2,5 +2,5 @@
-MenuItem.where(:parent_id => nil, :menu_id => 1).order(:position).each do |menu_item|
=menu_item_link(menu_item)
=link_to "Demander un devis","#", :class => "devis"
=link_to "Demander un devis",new_public_contact_path(:raison_id => 4), :class => "devis"

View File

@ -61,6 +61,7 @@ Rails.application.routes.draw do
namespace :public do
resources :contacts
resources :contact_products
resources :specific_maps
resources :specific_map_items

View File

@ -0,0 +1,15 @@
class CreateContactProducts < ActiveRecord::Migration
def change
create_table :contact_products do |t|
t.references :contact, index: true, foreign_key: true
t.references :d_product, index: true, foreign_key: true
t.integer :qte
t.decimal :price_ht
t.decimal :price_ttc
t.decimal :price_tot_ht
t.decimal :price_tot_ttc
t.timestamps null: false
end
end
end

View File

@ -0,0 +1,6 @@
class AddOrderableToDProducts < ActiveRecord::Migration
def change
add_column :d_products, :orderable, :boolean, :default => true
add_column :d_products, :unit, :string, :default => "L"
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20180801225533) do
ActiveRecord::Schema.define(version: 20190325230219) do
create_table "admin_admin_roles", force: :cascade do |t|
t.integer "admin_id", limit: 4
@ -247,6 +247,21 @@ ActiveRecord::Schema.define(version: 20180801225533) do
add_index "contact_actions", ["contact_id"], name: "index_contact_actions_on_contact_id", using: :btree
create_table "contact_products", force: :cascade do |t|
t.integer "contact_id", limit: 4
t.integer "d_product_id", limit: 4
t.integer "qte", limit: 4
t.decimal "price_ht", precision: 10
t.decimal "price_ttc", precision: 10
t.decimal "price_tot_ht", precision: 10
t.decimal "price_tot_ttc", precision: 10
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "contact_products", ["contact_id"], name: "index_contact_products_on_contact_id", using: :btree
add_index "contact_products", ["d_product_id"], name: "index_contact_products_on_d_product_id", using: :btree
create_table "contacts", force: :cascade do |t|
t.string "civilite", limit: 255
t.string "firstname", limit: 255
@ -291,6 +306,8 @@ ActiveRecord::Schema.define(version: 20180801225533) do
t.integer "icon_id", limit: 4
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "orderable", default: true
t.string "unit", limit: 255, default: "L"
end
create_table "data_file_categories", force: :cascade do |t|
@ -1085,6 +1102,8 @@ ActiveRecord::Schema.define(version: 20180801225533) do
add_foreign_key "articles", "article_authors"
add_foreign_key "block_contents", "image_files"
add_foreign_key "category_categoryables", "categories"
add_foreign_key "contact_products", "contacts"
add_foreign_key "contact_products", "d_products"
add_foreign_key "data_file_passwords", "data_files"
add_foreign_key "data_files", "image_files"
add_foreign_key "edit_watchers", "admins"

19
test/fixtures/contact_products.yml vendored Normal file
View File

@ -0,0 +1,19 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
contact_id:
d_product_id:
qte: 1
price_ht: 9.99
price_ttc: 9.99
price_tot_ht: 9.99
price_tot_ttc: 9.99
two:
contact_id:
d_product_id:
qte: 1
price_ht: 9.99
price_ttc: 9.99
price_tot_ht: 9.99
price_tot_ttc: 9.99

View File

@ -0,0 +1,7 @@
require 'test_helper'
class ContactProductTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end