Jump to content

Add a new customer to the data base manualy


DevelopperK

Recommended Posts

  • DevelopperK changed the title to Add a new customer to the data base manualy
  • 4 weeks later...

It would be better practice to create a function

 

    /**
     * @return bool
     *
     * @throws PrestaShopException
     */
    public function createNewCustomer()
    {
        /** @var Hashing $crypto */
        $crypto = ServiceLocator::get(Hashing::class);
       // create a new customer
        $customer = new Customer();
        $customer->id_gender = 1;
        $customer->lastname = 'Jane';
        $customer->firstname = 'Meldrum';
        $customer->email = 'meldrum@example.com';
        $customer->passwd = $crypto->hash('customer_password'); // generate encrypted password
        $customer->active = true;

        if ($customer->save() == false) {
            return false;
        }

        unset($customer);

        return true;
    }

 

It would also be recommended to add the namespaces in the controller before the class

class ProfileExpertProfileExpertfModuleFrontController extends ModuleFrontController

use PrestaShop\PrestaShop\Adapter\ServiceLocator;
use PrestaShop\PrestaShop\Core\Crypto\Hashing;

 

Link to comment
Share on other sites

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