Jump to content

Creating a new customer account from Prestashop on eFront using eFront's API


Recommended Posts

HI, I'm trying to merge Prestashop with eFront Learning Management System without using jFusion which doesn't work well for me.

 

Essentially, I'm trying to create an account on eFront automatically when a user signs up for an account on Prestashop.  I've managed to use an eFront API script and added it to the "processSubmitCreate" function.  I got it to work when I hard coded variables, like password, firstname, lastname and email in the script so I know it works. 

 

I'm trying to pass on the variables listed above from the create account function to this script but the variables doesn't seem to want to pass to it.  Can anyone tell me what I'm doing wrong? 

 

Right now, I'm getting a technical error (TECHNICAL ERROR: unable to load form. Details: Error thrown: [object Object] Text status: parsererror).  See the code below:

 

protected function processSubmitCreate()
    {
        if (!Validate::isEmail($email = Tools::getValue('email_create')) || empty($email))
            $this->errors[] = Tools::displayError('Invalid email address.');
        elseif (Customer::customerExists($email))
        {
            $this->errors[] = Tools::displayError('An account using this email address has already been registered. Please enter a valid password or request a new one. ', false);
            $_POST['email'] = $_POST['email_create'];
            unset($_POST['email_create']);
        }
        else
        {
            $this->create_account = true;
            $this->context->smarty->assign('email_create', Tools::safeOutput($email));
            $_POST['email'] = $email;
        }
        $api_url = 'http://localhost/efront3.6.14/www/api.php';
        $admin_id = 'admin-username';
        $admin_pw = 'admin-password';
        
        if ($stream = fopen($api_url.'?action=token', 'r')) {
            $token = stream_get_contents($stream);
            $token = preg_replace('#</?token[^>]*>#is', '', $token);
            fclose($stream);
        }
        
        
        if ($stream = fopen($api_url.'?action=login&username='.$admin_id.'&password='.$admin_pw.'&token='.$token, 'r')) {
            $login = stream_get_contents($stream);
            fclose($stream);
        }
        
        
        if ($stream = fopen($api_url.'?action=create_user&login=new&password='.$customer->passwd.'&name='.$customer->firstname.'&surname='.$customer->lastname.'&email='.$customer->email.'&languages=english&token='.$token, 'r')) {
            $create = stream_get_contents($stream);
            fclose($stream);
        }
    }

Link to comment
Share on other sites

I would really appreciate some help on this matter.   My other option is to write a function to pull the data from the database that was just created and run the script above to interface with eFront's API.  I just thought there'd be a way to use the captured data from the account create form and submit it that way.

 

No thoughts?

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