mlm
This commit is contained in:
parent
7c6618aa97
commit
489b53d885
@ -1,7 +1,7 @@
|
|||||||
class Public::ProductCustomersController < ApplicationController
|
class Public::ProductCustomersController < ApplicationController
|
||||||
layout "public"
|
layout "public"
|
||||||
|
|
||||||
before_filter :auth_product_customer, :except => [:new, :create, :confirm]
|
before_filter :auth_product_customer, :except => [:new, :create, :confirm, :find_parrain]
|
||||||
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@ -31,6 +31,14 @@ class Public::ProductCustomersController < ApplicationController
|
|||||||
|
|
||||||
@product_customer = ProductCustomer.new()
|
@product_customer = ProductCustomer.new()
|
||||||
|
|
||||||
|
|
||||||
|
if cookies[:mlm_token] and @parent = ProductCustomer.find_parrain(cookies[:mlm_token])
|
||||||
|
@product_customer.parent_code = @parent.mlm_token.upcase
|
||||||
|
|
||||||
|
elsif params[:p] and @parent = ProductCustomer.find_parrain(params[:p])
|
||||||
|
@product_customer.parent_code = @parent.mlm_token.upcase
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -112,6 +120,24 @@ class Public::ProductCustomersController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def find_parrain
|
||||||
|
@parent = ProductCustomer.find_parrain(params[:parent_code])
|
||||||
|
|
||||||
|
if @parent
|
||||||
|
cookies.permanent[:mlm_token] = @parent.mlm_token
|
||||||
|
else
|
||||||
|
cookies.permanent[:mlm_token] = nil
|
||||||
|
end
|
||||||
|
render layout: false
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def parrainage
|
||||||
|
cookies.permanent[:mlm_token] = params[:mlm_token]
|
||||||
|
redirect_to "/"
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,12 +16,18 @@ class ProductCustomer < ActiveRecord::Base
|
|||||||
|
|
||||||
before_create do
|
before_create do
|
||||||
self.generate_token
|
self.generate_token
|
||||||
|
self.generate_mlm_token
|
||||||
|
|
||||||
self.particular_bill = Particular.create(:particular_type => "facturation", :skip_validation => true)
|
self.particular_bill = Particular.create(:particular_type => "facturation", :skip_validation => true)
|
||||||
self.particular_idem = true
|
self.particular_idem = true
|
||||||
self.particular_send = Particular.create(:particular_type => "expedition", :skip_validation => true)
|
self.particular_send = Particular.create(:particular_type => "expedition", :skip_validation => true)
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def pseudo
|
||||||
|
self.particular_bill.firstname.to_s+" "+self.particular_bill.name.to_s
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def send_password_reset
|
def send_password_reset
|
||||||
@ -43,5 +49,42 @@ class ProductCustomer < ActiveRecord::Base
|
|||||||
end while ProductCustomer.exists?(:token => self.token)
|
end while ProductCustomer.exists?(:token => self.token)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def generate_mlm_token
|
||||||
|
self.mlm_token = loop do
|
||||||
|
|
||||||
|
mlm_token = SecureRandom.hex(3).upcase
|
||||||
|
break mlm_token unless ProductCustomer.exists?(mlm_token: mlm_token)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def self.find_parrain(token)
|
||||||
|
|
||||||
|
|
||||||
|
if token.to_s != ""
|
||||||
|
ProductCustomer.find_by_mlm_token(token.upcase)
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
before_validation do
|
||||||
|
|
||||||
|
if !self.id
|
||||||
|
if self.parent_code?
|
||||||
|
|
||||||
|
if mlm_parent = ProductCustomer.find_parrain(self.parent_code)
|
||||||
|
self.parent_id = mlm_parent.id
|
||||||
|
self.parent_at_create = true
|
||||||
|
else
|
||||||
|
errors.add(:parent_code, "Ce code de recommandation n'est pas valide, merci de vérifier son exactitude. ")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -28,10 +28,7 @@
|
|||||||
|
|
||||||
= stylesheet_link_tag 'public'
|
= stylesheet_link_tag 'public'
|
||||||
= stylesheet_link_tag '/fonts/Advent/stylesheet.css'
|
= stylesheet_link_tag '/fonts/Advent/stylesheet.css'
|
||||||
|
|
||||||
<script src='https://app.neocamino.com/api.js?id=dhd7sy0f' type='text/javascript'></script>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
=javascript_include_tag "http://maps.google.com/maps/api/js?sensor=false®ion=FR"
|
=javascript_include_tag "http://maps.google.com/maps/api/js?sensor=false®ion=FR"
|
||||||
|
10
app/views/public/product_customers/_find_parrain.html.haml
Normal file
10
app/views/public/product_customers/_find_parrain.html.haml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
-if @parent
|
||||||
|
|
||||||
|
%p
|
||||||
|
=qit("recommended-by-form", "Recommandé par")
|
||||||
|
=":"
|
||||||
|
|
||||||
|
%strong
|
||||||
|
= @parent.pseudo
|
||||||
|
%br
|
||||||
|
%br
|
@ -33,11 +33,29 @@
|
|||||||
=qit("your-password","Votre mot de passe")
|
=qit("your-password","Votre mot de passe")
|
||||||
= error
|
= error
|
||||||
|
|
||||||
|
=f.label :parent_code, "Code de recommandation "
|
||||||
|
%p
|
||||||
|
=qit "offre-10-credits-offerts-parainnage" do
|
||||||
|
Profitez d'un bon d'achat de 5€ avec un code de recommandation valide. Si vous n'en avez pas et que quelqu'un vous a parlé du site demandez lui, il en a certainement un !
|
||||||
|
.form-group{:class => ("has-error has-feedback" if @product_customer.errors[:parent_code].size > 0)}
|
||||||
|
=f.text_field :parent_code, :class => "form-control", :placeholder => qit("code-de-recommandation","Code de recommandation"), :onchange => "find_parrain( $(this).val());", :onkeyup => "find_parrain( $(this).val());", :onkeydown => "find_parrain( $(this).val());"
|
||||||
|
-if @product_customer.errors[:parent_code].uniq
|
||||||
|
-@product_customer.errors[:parent_code].uniq.each do |error|
|
||||||
|
.error= error
|
||||||
|
|
||||||
|
|
||||||
|
.parent
|
||||||
|
=render :partial => "public/product_customers/find_parrain"
|
||||||
|
|
||||||
|
|
||||||
=f.submit qit("account-create-save","Créer mon compte !"), :class => "btn btn-primary order_button"
|
=f.submit qit("account-create-save","Créer mon compte !"), :class => "btn btn-primary order_button"
|
||||||
%br
|
%br
|
||||||
%br
|
%br
|
||||||
|
|
||||||
|
:coffeescript
|
||||||
|
@find_parrain = (value) ->
|
||||||
|
$.ajax({url : '/fr/public/product_customers/find_parrain.js', data : {parent_code :value}})
|
||||||
|
|
||||||
|
|
||||||
%br
|
%br
|
||||||
%br
|
%br
|
||||||
|
1
app/views/public/product_customers/find_parrain.js.erb
Normal file
1
app/views/public/product_customers/find_parrain.js.erb
Normal file
@ -0,0 +1 @@
|
|||||||
|
$('.parent').html("<%= escape_javascript(render(:partial => "find_parrain"))%>");
|
@ -0,0 +1,9 @@
|
|||||||
|
class AddMlmToProductCustomers < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :product_customers, :parent_id, :integer
|
||||||
|
add_column :product_customers, :mlm_token, :string
|
||||||
|
add_column :product_customers, :parent_at_create, :boolean
|
||||||
|
add_column :product_customers, :parent_code, :string
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20160426151106) do
|
ActiveRecord::Schema.define(version: 20160428093204) do
|
||||||
|
|
||||||
create_table "admins", force: :cascade do |t|
|
create_table "admins", force: :cascade do |t|
|
||||||
t.string "name", limit: 255
|
t.string "name", limit: 255
|
||||||
@ -574,6 +574,10 @@ ActiveRecord::Schema.define(version: 20160426151106) do
|
|||||||
t.boolean "particular_idem", limit: 1, default: false
|
t.boolean "particular_idem", limit: 1, default: false
|
||||||
t.integer "particular_bill_id", limit: 4
|
t.integer "particular_bill_id", limit: 4
|
||||||
t.integer "particular_send_id", limit: 4
|
t.integer "particular_send_id", limit: 4
|
||||||
|
t.integer "parent_id", limit: 4
|
||||||
|
t.string "mlm_token", limit: 255
|
||||||
|
t.boolean "parent_at_create", limit: 1
|
||||||
|
t.string "parent_code", limit: 255
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "product_fdps", force: :cascade do |t|
|
create_table "product_fdps", force: :cascade do |t|
|
||||||
@ -680,7 +684,7 @@ ActiveRecord::Schema.define(version: 20160426151106) do
|
|||||||
t.string "particular_send_id", limit: 255
|
t.string "particular_send_id", limit: 255
|
||||||
t.string "token", limit: 255
|
t.string "token", limit: 255
|
||||||
t.boolean "completed_finish", limit: 1, default: false
|
t.boolean "completed_finish", limit: 1, default: false
|
||||||
t.integer "product_order_payment_ok", limit: 4
|
t.integer "product_order_payment_ok_id", limit: 4
|
||||||
t.integer "product_order_payment_type_ok_id", limit: 4
|
t.integer "product_order_payment_type_ok_id", limit: 4
|
||||||
t.integer "bill_index", limit: 4
|
t.integer "bill_index", limit: 4
|
||||||
t.string "bill_number", limit: 255
|
t.string "bill_number", limit: 255
|
||||||
|
Loading…
x
Reference in New Issue
Block a user