Jump to content

[SOLVED] Add customer and login via code


hurquiza

Recommended Posts

I'm trying to create a new customer and log him in at the same time via code, yet the cookie is setup it doesn't log in properly.

 

Here's the code I'm using:

require(dirname(__FILE__).'/config/config.inc.php');

$customer=new Customer();
$customer->email='[email protected]';
$customer->lastname='[edit me]';
$customer->firstname='[edit me]';
$customer->passwd='no password';
$customer->add();
$context=Context::getContext();
$context->customer = $customer;
$context->smarty->assign('confirmation', 1);
$context->cookie->id_customer = (int)$customer->id;
$context->cookie->customer_lastname = $customer->lastname;
$context->cookie->customer_firstname = $customer->firstname;
$context->cookie->passwd = $customer->passwd;
$context->cookie->logged = 1;

if (!Configuration::get('PS_REGISTRATION_PROCESS_TYPE'))
	$context->cookie->account_created = 1;
$customer->logged = 1;
$context->cookie->email = $customer->email;
$context->cookie->is_guest = !Tools::getValue('is_new_customer', 1);

I would like to know what I'm missing

 

Thanks!

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

Done, I get a bunch of print_r() output for several objects, I've already tried that earlier but didn't find nothing useful there. Here's the output:

Array
(
    [0] => Array
        (
            [file] => /var/www/presta/classes/Customer.php
            [line] => 478
            [function] => displayError
            [class] => ToolsCore
            [type] => ::
            [args] => Array
                (
                )

        )

    [1] => Array
        (
            [file] => /var/www/presta/classes/Customer.php
            [line] => 771
            [function] => checkPassword
            [class] => CustomerCore
            [type] => ::
            [args] => Array
                (
                    [0] => 13
                    [1] => Su password
                )

        )

    [2] => Array
        (
            [file] => /var/www/presta/classes/Hook.php
            [line] => 295
            [function] => isLogged
            [class] => CustomerCore
            [object] => Customer Object
                (
                    [id] => 13
                    [id_shop] => 1
                    [id_shop_group] => 1
                    [secure_key] => 2b7d44edd3b29850e4f95124389caf49
                    [note] => 
                    [id_gender] => 0
                    [id_default_group] => 3
                    [id_lang] => 3
                    [lastname] => Su apellido
                    [firstname] => Su nombre
                    [birthday] => 0000-00-00
                    [email] => [email protected]
                    [newsletter] => 0
                    [ip_registration_newsletter] => 
                    [newsletter_date_add] => 0000-00-00 00:00:00
                    [optin] => 0
                    [website] => 
                    [company] => 
                    [siret] => 
                    [ape] => 
                    [outstanding_allow_amount] => 0.000000
                    [show_public_prices] => 0
                    [id_risk] => 0
                    [max_payment_days] => 0
                    [passwd] => Su password
                    [last_passwd_gen] => 2013-12-06 04:15:14
                    [active] => 1
                    [is_guest] => 0
                    [deleted] => 0
                    [date_add] => 2013-12-06 10:15:14
                    [date_upd] => 2013-12-06 10:15:14
                    [years] => 
                    [days] => 
                    [months] => 
                    [geoloc_id_country] => 
                    [geoloc_id_state] => 
                    [geoloc_postcode] => 
                    [logged] => 1
                    [id_guest] => 
                    [groupBox] => 
                    [webserviceParameters:protected] => Array
                        (
                            [fields] => Array
                                (
                                    [id_default_group] => Array
                                        (
                                            [xlink_resource] => groups
                                        )

                                    [id_lang] => Array
                                        (
                                            [xlink_resource] => languages
                                        )

                                    [newsletter_date_add] => Array
                                        (
                                        )

                                    [ip_registration_newsletter] => Array
                                        (
                                        )

                                    [last_passwd_gen] => Array
                                        (
                                            [setter] => 
                                        )

                                    [secure_key] => Array
                                        (
                                            [setter] => 
                                        )

                                    [deleted] => Array
                                        (
                                        )

                                    [passwd] => Array
                                        (
                                            [setter] => setWsPasswd
                                        )

                                )

                            [associations] => Array
                                (
                                    [groups] => Array
                                        (
                                            [resource] => group
                                        )

                                )

                        )

                    [id_shop_list] => 
                    [get_shop_from_context:protected] => 1
                    [table:protected] => customer
                    [identifier:protected] => id_customer
                    [fieldsRequired:protected] => Array
                        (
                            [0] => lastname
                            [1] => firstname
                            [2] => email
                            [3] => passwd
                        )

                    [fieldsSize:protected] => Array
                        (
                            [lastname] => 32
                            [firstname] => 32
                            [email] => 128
                            [passwd] => 32
                            [note] => 65000
                        )

                    [fieldsValidate:protected] => Array
                        (
                            [secure_key] => isMd5
                            [lastname] => isName
                            [firstname] => isName
                            [email] => isEmail
                            [passwd] => isPasswd
                            [id_gender] => isUnsignedId
                            [birthday] => isBirthDate
                            [newsletter] => isBool
                            [optin] => isBool
                            [website] => isUrl
                            [company] => isGenericName
                            [siret] => isSiret
                            [ape] => isApe
                            [outstanding_allow_amount] => isFloat
                            [show_public_prices] => isBool
                            [id_risk] => isUnsignedInt
                            [max_payment_days] => isUnsignedInt
                            [active] => isBool
                            [deleted] => isBool
                            [note] => isCleanHtml
                            [is_guest] => isBool
                            [id_shop] => isUnsignedId
                            [id_shop_group] => isUnsignedId
                            [id_lang] => isUnsignedId
                            [date_add] => isDate
                            [date_upd] => isDate
                        )

                    [fieldsRequiredLang:protected] => Array
                        (
                        )

                    [fieldsSizeLang:protected] => Array
                        (
                        )

                    [fieldsValidateLang:protected] => Array
                        (
                        )

                    [tables:protected] => Array
                        (
                        )

                    [image_dir:protected] => 
                    [image_format:protected] => jpg
                    [def:protected] => Array
                        (
                            [table] => customer
                            [primary] => id_customer
                            [fields] => Array
                                (
                                    [secure_key] => Array
                                        (
                                            [type] => 3
                                            [validate] => isMd5
                                            [copy_post] => 
                                        )

                                    [lastname] => Array
                                        (
                                            [type] => 3
                                            [validate] => isName
                                            [required] => 1
                                            [size] => 32
                                        )

                                    [firstname] => Array
                                        (
                                            [type] => 3
                                            [validate] => isName
                                            [required] => 1
                                            [size] => 32
                                        )

                                    [email] => Array
                                        (
                                            [type] => 3
                                            [validate] => isEmail
                                            [required] => 1
                                            [size] => 128
                                        )

                                    [passwd] => Array
                                        (
                                            [type] => 3
                                            [validate] => isPasswd
                                            [required] => 1
                                            [size] => 32
                                        )

                                    [last_passwd_gen] => Array
                                        (
                                            [type] => 3
                                            [copy_post] => 
                                        )

                                    [id_gender] => Array
                                        (
                                            [type] => 1
                                            [validate] => isUnsignedId
                                        )

                                    [birthday] => Array
                                        (
                                            [type] => 5
                                            [validate] => isBirthDate
                                        )

                                    [newsletter] => Array
                                        (
                                            [type] => 2
                                            [validate] => isBool
                                        )

                                    [newsletter_date_add] => Array
                                        (
                                            [type] => 5
                                            [copy_post] => 
                                        )

                                    [ip_registration_newsletter] => Array
                                        (
                                            [type] => 3
                                            [copy_post] => 
                                        )

                                    [optin] => Array
                                        (
                                            [type] => 2
                                            [validate] => isBool
                                        )

                                    [website] => Array
                                        (
                                            [type] => 3
                                            [validate] => isUrl
                                        )

                                    [company] => Array
                                        (
                                            [type] => 3
                                            [validate] => isGenericName
                                        )

                                    [siret] => Array
                                        (
                                            [type] => 3
                                            [validate] => isSiret
                                        )

                                    [ape] => Array
                                        (
                                            [type] => 3
                                            [validate] => isApe
                                        )

                                    [outstanding_allow_amount] => Array
                                        (
                                            [type] => 4
                                            [validate] => isFloat
                                            [copy_post] => 
                                        )

                                    [show_public_prices] => Array
                                        (
                                            [type] => 2
                                            [validate] => isBool
                                            [copy_post] => 
                                        )

                                    [id_risk] => Array
                                        (
                                            [type] => 1
                                            [validate] => isUnsignedInt
                                            [copy_post] => 
                                        )

                                    [max_payment_days] => Array
                                        (
                                            [type] => 1
                                            [validate] => isUnsignedInt
                                            [copy_post] => 
                                        )

                                    [active] => Array
                                        (
                                            [type] => 2
                                            [validate] => isBool
                                            [copy_post] => 
                                        )

                                    [deleted] => Array
                                        (
                                            [type] => 2
                                            [validate] => isBool
                                            [copy_post] => 
                                        )

                                    [note] => Array
                                        (
                                            [type] => 6
                                            [validate] => isCleanHtml
                                            [size] => 65000
                                            [copy_post] => 
                                        )

                                    [is_guest] => Array
                                        (
                                            [type] => 2
                                            [validate] => isBool
                                            [copy_post] => 
                                        )

                                    [id_shop] => Array
                                        (
                                            [type] => 1
                                            [validate] => isUnsignedId
                                            [copy_post] => 
                                        )

                                    [id_shop_group] => Array
                                        (
                                            [type] => 1
                                            [validate] => isUnsignedId
                                            [copy_post] => 
                                        )

                                    [id_default_group] => Array
                                        (
                                            [type] => 1
                                            [copy_post] => 
                                        )

                                    [id_lang] => Array
                                        (
                                            [type] => 1
                                            [validate] => isUnsignedId
                                            [copy_post] => 
                                        )

                                    [date_add] => Array
                                        (
                                            [type] => 5
                                            [validate] => isDate
                                            [copy_post] => 
                                        )

                                    [date_upd] => Array
                                        (
                                            [type] => 5
                                            [validate] => isDate
                                            [copy_post] => 
                                        )

                                )

                            [classname] => Customer
                        )

                    [update_fields:protected] => 
                )

            [type] => ->
            [args] => Array
                (
                )

        )

    [3] => Array
        (
            [file] => /var/www/presta/classes/Hook.php
            [line] => 397
            [function] => getHookModuleExecList
            [class] => HookCore
            [type] => ::
            [args] => Array
                (
                    [0] => moduleRoutes
                )

        )

    [4] => Array
        (
            [file] => /var/www/presta/classes/Dispatcher.php
            [line] => 386
            [function] => exec
            [class] => HookCore
            [type] => ::
            [args] => Array
                (
                    [0] => moduleRoutes
                    [1] => Array
                        (
                            [id_shop] => 
                        )

                    [2] => 
                    [3] => 1
                    [4] => 
                )

        )

    [5] => Array
        (
            [file] => /var/www/presta/classes/Dispatcher.php
            [line] => 232
            [function] => loadRoutes
            [class] => DispatcherCore
            [object] => Dispatcher Object
                (
                    [default_routes] => Array
                        (
                            [category_rule] => Array
                                (
                                    [controller] => category
                                    [rule] => {id}-{rewrite}
                                    [keywords] => Array
                                        (
                                            [id] => Array
                                                (
                                                    [regexp] => [0-9]+
                                                    [param] => id_category
                                                )

                                            [rewrite] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                            [meta_keywords] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                            [meta_title] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                        )

                                )

                            [supplier_rule] => Array
                                (
                                    [controller] => supplier
                                    [rule] => {id}__{rewrite}
                                    [keywords] => Array
                                        (
                                            [id] => Array
                                                (
                                                    [regexp] => [0-9]+
                                                    [param] => id_supplier
                                                )

                                            [rewrite] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                            [meta_keywords] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                            [meta_title] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                        )

                                )

                            [manufacturer_rule] => Array
                                (
                                    [controller] => manufacturer
                                    [rule] => {id}_{rewrite}
                                    [keywords] => Array
                                        (
                                            [id] => Array
                                                (
                                                    [regexp] => [0-9]+
                                                    [param] => id_manufacturer
                                                )

                                            [rewrite] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                            [meta_keywords] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                            [meta_title] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                        )

                                )

                            [cms_rule] => Array
                                (
                                    [controller] => cms
                                    [rule] => content/{id}-{rewrite}
                                    [keywords] => Array
                                        (
                                            [id] => Array
                                                (
                                                    [regexp] => [0-9]+
                                                    [param] => id_cms
                                                )

                                            [rewrite] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                            [meta_keywords] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                            [meta_title] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                        )

                                )

                            [cms_category_rule] => Array
                                (
                                    [controller] => cms
                                    [rule] => content/category/{id}-{rewrite}
                                    [keywords] => Array
                                        (
                                            [id] => Array
                                                (
                                                    [regexp] => [0-9]+
                                                    [param] => id_cms_category
                                                )

                                            [rewrite] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                            [meta_keywords] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                            [meta_title] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                        )

                                )

                            [module] => Array
                                (
                                    [controller] => 
                                    [rule] => module/{module}{/:controller}
                                    [keywords] => Array
                                        (
                                            [module] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9_-]+
                                                    [param] => module
                                                )

                                            [controller] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9_-]+
                                                    [param] => controller
                                                )

                                        )

                                    [params] => Array
                                        (
                                            [fc] => module
                                        )

                                )

                            [product_rule] => Array
                                (
                                    [controller] => product
                                    [rule] => {category:/}{id}-{rewrite}{-:ean13}.html
                                    [keywords] => Array
                                        (
                                            [id] => Array
                                                (
                                                    [regexp] => [0-9]+
                                                    [param] => id_product
                                                )

                                            [rewrite] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                            [ean13] => Array
                                                (
                                                    [regexp] => [0-9\pL]*
                                                )

                                            [category] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                            [categories] => Array
                                                (
                                                    [regexp] => [/_a-zA-Z0-9-\pL]*
                                                )

                                            [reference] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                            [meta_keywords] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                            [meta_title] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                            [manufacturer] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                            [supplier] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                            [price] => Array
                                                (
                                                    [regexp] => [0-9\.,]*
                                                )

                                            [tags] => Array
                                                (
                                                    [regexp] => [a-zA-Z0-9-\pL]*
                                                )

                                        )

                                )

                            [layered_rule] => Array
                                (
                                    [controller] => category
                                    [rule] => {id}-{rewrite}{/:selected_filters}
                                    [keywords] => Array
                                        (
                                            [id] => Array
                                                (
                                                    [regexp] => [0-9]+
                                                    [param] => id_category
                                                )

                                            [selected_filters] => Array
                                                (
                                                    [regexp] => .*
                                                    [param] => selected_filters
                                                )

                                            [rewrite] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                            [meta_keywords] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                            [meta_title] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                        )

                                )

                        )

                    [use_routes:protected] => 1
                    [multilang_activated:protected] => 
                    [routes:protected] => Array
                        (
                        )

                    [controller:protected] => 
                    [request_uri:protected] => /
                    [empty_route:protected] => 
                    [default_controller:protected] => index
                    [controller_not_found:protected] => pagenotfound
                    [front_controller:protected] => 1
                )

            [type] => ->
            [args] => Array
                (
                )

        )

    [6] => Array
        (
            [file] => /var/www/presta/classes/Dispatcher.php
            [line] => 192
            [function] => __construct
            [class] => DispatcherCore
            [object] => Dispatcher Object
                (
                    [default_routes] => Array
                        (
                            [category_rule] => Array
                                (
                                    [controller] => category
                                    [rule] => {id}-{rewrite}
                                    [keywords] => Array
                                        (
                                            [id] => Array
                                                (
                                                    [regexp] => [0-9]+
                                                    [param] => id_category
                                                )

                                            [rewrite] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                            [meta_keywords] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                            [meta_title] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                        )

                                )

                            [supplier_rule] => Array
                                (
                                    [controller] => supplier
                                    [rule] => {id}__{rewrite}
                                    [keywords] => Array
                                        (
                                            [id] => Array
                                                (
                                                    [regexp] => [0-9]+
                                                    [param] => id_supplier
                                                )

                                            [rewrite] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                            [meta_keywords] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                            [meta_title] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                        )

                                )

                            [manufacturer_rule] => Array
                                (
                                    [controller] => manufacturer
                                    [rule] => {id}_{rewrite}
                                    [keywords] => Array
                                        (
                                            [id] => Array
                                                (
                                                    [regexp] => [0-9]+
                                                    [param] => id_manufacturer
                                                )

                                            [rewrite] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                            [meta_keywords] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                            [meta_title] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                        )

                                )

                            [cms_rule] => Array
                                (
                                    [controller] => cms
                                    [rule] => content/{id}-{rewrite}
                                    [keywords] => Array
                                        (
                                            [id] => Array
                                                (
                                                    [regexp] => [0-9]+
                                                    [param] => id_cms
                                                )

                                            [rewrite] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                            [meta_keywords] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                            [meta_title] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                        )

                                )

                            [cms_category_rule] => Array
                                (
                                    [controller] => cms
                                    [rule] => content/category/{id}-{rewrite}
                                    [keywords] => Array
                                        (
                                            [id] => Array
                                                (
                                                    [regexp] => [0-9]+
                                                    [param] => id_cms_category
                                                )

                                            [rewrite] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                            [meta_keywords] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                            [meta_title] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                        )

                                )

                            [module] => Array
                                (
                                    [controller] => 
                                    [rule] => module/{module}{/:controller}
                                    [keywords] => Array
                                        (
                                            [module] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9_-]+
                                                    [param] => module
                                                )

                                            [controller] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9_-]+
                                                    [param] => controller
                                                )

                                        )

                                    [params] => Array
                                        (
                                            [fc] => module
                                        )

                                )

                            [product_rule] => Array
                                (
                                    [controller] => product
                                    [rule] => {category:/}{id}-{rewrite}{-:ean13}.html
                                    [keywords] => Array
                                        (
                                            [id] => Array
                                                (
                                                    [regexp] => [0-9]+
                                                    [param] => id_product
                                                )

                                            [rewrite] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                            [ean13] => Array
                                                (
                                                    [regexp] => [0-9\pL]*
                                                )

                                            [category] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                            [categories] => Array
                                                (
                                                    [regexp] => [/_a-zA-Z0-9-\pL]*
                                                )

                                            [reference] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                            [meta_keywords] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                            [meta_title] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                            [manufacturer] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                            [supplier] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                            [price] => Array
                                                (
                                                    [regexp] => [0-9\.,]*
                                                )

                                            [tags] => Array
                                                (
                                                    [regexp] => [a-zA-Z0-9-\pL]*
                                                )

                                        )

                                )

                            [layered_rule] => Array
                                (
                                    [controller] => category
                                    [rule] => {id}-{rewrite}{/:selected_filters}
                                    [keywords] => Array
                                        (
                                            [id] => Array
                                                (
                                                    [regexp] => [0-9]+
                                                    [param] => id_category
                                                )

                                            [selected_filters] => Array
                                                (
                                                    [regexp] => .*
                                                    [param] => selected_filters
                                                )

                                            [rewrite] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                            [meta_keywords] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                            [meta_title] => Array
                                                (
                                                    [regexp] => [_a-zA-Z0-9-\pL]*
                                                )

                                        )

                                )

                        )

                    [use_routes:protected] => 1
                    [multilang_activated:protected] => 
                    [routes:protected] => Array
                        (
                        )

                    [controller:protected] => 
                    [request_uri:protected] => /
                    [empty_route:protected] => 
                    [default_controller:protected] => index
                    [controller_not_found:protected] => pagenotfound
                    [front_controller:protected] => 1
                )

            [type] => ->
            [args] => Array
                (
                )

        )

    [7] => Array
        (
            [file] => /var/www/presta/index.php
            [line] => 28
            [function] => getInstance
            [class] => DispatcherCore
            [type] => ::
            [args] => Array
                (
                )

        )

)

Link to comment
Share on other sites

Looks like it complains about the password. Can you change your default password to something without a space in it?

Try 'YourPwrd' or so, just to see if that helps. Also the name may be a problem, as there are some '[' ']' in, which might not be acceptable. Try 'Your Name' or so

 

Hope this does something,

pascal.

Link to comment
Share on other sites

Finally got it working!! Pascal gave me the idea with the password thing, in fact there was the error.

 

I was saving the password unencrypted, thus the code to accomplish the task as follows:

<?php

require(dirname(__FILE__).'/config/config.inc.php');

$context=Context::getContext();
$_POST['lastname']='Chavez';
$_POST['firstname']='Hugo';
$_POST['customer_lastname']=$_POST['lastname'];
$_POST['customer_firstname']=$_POST['firstname'];
$_POST['phone']='5411123456780';
$_POST['email']='[email protected]';

// Checked the user address in case he changed his email address
if (Validate::isEmail($email = Tools::getValue('email')) && !empty($email))
	if (Customer::customerExists($email))
		die('An account using this email address has already been registered.');
// Preparing customer
$customer = new Customer();
$lastnameAddress = Tools::getValue('lastname');
$firstnameAddress = Tools::getValue('firstname');		
$_POST['lastname'] = Tools::getValue('customer_lastname');
$_POST['firstname'] = Tools::getValue('customer_firstname');
$error_phone = false;
$customer->lastname=$lastnameAddress;
$customer->firstname =$firstnameAddress;
$pwd='wsxedc';
$customer->passwd=md5(pSQL(_COOKIE_KEY_.$pwd));
$customer->email=$_POST['email'];

if (Configuration::get('PS_ONE_PHONE_AT_LEAST'))
{
	if (Tools::isSubmit('submitGuestAccount') || !Tools::getValue('is_new_customer'))
	{
		if (!Tools::getValue('phone') && !Tools::getValue('phone_mobile'))
			$error_phone = true;
	}
	elseif (((Configuration::get('PS_REGISTRATION_PROCESS_TYPE') && Configuration::get('PS_ORDER_PROCESS_TYPE')) 
			|| (Configuration::get('PS_ORDER_PROCESS_TYPE') && !Tools::getValue('email_create')))
			&& (!Tools::getValue('phone') && !Tools::getValue('phone_mobile')))
		$error_phone = true;
	elseif (((Configuration::get('PS_REGISTRATION_PROCESS_TYPE') && Configuration::get('PS_ORDER_PROCESS_TYPE') && Tools::getValue('email_create')))
			&& (!Tools::getValue('phone') && !Tools::getValue('phone_mobile')))
		$error_phone = true;
}

if ($error_phone)
	die('You must register at least one phone number.');

if (!Configuration::get('PS_REGISTRATION_PROCESS_TYPE') && !Tools::isSubmit('submitGuestAccount'))
{

	$customer->firstname = Tools::ucwords($customer->firstname);
	$customer->birthday = (empty($_POST['years']) ? '' : (int)$_POST['years'].'-'.(int)$_POST['months'].'-'.(int)$_POST['days']);
	if (!Validate::isBirthDate($customer->birthday))
		die('Invalid date of birth.');

	// New Guest customer
	$customer->is_guest = (Tools::isSubmit('is_new_customer') ? !Tools::getValue('is_new_customer', 1) : 0);
	$customer->active = 1;

	if ($customer->add())
	{
		updateContext($customer);
		//$context->cart->update();
	/*	Hook::exec('actionCustomerAccountAdd', array(
				'_POST' => $_POST,
				'newCustomer' => $customer
			));*/
		die("listo?");
	}
	else
		die('An error occurred while creating your account.');
}

function updateContext(Customer $customer)
{
	global $context;

	$context->customer = $customer;
	$context->smarty->assign('confirmation', 1);
	$context->cookie->id_customer = (int)$customer->id;
	$context->cookie->customer_lastname = $customer->lastname;
	$context->cookie->customer_firstname = $customer->firstname;
	$context->cookie->passwd = $customer->passwd;
	$context->cookie->logged = 1;
	// if register process is in two steps, we display a message to confirm account creation
	if (!Configuration::get('PS_REGISTRATION_PROCESS_TYPE'))
		$context->cookie->account_created = 1;
	$customer->logged = 1;
	$context->cookie->email = $customer->email;
	$context->cookie->is_guest = !Tools::getValue('is_new_customer', 1);
	// Update cart address
	$context->cart->secure_key = $customer->secure_key;
}

Thank you very much guys!

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

  • 4 weeks later...

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