Jump to content

Retrieve new customer variables and insert them in external database


Bewat

Recommended Posts

- When a new customer register in Prestashop 1.7 I need the user to be also registered in another external system, it is a feedback system called phpBack. 

- Basically when he registers I need to insert his new customer values: $id_customer, $firstname, $lastname, $email and $password_hash, into phpBack database called "external" in a table called "users"

- I am successfully able to insert values manually to that database via classes/customer.php, but the thing is I need to retrieve the new user variables like in the following code:

 

<?php
$servername = "localhost";
$username = "external";
$password = "example";
$dbname = "external";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn1) {
    die("Connection failed: " . mysqli_connect_error());
}

$sql1 = "INSERT INTO `users` (`id`, `name`, `email`, `pass`, `votes`, `isadmin`, `banned`) 
VALUES ($id_customer, '$firstname $lastname', '$email', '$passwordhash', 20, 0, 0);";
$result1 = mysqli_query($conn1, $sql1);

?>

Where and how in classes/customer.php can I take the new customer variables $id_customer, '$firstname $lastname', '$email', '$passwordhash' to insert them in external database?

Thanks in advance

Edited by Bewat (see edit history)
Link to comment
Share on other sites

Hello,

You could try to run the sql in add() function.

About the variables:

customer_id : $this->id,

firstname:  $this->firstname,

lastname: $this->lastname,

email: $this->email,

about the password, you can get it with $this->passwd.

And before the insert you can assign to the password, the hashed value.

In customer.php line ~401 you will see the $crypto variable, that is called to hash the password entered, you can use that example.

Link to comment
Share on other sites

11 hours ago, Presta Bucket said:

Hello,

You could try to run the sql in add() function.

About the variables:

customer_id : $this->id,

firstname:  $this->firstname,

lastname: $this->lastname,

email: $this->email,

about the password, you can get it with $this->passwd.

And before the insert you can assign to the password, the hashed value.

In customer.php line ~401 you will see the $crypto variable, that is called to hash the password entered, you can use that example.

Hi

Thanks very much for your answer. I have tried as much as I can your suggestion but it seems the variable values I get for the new customer in customer.php are empty, not matter where I place the code. 

Could you please let me know if it is not too much effort the code to insert and where in customer.php? Is there any other file that should I edit? 

Link to comment
Share on other sites

  • 2 weeks later...
On 12/30/2018 at 12:11 PM, Bewat said:

Hi

Thanks very much for your answer. I have tried as much as I can your suggestion but it seems the variable values I get for the new customer in customer.php are empty, not matter where I place the code. 

Could you please let me know if it is not too much effort the code to insert and where in customer.php? Is there any other file that should I edit? 

Hello,

I attached 2 photos with a example code for insert, in the first screenshot you can see the lines in the left side and the code.

The code is written in customer.php.

In the second screenshot there is data inserted into the test table.

Screen Shot 2019-01-08 at 11.30.52 PM.png

Screen Shot 2019-01-08 at 11.33.36 PM.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...