Jump to content
claudiaIta

Prestashop 1.7 add address in registration Form

Recommended Posts

I hope someone could help with this:

 

after setting up Prestashop 1.7, i saw that diffrently from PS 1.6 ther's no "backoffice>customer> registration process type (standard account creation and address creation)", as in need customer fill its address already in the registration form.

 

How can i merge the address form in the registration form??

 

 

Thanks!

  • Like 1

Share this post


Link to post
Share on other sites

I have the same problem, I need to customers who register on the website to enter all your data, including address. The version of prestashop 1.7 does not allow it. is there any way to perform a full data record? It should be as the record standard in prestashop 1.6

Share this post


Link to post
Share on other sites

Hello

 

Have you find a solution please, I have the same problem, I would lke to have a complete register form with addresses fields;

 

Thank you

Share this post


Link to post
Share on other sites

This should be standard functionality. Really disappointed there is no way to easily add an address field in the registration form.

Share this post


Link to post
Share on other sites

Could anybody advice how I can redirect to add address page after registration if the registration is not done through checkout page?

Share this post


Link to post
Share on other sites

@PrestaPros 

Thanks for this tutorial the only problem with it is how to disable these fields when the user is registering on the checkout page or when editing the identity

Meaning these fields should be only displayed when the user is registering for the first time only!

Share this post


Link to post
Share on other sites

I managed to find a solution by following your instruction but only changing the required to false in case the user wants to edit their personal information.

then in the customer-form.tpl file inside the foreach I added this code
 

        {$address_fields = ['phone','address1','postcode','city']}
        {if $customer.is_logged OR $page.page_name == 'checkout'}
          {if in_array($field.name, $address_fields)}
            {continue}
          {/if}
        {else}
          {if in_array($field.name, $address_fields)}
            {$field.required = true}
          {/if}
        {/if}

 

 

 

 

Share this post


Link to post
Share on other sites

hopefully with prestashop 1.7.5 we would have a real solution :P

 

@PrestaPros
Is it too complicated to add the country field?

Edited by rygar (see edit history)

Share this post


Link to post
Share on other sites

I managed to add the country field through smarty 

Make sure to change in the AuthController.php  to  $address->id_country = Tools::getValue('id_country');

 

        {if $field.name == 'id_country'}
          {$field.type = 'countrySelect'}
          {assign var='countries' value=Country::getCountries((int)$language.id, true)}
          {foreach from=$countries key=k item=v}
            {$field.availableValues.$k = $v.name}
          {/foreach}
        {/if}

 

 

Edited by rygar (see edit history)

Share this post


Link to post
Share on other sites

Hi,

 

I am Thilak Developer. I have implemented this part for my one of the customer.

$customer = new Customer();
                $customer = $customer->getByEmail($this->getValue('email'));
                $address = new Address(
                        null,
                        $this->context->language->id
                    );                    

                $address->address1 = $this->getValue('address1');
                $address->postcode = $this->getValue('postcode');
                $address->city = $this->getValue('city');
                $address->phone = $this->getValue('phone');
                
                $address->firstname = $customer->firstname;
                $address->lastname = $customer->lastname;
                $address->id_customer = (int) $customer->id;
                $address->id_country = $this->getValue('id_country');
                
                $address->id_state = 0;
                $address->alias = 'My Address';                    
                $address->save();

 

 

I added the above code in ContactForm submit event.

 

 

If i want to do this in your site please contact me. But you have to buy me.

 

Thank you

 

Share this post


Link to post
Share on other sites

add this code in CustomerFormatter.php

$format['phone'] = (new FormField)
                    ->setName('phone')
                    ->setLabel(
                        $this->translator->trans(
                            'Phone', [], 'Shop.Forms.Labels'
                        )
                    )
                    ->setRequired(true)
                ;
                $format['address1'] = (new FormField)
                    ->setName('address1')
                    ->setLabel(
                        $this->translator->trans(
                            'Address', [], 'Shop.Forms.Labels'
                        )
                    )
                    ->setRequired(true)
                ;
                $format['postcode'] = (new FormField)
                    ->setName('postcode')
                    ->setLabel(
                        $this->translator->trans(
                            'Zip/Postal Code', [], 'Shop.Forms.Labels'
                        )
                    )
                    ->setRequired(true)
                ;
                $format['city'] = (new FormField)
                    ->setName('city')
                    ->setLabel(
                        $this->translator->trans(
                            'City', [], 'Shop.Forms.Labels'
                        )
                    )
                    ->setRequired(true)
                ;
                $format['vat_number'] = (new FormField)
                    ->setName('vat_number')
                    ->setLabel(
                        $this->translator->trans(
                            'Vat Number', [], 'Shop.Forms.Labels'
                        )
                    )
                    ->setRequired(true)
                ;

--> add this code in AuthController.php

inside  if($hookResult && $register_form->submit()) {


                      //address saving
                    $customer = new Customer();
                    $customer = $customer->getByEmail($register_form->getCustomer()->email);
                    
                    $address = new Address(
                        null,
                        $this->context->language->id
                    );                    

                    $address->id_country = (int) Tools::getCountry();
                    $address->address1 = Tools::getValue('address1');
                    $address->postcode = Tools::getValue('postcode');
                    $address->city = Tools::getValue('city');
                    $address->phone = Tools::getValue('phone');
                    $address->vat_number = Tools::getValue('vat_number');
                    
                    $address->firstname = $customer->firstname;
                    $address->lastname = $customer->lastname;
                    $address->id_customer = (int) $customer->id;
                    
                    $address->id_state = 0;
                    $address->alias = $this->trans('My Address', [], 'Shop.Theme.Checkout');                    
                    
                    if($address->save()){
                        $should_redirect = true;                        
                    } else {
                        $customer->delete();
                        $this->errors[] = $this->trans('Could not update your information, please check your data.', array(), 'Shop.Notifications.Error');
                        $this->redirectWithNotifications($this->getCurrentURL());
                    }
                    
                   // $should_redirect = true;

for Better please visit link 

 

Edited by jayesh_naghera (see edit history)

Share this post


Link to post
Share on other sites

Hi i'm having a problem with this code. I managed to make the address fields appear in the form but i can't get it to save them. I get a 500 error.  Could you please see if i'm doing something wrong?

Here is my AuthController.php override

 

class AuthController extends AuthControllerCore
{
    public $ssl = true;
    public $php_self = 'authentication';
    public $auth = false;

    public function checkAccess()
    {
        if ($this->context->customer->isLogged() && !$this->ajax) {
            $this->redirect_after = ($this->authRedirection) ? urlencode($this->authRedirection) : 'my-account';
            $this->redirect();
        }

        return parent::checkAccess();
    }

    public function initContent()
    {
        $should_redirect = false;

        if (Tools::isSubmit('submitCreate') || Tools::isSubmit('create_account')) {
            $register_form = $this
                ->makeCustomerForm()
                ->setGuestAllowed(false)
                ->fillWith(Tools::getAllValues());

            if (Tools::isSubmit('submitCreate')) {
                $hookResult = array_reduce(
                    Hook::exec('actionSubmitAccountBefore', array(), null, true),
                    function ($carry, $item) {
                        return $carry && $item;
                    },
                    true
                );
                if ($hookResult && $register_form->submit()) {
                    
                    //address saving
                    $customer = new Customer();
                    $customer = $customer->getByEmail($register_form->getCustomer()->email);
                    
                    $address = new Address(
                        null,
                        $this->context->language->id
                    );                    

                    $address->id_country = (int) Tools::getCountry();
                    $address->address1 = Tools::getValue('address1');
                    $address->postcode = Tools::getValue('postcode');
                    $address->city = Tools::getValue('city');
                    $address->phone = Tools::getValue('phone');
                    
                    $address->firstname = $customer->firstname;
                    $address->lastname = $customer->lastname;
                    $address->id_customer = (int) $customer->id;
                    
                    $address->id_state = 0;
                    $address->alias = $this->trans('My Address', [], 'Shop.Theme.Checkout');                    
                    
                    if($address->save()){
                        $should_redirect = true;
                    } else {
                        $customer->delete();
                        $this->errors[] = $this->trans('Could not update your information, please check your data.', array(), 'Shop.Notifications.Error');
                        $this->redirectWithNotifications($this->getCurrentURL());
                    }
                }
                    
                
                {
                    
                    $should_redirect = true;
                }
            }
            

            $this->context->smarty->assign([
                'register_form' => $register_form->getProxy(),
                'hook_create_account_top' => Hook::exec('displayCustomerAccountFormTop'),
            ]);
            $this->setTemplate('customer/registration');
        } else {
            $login_form = $this->makeLoginForm()->fillWith(
                Tools::getAllValues()
            );

            if (Tools::isSubmit('submitLogin')) {
                if ($login_form->submit()) {
                    $should_redirect = true;
                }
            }

            $this->context->smarty->assign([
                'login_form' => $login_form->getProxy(),
            ]);
            $this->setTemplate('customer/authentication');
        }

        parent::initContent();

        if ($should_redirect && !$this->ajax) {
            $back = urldecode(Tools::getValue('back'));

            if (Tools::urlBelongsToShop($back)) {
                // Checks to see if "back" is a fully qualified
                // URL that is on OUR domain, with the right protocol
                return $this->redirectWithNotifications($back);
            }

            // Well we're not redirecting to a URL,
            // so...
            if ($this->authRedirection) {
                // We may need to go there if defined
                return $this->redirectWithNotifications($this->authRedirection);
            }

            // go home
            return $this->redirectWithNotifications(__PS_BASE_URI__);
        }
    }
}

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More