Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields
Customer Class Reference
Inheritance diagram for Customer:
WebapiAbstract

Public Member Functions

 __construct ($name=null, array $data=[], $dataName='')
 
 createSampleCustomer (array $additional=[])
 
 updateSampleCustomer ($customerId, array $additional=[])
 
 createSampleCustomerDataObject (array $additional=[])
 
- Public Member Functions inherited from WebapiAbstract
 addModelToDelete ($model, $secure=false)
 
 processRestExceptionResult (\Exception $e)
 

Data Fields

const RESOURCE_PATH = '/V1/customers'
 
const SERVICE_NAME = 'customerAccountManagementV1'
 
const CUSTOMER_REPOSITORY_SERVICE_NAME = "customerCustomerRepositoryV1"
 
const SERVICE_VERSION = 'V1'
 
const CONFIRMATION = 'a4fg7h893e39d'
 
const CREATED_AT = '2013-11-05'
 
const CREATED_IN = 'default'
 
const STORE_NAME = 'Store Name'
 
const DOB = '1970-01-01'
 
const GENDER = 'Male'
 
const GROUP_ID = 1
 
const MIDDLENAME = 'A'
 
const PREFIX = 'Mr.'
 
const STORE_ID = 1
 
const SUFFIX = 'Esq.'
 
const TAXVAT = '12'
 
const WEBSITE_ID = 1
 
const FIRSTNAME = 'Jane'
 
const LASTNAME = 'Doe'
 
const PASSWORD = 'test@123'
 
const ADDRESS_CITY1 = 'CityM'
 
const ADDRESS_CITY2 = 'CityX'
 
const ADDRESS_REGION_CODE1 = 'AL'
 
const ADDRESS_REGION_CODE2 = 'AL'
 
- Data Fields inherited from WebapiAbstract
const AUTO_TEAR_DOWN_DISABLED = 0
 
const AUTO_TEAR_DOWN_AFTER_METHOD = 1
 
const AUTO_TEAR_DOWN_AFTER_CLASS = 2
 
const ADAPTER_SOAP = 'soap'
 
const ADAPTER_REST = 'rest'
 

Additional Inherited Members

- Static Public Member Functions inherited from WebapiAbstract
static setUpBeforeClass ()
 
static tearDownAfterClass ()
 
static setFixture ($key, $fixture, $tearDown=self::AUTO_TEAR_DOWN_AFTER_METHOD)
 
static getFixture ($key)
 
static callModelDelete ($model, $secure=false)
 
static deleteFixture ($key, $secure=false)
 
- Protected Member Functions inherited from WebapiAbstract
 tearDown ()
 
 _webApiCall ( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
 
 _markTestAsSoapOnly ($message=null)
 
 _markTestAsRestOnly ($message=null)
 
 _getWebApiAdapter ($webApiAdapterCode)
 
 _assertMessagesEqual ($expectedMessages, $receivedMessages)
 
 _cleanAppConfigCache ()
 
 _restoreAppConfig ()
 
 checkSoapFault ( $soapFault, $expectedMessage, $expectedFaultCode, $expectedErrorParams=[], $expectedWrappedErrors=[], $traceString=null)
 
 _checkFaultParams ($expectedErrorParams, $errorDetails)
 
 _checkWrappedErrors ($expectedWrappedErrors, $errorDetails)
 
- Static Protected Member Functions inherited from WebapiAbstract
static _setFixtureNamespace ()
 
static _unsetFixtureNamespace ()
 
static _getFixtureNamespace ()
 
static _deleteFixtures ($fixtures)
 
- Protected Attributes inherited from WebapiAbstract
 $_appCache
 
 $_modelsToDelete = []
 
 $_origConfigValues = []
 
 $_webApiAdapters
 
 $_webApiAdaptersMap
 
- Static Protected Attributes inherited from WebapiAbstract
static $_fixturesNamespace
 
static $_fixtures = []
 
static $_methodLevelFixtures = []
 
static $_classLevelFixtures = []
 

Detailed Description

Definition at line 14 of file Customer.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $name = null,
array  $data = [],
  $dataName = '' 
)

Definition at line 63 of file Customer.php.

64  {
65  parent::__construct($name, $data, $dataName);
66 
67  $this->customerAddressFactory = Bootstrap::getObjectManager()->create(
68  \Magento\Customer\Api\Data\AddressInterfaceFactory::class
69  );
70 
71  $this->customerDataFactory = Bootstrap::getObjectManager()->create(
72  \Magento\Customer\Api\Data\CustomerInterfaceFactory::class
73  );
74 
75  $this->dataObjectHelper = Bootstrap::getObjectManager()->create(
76  \Magento\Framework\Api\DataObjectHelper::class
77  );
78 
79  $this->dataObjectProcessor = Bootstrap::getObjectManager()->create(
80  \Magento\Framework\Reflection\DataObjectProcessor::class
81  );
82  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

Member Function Documentation

◆ createSampleCustomer()

createSampleCustomer ( array  $additional = [])
Parameters
array$additional
Returns
array|bool|float|int|string

Definition at line 88 of file Customer.php.

89  {
90  $serviceInfo = [
91  'rest' => [
92  'resourcePath' => self::RESOURCE_PATH,
93  'httpMethod' => RestRequest::HTTP_METHOD_POST,
94  ],
95  'soap' => [
96  'service' => self::SERVICE_NAME,
97  'serviceVersion' => self::SERVICE_VERSION,
98  'operation' => self::SERVICE_NAME . 'CreateAccount',
99  ],
100  ];
101 
102  $customerDataArray = $this->dataObjectProcessor->buildOutputDataArray(
103  $this->createSampleCustomerDataObject($additional),
104  \Magento\Customer\Api\Data\CustomerInterface::class
105  );
106  $requestData = ['customer' => $customerDataArray, 'password' => self::PASSWORD];
107  $customerData = $this->_webApiCall($serviceInfo, $requestData);
108  return $customerData;
109  }
$customerData
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
createSampleCustomerDataObject(array $additional=[])
Definition: Customer.php:180

◆ createSampleCustomerDataObject()

createSampleCustomerDataObject ( array  $additional = [])

Create customer using setters.

Parameters
array$additional
Returns
CustomerInterface

Definition at line 180 of file Customer.php.

181  {
182  $customerAddress1 = $this->customerAddressFactory->create();
183  $customerAddress1->setCountryId('US');
184  $customerAddress1->setIsDefaultBilling(true);
185  $customerAddress1->setIsDefaultShipping(true);
186  $customerAddress1->setPostcode('75477');
187  $customerAddress1->setRegion(
188  Bootstrap::getObjectManager()->create(\Magento\Customer\Api\Data\RegionInterfaceFactory::class)
189  ->create()
190  ->setRegionCode(self::ADDRESS_REGION_CODE1)
191  ->setRegion('Alabama')
192  ->setRegionId(1)
193  );
194  $customerAddress1->setStreet(['Green str, 67']);
195  $customerAddress1->setTelephone('3468676');
196  $customerAddress1->setCity(self::ADDRESS_CITY1);
197  $customerAddress1->setFirstname('John');
198  $customerAddress1->setLastname('Smith');
199  $address1 = $this->dataObjectProcessor->buildOutputDataArray(
200  $customerAddress1,
201  \Magento\Customer\Api\Data\AddressInterface::class
202  );
203 
204  $customerAddress2 = $this->customerAddressFactory->create();
205  $customerAddress2->setCountryId('US');
206  $customerAddress2->setIsDefaultBilling(false);
207  $customerAddress2->setIsDefaultShipping(false);
208  $customerAddress2->setPostcode('47676');
209  $customerAddress2->setRegion(
210  Bootstrap::getObjectManager()->create(\Magento\Customer\Api\Data\RegionInterfaceFactory::class)
211  ->create()
212  ->setRegionCode(self::ADDRESS_REGION_CODE2)
213  ->setRegion('Alabama')
214  ->setRegionId(1)
215  );
216  $customerAddress2->setStreet(['Black str, 48', 'Building D']);
217  $customerAddress2->setTelephone('3234676');
218  $customerAddress2->setCity(self::ADDRESS_CITY2);
219  $customerAddress2->setFirstname('John');
220  $customerAddress2->setLastname('Smith');
221  $address2 = $this->dataObjectProcessor->buildOutputDataArray(
222  $customerAddress2,
223  \Magento\Customer\Api\Data\AddressInterface::class
224  );
225 
226  $customerData = $this->getCustomerSampleData(
227  array_merge([CustomerData::KEY_ADDRESSES => [$address1, $address2]], $additional)
228  );
229  $customer = $this->customerDataFactory->create();
230  $this->dataObjectHelper->populateWithArray(
231  $customer,
233  \Magento\Customer\Api\Data\CustomerInterface::class
234  );
235  return $customer;
236  }
$customerData
$customer
Definition: customers.php:11

◆ updateSampleCustomer()

updateSampleCustomer (   $customerId,
array  $additional = [] 
)

Update Existing customer

Parameters
array$additional
int$customerId
Returns
array|bool|float|int|string

Definition at line 118 of file Customer.php.

119  {
120  $serviceInfo = [
121  'rest' => [
122  'resourcePath' => self::RESOURCE_PATH . "/" . $customerId,
123  'httpMethod' => RestRequest::HTTP_METHOD_PUT,
124  ],
125  'soap' => [
127  'serviceVersion' => self::SERVICE_VERSION,
128  'operation' => self::CUSTOMER_REPOSITORY_SERVICE_NAME . 'save',
129  ],
130  ];
131 
132  $customerDataArray = $this->dataObjectProcessor->buildOutputDataArray(
133  $this->createSampleCustomerDataObject($additional),
134  \Magento\Customer\Api\Data\CustomerInterface::class
135  );
136  $requestData = ['customer' => $customerDataArray, 'password' => self::PASSWORD];
137  $customerData = $this->_webApiCall($serviceInfo, $requestData);
138  return $customerData;
139  }
$customerData
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
createSampleCustomerDataObject(array $additional=[])
Definition: Customer.php:180

Field Documentation

◆ ADDRESS_CITY1

const ADDRESS_CITY1 = 'CityM'

Definition at line 40 of file Customer.php.

◆ ADDRESS_CITY2

const ADDRESS_CITY2 = 'CityX'

Definition at line 41 of file Customer.php.

◆ ADDRESS_REGION_CODE1

const ADDRESS_REGION_CODE1 = 'AL'

Definition at line 42 of file Customer.php.

◆ ADDRESS_REGION_CODE2

const ADDRESS_REGION_CODE2 = 'AL'

Definition at line 43 of file Customer.php.

◆ CONFIRMATION

const CONFIRMATION = 'a4fg7h893e39d'

Definition at line 21 of file Customer.php.

◆ CREATED_AT

const CREATED_AT = '2013-11-05'

Definition at line 22 of file Customer.php.

◆ CREATED_IN

const CREATED_IN = 'default'

Definition at line 23 of file Customer.php.

◆ CUSTOMER_REPOSITORY_SERVICE_NAME

const CUSTOMER_REPOSITORY_SERVICE_NAME = "customerCustomerRepositoryV1"

Definition at line 18 of file Customer.php.

◆ DOB

const DOB = '1970-01-01'

Definition at line 25 of file Customer.php.

◆ FIRSTNAME

const FIRSTNAME = 'Jane'

Sample values for testing

Definition at line 36 of file Customer.php.

◆ GENDER

const GENDER = 'Male'

Definition at line 26 of file Customer.php.

◆ GROUP_ID

const GROUP_ID = 1

Definition at line 27 of file Customer.php.

◆ LASTNAME

const LASTNAME = 'Doe'

Definition at line 37 of file Customer.php.

◆ MIDDLENAME

const MIDDLENAME = 'A'

Definition at line 28 of file Customer.php.

◆ PASSWORD

const PASSWORD = 'test@123'

Definition at line 38 of file Customer.php.

◆ PREFIX

const PREFIX = 'Mr.'

Definition at line 29 of file Customer.php.

◆ RESOURCE_PATH

const RESOURCE_PATH = '/V1/customers'

Definition at line 16 of file Customer.php.

◆ SERVICE_NAME

const SERVICE_NAME = 'customerAccountManagementV1'

Definition at line 17 of file Customer.php.

◆ SERVICE_VERSION

const SERVICE_VERSION = 'V1'

Definition at line 19 of file Customer.php.

◆ STORE_ID

const STORE_ID = 1

Definition at line 30 of file Customer.php.

◆ STORE_NAME

const STORE_NAME = 'Store Name'

Definition at line 24 of file Customer.php.

◆ SUFFIX

const SUFFIX = 'Esq.'

Definition at line 31 of file Customer.php.

◆ TAXVAT

const TAXVAT = '12'

Definition at line 32 of file Customer.php.

◆ WEBSITE_ID

const WEBSITE_ID = 1

Definition at line 33 of file Customer.php.


The documentation for this class was generated from the following file: