Jump to content

Add address after customer creation


beaudenheijer

Recommended Posts

Good evening,

 

I'm currently developing a website for a company. I've been using prestashop since 2 weeks ago. but some here and there are a little to complicated.

right now where im stuck at is by adding an address after a creation of the customer in the registration panel.

currently my code look this:

include_once('../config/config.inc.php');
include_once('../init.php');

$context = Context::getContext();
$default_lang = Configuration::get('PS_LANG_DEFAULT');

try
{
    if (isset($_POST['email'], $_POST['voornaam'], $_POST['achternaam'], $_POST['wachtwoord'], $_POST['birthDay'], $_POST['birthMonth'], $_POST['birthYear'], $_POST['gender']))
    {
        // initializing customer
        $customer = new Customer();

        if ($customer->getByEmail($_POST['email'], $_POST['wachtwoord'])) {
            echo "user already exist";
            return;
        }

        // initializing customer details
        $customer->id = 1;
        $customer->email = $_POST['email'];
        $customer->lastname = $_POST['achternaam'];
        $customer->firstname = $_POST['voornaam'];
        $customer->passwd = $_POST['wachtwoord'];
        $customer->id_gender = $_POST['gender.'] === 'Dhr.' ? 0 : 1;
        $customer->birthday = $_POST['birthYear'] . '-' . $_POST['birthMonth'] . '-' . $_POST['birthDay'];

        // adding the customer
        $customer->add();

        if(isset($_POST['adres'], $_POST['number'], $_POST['zip'], $_POST['city'], $_POST['phone_number']))
        {
            $address = new CustomerAddress();

            $address->id = 1;
            $address->id_customer = $customer->id;
            $address->firstname =$customer->firstname;
            $address->lastname = $customer->lastname;
            $address->city = $_POST['city'];
            $address->postcode = $_POST['zip'];
            $address->phone = $_POST['phone_number'];
            $address->address1 = $_POST['adres'] . ' ' . $_POST['number'];
            $address->address2 = '';
            $address->alias = 'Home';

            $address->add();
            $customer->update();
        }
    }
}
catch(PrestaShopException $e)
{
    echo $e;
}

as you can see in the back-end of prestashop you can see a (test user) has been made.

but as you can see down to the bottom that there is nothing while i said in the code to add the address on the customers id.

It would be nice that it could be fixed or something that i missed.

I wish you all a nice evening,

Yours faithfully,

Beau

 

Knipsel.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...