Using Create new customer using CLI like admin approved method as a base I have been pulling my hair out on how to extend it so I can also add an address to the created user via CLI. any assistance is appreciated.

1 Answer 1


After a bit of time. customer.php

class Customer extends AbstractHelper
    const KEY_EMAIL = 'customer-email';
    const KEY_FIRSTNAME = 'customer-firstname';
    const KEY_LASTNAME = 'customer-lastname';
    const KEY_PASSWORD = 'customer-password';
    const KEY_WEBSITE = 'website';
    const KEY_SENDEMAIL = 'send-email';
    const KEY_CITY = 'city';
    const KEY_TELEPHONE = 'telephone';
    const KEY_STREET = 'street';
    const KEY_POSTCODE = 'postcode';
    const KEY_REGION = 'region';


        EmailNotificationInterface $emailNotificationInterface,
        AddressInterfaceFactory $dataAddressFactory,
        AddressRepositoryInterface $addressRepository,
        CollectionFactory $collectionFactory,
        \Magento\Customer\Model\Customer $customer

        $this->dataAddressFactory = $dataAddressFactory;
        $this->addressRepository = $addressRepository;
        $this->collectionFactory = $collectionFactory;
        $this->customer = $customer;

        $city = $this->data->getOption(self::KEY_CITY);
        $telephone = $this->data->getOption(self::KEY_TELEPHONE);
        $street = $this->data->getOption(self::KEY_STREET);
        $postcode = $this->data->getOption(self::KEY_POSTCODE);
        $region = $this->data->getOption(self::KEY_REGION);

    public function saveAddress($customerId, $firstname, $lastname, $street_1, $city, $postcode, $telephone, $region)
        try {
            $address = $this->dataAddressFactory->create();
            $street[] = $street_1;

            $regionData = $this->getRegionCode($region);
            $this->exception = false;
        } catch (\Exception $e) {
            $this->exception = $e;
            return false;

basically details what is required. Hope this helps someone else out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.