customer_address.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /**
  3. * Customer address fixture with entity_id = 1
  4. *
  5. * Copyright © Magento, Inc. All rights reserved.
  6. * See COPYING.txt for license details.
  7. */
  8. $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
  9. /** @var \Magento\Customer\Model\Address $customerAddress */
  10. $customerAddress = $objectManager->create(\Magento\Customer\Model\Address::class);
  11. /** @var \Magento\Customer\Model\CustomerRegistry $customerRegistry */
  12. $customerRegistry = $objectManager->get(\Magento\Customer\Model\CustomerRegistry::class);
  13. $customerAddress->isObjectNew(true);
  14. $customerAddress->setData(
  15. [
  16. 'entity_id' => 1,
  17. 'attribute_set_id' => 2,
  18. 'telephone' => 3468676,
  19. 'postcode' => 75477,
  20. 'country_id' => 'US',
  21. 'city' => 'CityM',
  22. 'company' => 'CompanyName',
  23. 'street' => 'Green str, 67',
  24. 'lastname' => 'Smith',
  25. 'firstname' => 'John',
  26. 'parent_id' => 1,
  27. 'region_id' => 1,
  28. ]
  29. );
  30. $customerAddress->save();
  31. /** @var \Magento\Customer\Api\AddressRepositoryInterface $addressRepository */
  32. $addressRepository = $objectManager->get(\Magento\Customer\Api\AddressRepositoryInterface::class);
  33. $customerAddress = $addressRepository->getById(1);
  34. $customerAddress->setCustomerId(1);
  35. $customerAddress = $addressRepository->save($customerAddress);
  36. $customerRegistry->remove($customerAddress->getCustomerId());
  37. /** @var \Magento\Customer\Model\AddressRegistry $addressRegistry */
  38. $addressRegistry = $objectManager->get(\Magento\Customer\Model\AddressRegistry::class);
  39. $addressRegistry->remove($customerAddress->getId());