Jump to content

Edit History

Welele

Welele

This was my solution:

Thinking about how to solve the problem: forcing customer to register his address in customer registration process, I thought of something that is much easier, just redirect customer to the address register just after customer registration.

The solution was using the actionCustomerAccountAdd hook, in CustomerPersister.php

 

if ($ok) {
            $this->context->updateCustomer($customer);
            $this->context->cart->update();
            $this->sendConfirmationMail($customer);
            Hook::exec('actionCustomerAccountAdd', [
                'newCustomer' => $customer,
                Tools::redirect('index.php?controller=address')  //Redirect after registration
            ]);
        }

Regards

Welele

Welele

On 2/22/2022 at 3:19 PM, wegorz23 said:


Add code inside CustomerPersister.php is good solution.




But if you want add County field, add this code in file override/classes/form/CustomerFormatter.php :

        $countries = Country::getCountries((int)$this->language->id, true, false, false);
        if (count($countries) > 0) {
            $countryField = (new FormField)
                ->setName('id_country')
                ->setType('countrySelect')
                ->setLabel($this->translator->trans('Country', [], 'Shop.Forms.Labels'))
                ->setRequired(true);
            foreach ($countries as $country) {
                $countryField->addAvailableValue(
                    $country['id_country'],
                    $country['country']
                );
            }
            $format[$countryField->getName()] = $countryField;
        }



and this code in file override/classes/form/CustomerPersister.php:
 

//$address->id_country = (int) Tools::getCountry();
					
$address->id_country = (int)Tools::getValue('id_country') > 0 ? Tools::getValue('id_country') : (int) Tools::getCountry();



 

 

Do you know how could be State field? For me is important and if I dont display this field I cannot show any field...

×
×
  • Create New...