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

Commit 79b23de

Browse files
author
Barbara Palumbo
committed
WIP: productselectiontype and messages are been adapted in base of the docs
1 parent f8649d4 commit 79b23de

File tree

8 files changed

+51
-34
lines changed

8 files changed

+51
-34
lines changed

src/Core/Model/Message/ProductSelectionCreatedMessage.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Commercetools\Core\Model\Common\DateTimeDecorator;
66
use Commercetools\Core\Model\Common\Reference;
7-
use Commercetools\Core\Model\ProductSelection\ProductSelectionType;
7+
use Commercetools\Core\Model\ProductSelection\IndividualProductSelectionType;
88
use DateTime;
99

1010
/**
@@ -30,8 +30,8 @@
3030
* phpcs:disable
3131
* @method ProductSelectionCreatedMessage setResourceUserProvidedIdentifiers(UserProvidedIdentifiers $resourceUserProvidedIdentifiers = null)
3232
* phpcs:enable
33-
* @method ProductSelectionType getProductSelection()
34-
* @method ProductSelectionCreatedMessage setProductSelection(ProductSelectionType $productSelection = null)
33+
* @method IndividualProductSelectionType getProductSelection()
34+
* @method ProductSelectionCreatedMessage setProductSelection(IndividualProductSelectionType $productSelection = null)
3535
*/
3636
class ProductSelectionCreatedMessage extends Message
3737
{
@@ -40,7 +40,7 @@ class ProductSelectionCreatedMessage extends Message
4040
public function fieldDefinitions()
4141
{
4242
$definitions = parent::fieldDefinitions();
43-
$definitions['productSelection'] = [static::TYPE => ProductSelectionType::class];
43+
$definitions['productSelection'] = [static::TYPE => IndividualProductSelectionType::class];
4444

4545
return $definitions;
4646
}

src/Core/Model/ProductSelection/IndividualProductSelectionType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* @method LocalizedString getName()
1111
* @method IndividualProductSelectionType setName(LocalizedString $name = null)
1212
*/
13-
class IndividualProductSelectionType extends ProductSelectionTypeEnum
13+
class IndividualProductSelectionType extends ProductSelectionType
1414
{
1515
public function fieldDefinitions()
1616
{

src/Core/Model/ProductSelection/ProductSelection.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
* @method ProductSelection setName(LocalizedString $name = null)
3131
* @method int getProductCount()
3232
* @method ProductSelection setProductCount(int $productCount = null)
33-
* @method ProductSelectionTypeEnum getType()
34-
* @method ProductSelection setType(ProductSelectionTypeEnum $type = null)
33+
* @method ProductSelectionType getType()
34+
* @method ProductSelection setType(ProductSelectionType $type = null)
3535
* @method ProductSelectionReference getReference()
3636
*/
3737
class ProductSelection extends Resource
@@ -54,7 +54,7 @@ public function fieldDefinitions()
5454
'createdBy' => [static::TYPE => CreatedBy::class],
5555
'name' => [static::TYPE => LocalizedString::class],
5656
'productCount' => [static::TYPE => 'int'],
57-
'type' => [static::TYPE => ProductSelectionTypeEnum::class]
57+
'type' => [static::TYPE => ProductSelectionType::class]
5858
];
5959
}
6060
}

src/Core/Model/ProductSelection/ProductSelectionType.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,21 @@
77
/**
88
* @package Commercetools\Core\Model\ProductSelection
99
*
10-
* @method ProductSelectionTypeEnum getType()
11-
* @method ProductSelectionType setType(ProductSelectionTypeEnum $type = null)
10+
* @method string getLabel()
11+
* @method ProductSelectionType setLabel(string $label = null)
12+
* @method string getKey()
13+
* @method ProductSelectionType setKey(string $key = null)
14+
* @method ProductSelectionType getType()
15+
* @method ProductSelectionType setType(ProductSelectionType $type = null)
1216
*/
1317
class ProductSelectionType extends JsonObject
1418
{
15-
const INPUT_TYPE = '';
19+
const INDIVIDUAL = 'individual';
1620

1721
public function fieldDefinitions()
1822
{
1923
return [
20-
'type' => [static::TYPE => ProductSelectionTypeEnum::class],
24+
'type' => [static::TYPE => ProductSelectionType::class],
2125
];
2226
}
2327
}

src/Core/Model/ProductSelection/ProductSelectionTypeEnum.php

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/Core/Request/ProductSelections/ProductSelectionAssignmentsQueryRequest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
use Commercetools\Core\Model\Common\Context;
66
use Commercetools\Core\Model\ProductSelection\ProductSelectionAssignment;
77
use Commercetools\Core\Request\AbstractQueryRequest;
8-
use Commercetools\Core\Model\ProductSelection\ProductSelectionCollection;
98
use Commercetools\Core\Response\ApiResponseInterface;
109
use Commercetools\Core\Model\MapperInterface;
1110

1211
/**
1312
* @package Commercetools\Core\Request\ProductSelections
1413
* @link https://docs.commercetools.com/api/projects/product-selections#query-products-available-in-a-store-through-active-product-selections
15-
* @method ProductSelectionCollection mapResponse(ApiResponseInterface $response)
16-
* @method ProductSelectionCollection mapFromResponse(ApiResponseInterface $response, MapperInterface $mapper = null)
14+
* @method ProductSelectionAssignment mapResponse(ApiResponseInterface $response)
15+
* @method ProductSelectionAssignment mapFromResponse(ApiResponseInterface $response, MapperInterface $mapper = null)
1716
*/
1817
class ProductSelectionAssignmentsQueryRequest extends AbstractQueryRequest
1918
{

tests/integration/ProductSelection/ProductSelectionUpdateRequestTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
use Commercetools\Core\IntegrationTests\ApiTestCase;
77
use Commercetools\Core\IntegrationTests\Product\ProductFixture;
88
use Commercetools\Core\Model\Common\LocalizedString;
9+
use Commercetools\Core\Model\Message\ProductSelectionCreatedMessage;
910
use Commercetools\Core\Model\Product\Product;
1011
use Commercetools\Core\Model\Product\ProductReference;
1112
use Commercetools\Core\Model\ProductSelection\AssignedProductReference;
1213
use Commercetools\Core\Model\ProductSelection\ProductSelection;
14+
use Commercetools\Core\Request\Messages\MessageQueryRequest;
1315
use Commercetools\Core\Request\ProductSelections\Command\ProductSelectionAddProductAction;
1416
use Commercetools\Core\Request\ProductSelections\Command\ProductSelectionChangeNameAction;
1517
use Commercetools\Core\Request\ProductSelections\Command\ProductSelectionRemoveProductAction;
@@ -18,6 +20,36 @@
1820

1921
class ProductSelectionUpdateRequestTest extends ApiTestCase
2022
{
23+
public function testCreateProductSelection()
24+
{
25+
$client = $this->getApiClient();
26+
27+
ProductSelectionFixture::withProductSelection(
28+
$client,
29+
function (ProductSelection $productSelection) use ($client) {
30+
$this->assertNotEmpty($productSelection);
31+
$retries = 0;
32+
do {
33+
$retries++;
34+
sleep(1);
35+
$request = MessageQueryRequest::of()
36+
->where('type = "ProductSelectionCreated"')
37+
->where('resource(id = "' . $productSelection->getId() . '")');
38+
$response = $this->execute($client, $request);
39+
$result = $request->mapFromResponse($response);
40+
} while (is_null($result) && $retries <= 9);
41+
42+
/**
43+
* @var ProductSelectionCreatedMessage $message
44+
*/
45+
$message = $result->current();
46+
47+
$this->assertInstanceOf(ProductSelectionCreatedMessage::class, $message);
48+
$this->assertSame($productSelection->getId(), $message->getResource()->getId());
49+
}
50+
);
51+
}
52+
2153
public function testChangeName()
2254
{
2355
$client = $this->getApiClient();

tests/integration/Store/StoreUpdateRequestTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Commercetools\Core\Model\ProductSelection\ProductSelection;
1515
use Commercetools\Core\Model\ProductSelection\ProductSelectionDraft;
1616
use Commercetools\Core\Model\ProductSelection\ProductSelectionReference;
17-
use Commercetools\Core\Model\ProductSelection\ProductSelectionTypeEnum;
17+
use Commercetools\Core\Model\ProductSelection\ProductSelectionType;
1818
use Commercetools\Core\Model\Store\ProductSelectionSettingDraft;
1919
use Commercetools\Core\Model\Store\Store;
2020
use Commercetools\Core\Model\Store\StoreDraft;

0 commit comments

Comments
 (0)