Skip to content
This repository was archived by the owner on Oct 24, 2023. It is now read-only.

Commit c1c65fd

Browse files
author
Jens Schulze
committed
feat(Customer): add salutation to customer
Closes #324
1 parent af666f6 commit c1c65fd

File tree

5 files changed

+64
-1
lines changed

5 files changed

+64
-1
lines changed

src/Core/Model/Customer/Customer.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,14 @@
6565
* @method Customer setShippingAddressIds(array $shippingAddressIds = null)
6666
* @method array getBillingAddressIds()
6767
* @method Customer setBillingAddressIds(array $billingAddressIds = null)
68+
* @method string getSalutation()
69+
* @method Customer setSalutation(string $salutation = null)
6870
* @method CustomerReference getReference()
6971
*/
7072
class Customer extends Resource
7173
{
7274
use LocaleTrait;
73-
75+
7476
public function fieldDefinitions()
7577
{
7678
return [
@@ -107,6 +109,7 @@ public function fieldDefinitions()
107109
'locale' => [static::TYPE => 'string'],
108110
'shippingAddressIds' => [static::TYPE => 'array'],
109111
'billingAddressIds' => [static::TYPE => 'array'],
112+
'salutation' => [static::TYPE => 'string'],
110113
];
111114
}
112115

src/Core/Model/Customer/CustomerDraft.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
* @method CustomerDraft setBillingAddresses(array $billingAddresses = null)
6161
* @method array getShippingAddresses()
6262
* @method CustomerDraft setShippingAddresses(array $shippingAddresses = null)
63+
* @method string getSalutation()
64+
* @method CustomerDraft setSalutation(string $salutation = null)
6365
*/
6466
class CustomerDraft extends JsonObject
6567
{
@@ -92,6 +94,7 @@ public function fieldDefinitions()
9294
'locale' => [static::TYPE => 'string'],
9395
'billingAddresses' => [static::TYPE => 'array'],
9496
'shippingAddresses' => [static::TYPE => 'array'],
97+
'salutation' => [static::TYPE => 'string'],
9598
];
9699
}
97100

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* @author @jayS-de <[email protected]>
4+
*/
5+
6+
namespace Commercetools\Core\Request\Customers\Command;
7+
8+
use Commercetools\Core\Model\Common\Context;
9+
use Commercetools\Core\Request\AbstractAction;
10+
11+
/**
12+
* @package Commercetools\Core\Request\Customers\Command
13+
* @link https://dev.commercetools.com/http-api-projects-customers.html#set-salutation
14+
* @method string getSalutation()
15+
* @method CustomerSetSalutationAction setSalutation(string $salutation = null)
16+
* @method string getAction()
17+
* @method CustomerSetSalutationAction setAction(string $action = null)
18+
*/
19+
class CustomerSetSalutationAction extends AbstractAction
20+
{
21+
public function fieldDefinitions()
22+
{
23+
return [
24+
'action' => [static::TYPE => 'string'],
25+
'salutation' => [static::TYPE => 'string'],
26+
];
27+
}
28+
29+
/**
30+
* @param array $data
31+
* @param Context|callable $context
32+
*/
33+
public function __construct(array $data = [], $context = null)
34+
{
35+
parent::__construct($data, $context);
36+
$this->setAction('setSalutation');
37+
}
38+
}

tests/fixtures/models.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ customer:
305305
- locale
306306
- shippingAddressIds
307307
- billingAddressIds
308+
- salutation
308309
customerSigninResult:
309310
domain: customer
310311
model: CustomerSigninResult

tests/integration/Customer/CustomerUpdateRequestTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use Commercetools\Core\Request\Customers\Command\CustomerSetLastNameAction;
3232
use Commercetools\Core\Request\Customers\Command\CustomerSetLocaleAction;
3333
use Commercetools\Core\Request\Customers\Command\CustomerSetMiddleNameAction;
34+
use Commercetools\Core\Request\Customers\Command\CustomerSetSalutationAction;
3435
use Commercetools\Core\Request\Customers\Command\CustomerSetTitleAction;
3536
use Commercetools\Core\Request\Customers\Command\CustomerSetVatIdAction;
3637
use Commercetools\Core\Request\Customers\CustomerCreateRequest;
@@ -86,6 +87,23 @@ public function testCustomerEmail()
8687
$this->assertSame($email, $customer->getEmail());
8788
}
8889

90+
public function testSalutation()
91+
{
92+
$draft = $this->getDraft('salutation');
93+
$customer = $this->createCustomer($draft);
94+
95+
$salutation = 'new-salutation';
96+
97+
$request = CustomerUpdateRequest::ofIdAndVersion($customer->getId(), $customer->getVersion())
98+
->addAction(CustomerSetSalutationAction::of()->setSalutation($salutation))
99+
;
100+
$response = $request->executeWithClient($this->getClient());
101+
$customer = $request->mapResponse($response);
102+
$this->deleteRequest->setVersion($customer->getVersion());
103+
104+
$this->assertSame($salutation, $customer->getSalutation());
105+
}
106+
89107
public function testNoopCustomerEmail()
90108
{
91109
$draft = $this->getDraft('email');

0 commit comments

Comments
 (0)