I'm using magento v2.2.5 , i successfully insert customer programmatically and after i finished insert the customer , i tried to insert customer address like this:
//load
$customer = $this->insertCustomer();
$data['customer_id'] = $customer->getId();
//create address
/* \Magento\Customer\Model\AddressFactory */
$address = $this->addressFactory->create();
$address = $this->addressDataFactory->setCustomerId($data['customer_id'])
->setFirstname($data['firstname'])
->setLastname($data['lastname'])
->setCountryId($data['country'])
->setRegion($data['region'])
->setPostcode($data['postcode'])
->setCity($data['city'])
->setTelephone($data['main_telephone'])
->setStreet($data['street'])
->setIsDefaultBilling('1')
->setIsDefaultShipping('1')
->setSaveInAddressBook('1');
$address->save();
if i run this code the address is not being be saved in database, but if i add this code die($address->getId());
after $address->save();
the address is being saved in the database table. for example:
...
->setIsDefaultShipping('1')
->setSaveInAddressBook('1');
$address->save();
die($address->getId());