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

Commit 5389c23

Browse files
committed
feat(Messages): set MessagesConfiguration at Project
closes #443
1 parent 7ba30dd commit 5389c23

File tree

7 files changed

+131
-9
lines changed

7 files changed

+131
-9
lines changed

src/Core/Builder/Update/ProjectActionBuilder.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Commercetools\Core\Request\Project\Command\ProjectChangeCountriesAction;
88
use Commercetools\Core\Request\Project\Command\ProjectChangeCurrenciesAction;
99
use Commercetools\Core\Request\Project\Command\ProjectChangeLanguagesAction;
10+
use Commercetools\Core\Request\Project\Command\ProjectChangeMessagesConfigurationAction;
1011
use Commercetools\Core\Request\Project\Command\ProjectChangeMessagesEnabledAction;
1112
use Commercetools\Core\Request\Project\Command\ProjectChangeNameAction;
1213
use Commercetools\Core\Request\Project\Command\ProjectSetShippingRateInputTypeAction;
@@ -48,6 +49,17 @@ public function changeLanguages($action = null)
4849
return $this;
4950
}
5051

52+
/**
53+
* @link https://docs.commercetools.com/http-api-projects-project.html#change-messages-enabled
54+
* @param ProjectChangeMessagesConfigurationAction|callable $action
55+
* @return $this
56+
*/
57+
public function changeMessagesConfiguration($action = null)
58+
{
59+
$this->addAction($this->resolveAction(ProjectChangeMessagesConfigurationAction::class, $action));
60+
return $this;
61+
}
62+
5163
/**
5264
* @link https://docs.commercetools.com/http-api-projects-project.html#change-messages-enabled
5365
* @param ProjectChangeMessagesEnabledAction|callable $action

src/Core/Model/Message/MessagesConfiguration.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,14 @@
55

66
namespace Commercetools\Core\Model\Message;
77

8-
use Commercetools\Core\Model\Common\JsonObject;
9-
108
/**
119
* @package Commercetools\Core\Model\Message
1210
*
1311
* @method bool getEnabled()
1412
* @method MessagesConfiguration setEnabled(bool $enabled = null)
13+
* @method int getDeleteDaysAfterCreation()
14+
* @method MessagesConfiguration setDeleteDaysAfterCreation(int $deleteDaysAfterCreation = null)
1515
*/
16-
class MessagesConfiguration extends JsonObject
16+
class MessagesConfiguration extends MessagesConfigurationDraft
1717
{
18-
public function fieldDefinitions()
19-
{
20-
return [
21-
'enabled' => [static::TYPE => 'bool'],
22-
];
23-
}
2418
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
*/
4+
5+
namespace Commercetools\Core\Model\Message;
6+
7+
use Commercetools\Core\Model\Common\JsonObject;
8+
9+
/**
10+
* @package Commercetools\Core\Model\Message
11+
*
12+
* @method bool getEnabled()
13+
* @method MessagesConfigurationDraft setEnabled(bool $enabled = null)
14+
* @method int getDeleteDaysAfterCreation()
15+
* @method MessagesConfigurationDraft setDeleteDaysAfterCreation(int $deleteDaysAfterCreation = null)
16+
*/
17+
class MessagesConfigurationDraft extends JsonObject
18+
{
19+
public function fieldDefinitions()
20+
{
21+
return [
22+
'enabled' => [static::TYPE => 'bool'],
23+
'deleteDaysAfterCreation' => [static::TYPE => 'int'],
24+
];
25+
}
26+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
*/
4+
5+
namespace Commercetools\Core\Request\Project\Command;
6+
7+
use Commercetools\Core\Model\Common\Context;
8+
use Commercetools\Core\Model\Message\MessagesConfigurationDraft;
9+
use Commercetools\Core\Request\AbstractAction;
10+
11+
/**
12+
* @package Commercetools\Core\Request\Project\Command
13+
* @link https://docs.commercetools.com/http-api-projects-project.html#change-messages-enabled
14+
* @method string getAction()
15+
* @method ProjectChangeMessagesConfigurationAction setAction(string $action = null)
16+
* @method bool getMessagesEnabled()
17+
* @method ProjectChangeMessagesConfigurationAction setMessagesEnabled(bool $messagesEnabled = null)
18+
* @method MessagesConfigurationDraft getMessagesConfiguration()
19+
* phpcs:disable
20+
* @method ProjectChangeMessagesConfigurationAction setMessagesConfiguration(MessagesConfigurationDraft $messagesConfiguration = null)
21+
* phpcs:enable
22+
*/
23+
class ProjectChangeMessagesConfigurationAction extends AbstractAction
24+
{
25+
public function fieldDefinitions()
26+
{
27+
return [
28+
'action' => [static::TYPE => 'string'],
29+
'messagesConfiguration' => [static::TYPE => MessagesConfigurationDraft::class],
30+
];
31+
}
32+
33+
/**
34+
* @param array $data
35+
* @param Context|callable $context
36+
*/
37+
public function __construct(array $data = [], $context = null)
38+
{
39+
parent::__construct($data, $context);
40+
$this->setAction('changeMessagesConfiguration');
41+
}
42+
43+
/**
44+
* @param MessagesConfigurationDraft $draft
45+
* @param Context|callable $context
46+
* @return ProjectChangeMessagesConfigurationAction
47+
*/
48+
public static function ofDraft(MessagesConfigurationDraft $draft, $context = null)
49+
{
50+
return static::of($context)->setMessagesConfiguration($draft);
51+
}
52+
}

src/Core/Request/Project/Command/ProjectChangeMessagesEnabledAction.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
/**
1212
* @package Commercetools\Core\Request\Project\Command
1313
* @link https://docs.commercetools.com/http-api-projects-project.html#change-messages-enabled
14+
* @deprecated
1415
* @method string getAction()
1516
* @method ProjectChangeMessagesEnabledAction setAction(string $action = null)
1617
* @method bool getMessagesEnabled()

tests/integration/Project/ProjectUpdateRequestTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
use Commercetools\Core\Model\Common\LocalizedEnum;
1010
use Commercetools\Core\Model\Common\LocalizedEnumCollection;
1111
use Commercetools\Core\Model\Common\LocalizedString;
12+
use Commercetools\Core\Model\Message\MessagesConfigurationDraft;
1213
use Commercetools\Core\Model\Project\CartClassificationType;
1314
use Commercetools\Core\Model\Project\CartScoreType;
1415
use Commercetools\Core\Model\Project\CartValueType;
1516
use Commercetools\Core\Model\Project\Project;
1617
use Commercetools\Core\Request\Project\Command\ProjectChangeCountriesAction;
1718
use Commercetools\Core\Request\Project\Command\ProjectChangeCurrenciesAction;
1819
use Commercetools\Core\Request\Project\Command\ProjectChangeLanguagesAction;
20+
use Commercetools\Core\Request\Project\Command\ProjectChangeMessagesConfigurationAction;
1921
use Commercetools\Core\Request\Project\Command\ProjectChangeMessagesEnabledAction;
2022
use Commercetools\Core\Request\Project\Command\ProjectChangeNameAction;
2123
use Commercetools\Core\Request\Project\Command\ProjectSetShippingRateInputTypeAction;
@@ -149,6 +151,40 @@ public function testChangeMessagesEnabled()
149151
$this->assertFalse($response->isError());
150152
}
151153

154+
public function testChangeMessagesConfiguration()
155+
{
156+
$request = ProjectGetRequest::of();
157+
$response = $request->executeWithClient($this->getClient());
158+
$project = $request->mapResponse($response);
159+
160+
$this->assertInstanceOf(Project::class, $project);
161+
$messagesConfiguration = $project->getMessages();
162+
$messagesEnabled = $messagesConfiguration->getEnabled();
163+
$deleteDaysAfterCreation = (5 === $messagesConfiguration->getDeleteDaysAfterCreation() ? 10 : 5);
164+
165+
$messagesConfigurationDraft = MessagesConfigurationDraft::of()
166+
->setEnabled(!$messagesEnabled)
167+
->setDeleteDaysAfterCreation($deleteDaysAfterCreation);
168+
169+
$request = ProjectUpdateRequest::ofVersion($project->getVersion());
170+
$request->addAction(ProjectChangeMessagesConfigurationAction::ofDraft($messagesConfigurationDraft));
171+
$response = $request->executeWithClient($this->getClient());
172+
$result = $request->mapResponse($response);
173+
174+
$this->assertInstanceOf(Project::class, $result);
175+
$this->assertNotSame($messagesEnabled, $result->getMessages()->getEnabled());
176+
$this->assertSame($deleteDaysAfterCreation, $result->getMessages()->getDeleteDaysAfterCreation());
177+
178+
$request = ProjectUpdateRequest::ofVersion($result->getVersion());
179+
$messagesConfigurationDraft = MessagesConfigurationDraft::of()
180+
->setEnabled($messagesEnabled)
181+
->setDeleteDaysAfterCreation($deleteDaysAfterCreation);
182+
$request->addAction(ProjectChangeMessagesConfigurationAction::ofDraft($messagesConfigurationDraft));
183+
$response = $request->executeWithClient($this->getClient());
184+
185+
$this->assertFalse($response->isError());
186+
}
187+
152188
public function testSetShippingRateInputTypeCartValue()
153189
{
154190
$request = ProjectGetRequest::of();

tests/unit/Model/RamlModelTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,7 @@ private function ramlToModelMap()
600600
'Product\FacetResultRange' => 'Product\FacetRange',
601601
'Product\FacetResultTerm' => 'Product\FacetTerm',
602602
'Message\MessageConfiguration' => 'Message\MessagesConfiguration',
603+
'Message\MessageConfigurationDraft' => 'Message\MessagesConfigurationDraft',
603604
'Message\OrderPaymentStateChangedMessage' => 'Message\OrderPaymentChangedMessage',
604605
'Order\PaymentInfo' => 'Payment\PaymentInfo',
605606
'Cart\ExternalTaxRateDraft' => 'TaxCategory\ExternalTaxRateDraft',

0 commit comments

Comments
 (0)