1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author @jayS-de <[email protected]> |
4
|
|
|
* @created: 11.02.15, 14:23 |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace Commercetools\Core\Model\Customer; |
8
|
|
|
|
9
|
|
|
use Commercetools\Core\Model\Common\Context; |
10
|
|
|
use Commercetools\Core\Model\Common\JsonObject; |
11
|
|
|
use Commercetools\Core\Model\Common\DateTimeDecorator; |
12
|
|
|
use Commercetools\Core\Model\CustomerGroup\CustomerGroupReference; |
13
|
|
|
use Commercetools\Core\Model\Common\AddressCollection; |
14
|
|
|
use Commercetools\Core\Model\CustomField\CustomFieldObjectDraft; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @package Commercetools\Core\Model\Customer |
18
|
|
|
* @link https://dev.commercetools.com/http-api-projects-customers.html#customerdraft |
19
|
|
|
* @method string getCustomerNumber() |
20
|
|
|
* @method string getEmail() |
21
|
|
|
* @method string getTitle() |
22
|
|
|
* @method string getFirstName() |
23
|
|
|
* @method string getMiddleName() |
24
|
|
|
* @method string getLastName() |
25
|
|
|
* @method string getPassword() |
26
|
|
|
* @method string getAnonymousCartId() |
27
|
|
|
* @method string getExternalId() |
28
|
|
|
* @method CustomerDraft setCustomerNumber(string $customerNumber = null) |
29
|
|
|
* @method CustomerDraft setEmail(string $email = null) |
30
|
|
|
* @method CustomerDraft setTitle(string $title = null) |
31
|
|
|
* @method CustomerDraft setFirstName(string $firstName = null) |
32
|
|
|
* @method CustomerDraft setMiddleName(string $middleName = null) |
33
|
|
|
* @method CustomerDraft setLastName(string $lastName = null) |
34
|
|
|
* @method CustomerDraft setPassword(string $password = null) |
35
|
|
|
* @method CustomerDraft setAnonymousCartId(string $anonymousCartId = null) |
36
|
|
|
* @method CustomerDraft setExternalId(string $externalId = null) |
37
|
|
|
* @method DateTimeDecorator getDateOfBirth() |
38
|
|
|
* @method CustomerDraft setDateOfBirth(\DateTime $dateOfBirth = null) |
39
|
|
|
* @method string getCompanyName() |
40
|
|
|
* @method CustomerDraft setCompanyName(string $companyName = null) |
41
|
|
|
* @method string getVatId() |
42
|
|
|
* @method CustomerDraft setVatId(string $vatId = null) |
43
|
|
|
* @method bool getIsEmailVerified() |
44
|
|
|
* @method CustomerDraft setIsEmailVerified(bool $isEmailVerified = null) |
45
|
|
|
* @method CustomerGroupReference getCustomerGroup() |
46
|
|
|
* @method CustomerDraft setCustomerGroup(CustomerGroupReference $customerGroup = null) |
47
|
|
|
* @method AddressCollection getAddresses() |
48
|
|
|
* @method CustomerDraft setAddresses(AddressCollection $addresses = null) |
49
|
|
|
* @method int getDefaultShippingAddress() |
50
|
|
|
* @method CustomerDraft setDefaultShippingAddress(int $defaultShippingAddress = null) |
51
|
|
|
* @method int getDefaultBillingAddress() |
52
|
|
|
* @method CustomerDraft setDefaultBillingAddress(int $defaultBillingAddress = null) |
53
|
|
|
* @method CustomFieldObjectDraft getCustom() |
54
|
|
|
* @method CustomerDraft setCustom(CustomFieldObjectDraft $custom = null) |
55
|
|
|
* @method string getLocale() |
56
|
|
|
*/ |
57
|
|
|
class CustomerDraft extends JsonObject |
58
|
79 |
|
{ |
59
|
|
|
public function fieldDefinitions() |
60
|
|
|
{ |
61
|
79 |
|
return [ |
62
|
79 |
|
'customerNumber' => [static::TYPE => 'string'], |
63
|
79 |
|
'email' => [static::TYPE => 'string'], |
64
|
79 |
|
'title' => [static::TYPE => 'string'], |
65
|
79 |
|
'firstName' => [static::TYPE => 'string'], |
66
|
79 |
|
'middleName' => [static::TYPE => 'string'], |
67
|
79 |
|
'lastName' => [static::TYPE => 'string'], |
68
|
79 |
|
'password' => [static::TYPE => 'string'], |
69
|
79 |
|
'anonymousCartId' => [static::TYPE => 'string'], |
70
|
|
|
'externalId' => [static::TYPE => 'string'], |
71
|
79 |
|
'dateOfBirth' => [ |
72
|
79 |
|
static::TYPE => '\DateTime', |
73
|
|
|
static::DECORATOR => '\Commercetools\Core\Model\Common\DateTimeDecorator' |
74
|
79 |
|
], |
75
|
79 |
|
'companyName' => [static::TYPE => 'string'], |
76
|
79 |
|
'vatId' => [static::TYPE => 'string'], |
77
|
79 |
|
'isEmailVerified' => [static::TYPE => 'bool'], |
78
|
79 |
|
'customerGroup' => [static::TYPE => '\Commercetools\Core\Model\CustomerGroup\CustomerGroupReference'], |
79
|
79 |
|
'addresses' => [static::TYPE => '\Commercetools\Core\Model\Common\AddressCollection'], |
80
|
79 |
|
'defaultShippingAddress' => [static::TYPE => 'int'], |
81
|
79 |
|
'defaultBillingAddress' => [static::TYPE => 'int'], |
82
|
|
|
'custom' => [static::TYPE => '\Commercetools\Core\Model\CustomField\CustomFieldObjectDraft'], |
83
|
|
|
'locale' => [static::TYPE => 'string'], |
84
|
|
|
]; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param string $email |
89
|
|
|
* @param string $firstName |
90
|
|
|
* @param string $lastName |
91
|
|
|
* @param string $password |
92
|
|
|
* @param Context|callable $context |
93
|
79 |
|
* @return CustomerDraft |
94
|
|
|
*/ |
95
|
79 |
View Code Duplication |
public static function ofEmailNameAndPassword($email, $firstName, $lastName, $password, $context = null) |
|
|
|
|
96
|
79 |
|
{ |
97
|
79 |
|
$draft = static::of($context); |
98
|
79 |
|
return $draft->setEmail($email) |
99
|
79 |
|
->setFirstName($firstName) |
100
|
|
|
->setLastName($lastName) |
101
|
|
|
->setPassword($password); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function setLocale($locale) |
105
|
|
|
{ |
106
|
|
|
$locale = \Locale::canonicalize($locale); |
107
|
|
|
parent::setLocale($locale); |
|
|
|
|
108
|
|
|
|
109
|
|
|
return $this; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @return array |
114
|
|
|
*/ |
115
|
|
|
public function toJson() |
116
|
|
|
{ |
117
|
|
|
$data = parent::toArray(); |
|
|
|
|
118
|
|
|
$data['locale'] = str_replace('_', '-', $data['locale']); |
119
|
|
|
|
120
|
|
|
return $data; |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.