Skip to content

Commit 2760b1c

Browse files
committed
MAGETWO-59130: [Github] REST API with searchCriteria does not return category_ids #6127
1 parent f491ac8 commit 2760b1c

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

app/code/Magento/Catalog/Model/ProductRepository.php

+1
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,7 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCr
640640

641641
$collection->load();
642642

643+
$collection->addCategoryIds();
643644
$searchResult = $this->searchResultsFactory->create();
644645
$searchResult->setSearchCriteria($searchCriteria);
645646
$searchResult->setItems($collection->getItems());

app/code/Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,7 @@ public function testGetList()
715715
->method('process')
716716
->with($searchCriteriaMock, $collectionMock);
717717
$collectionMock->expects($this->once())->method('load');
718+
$collectionMock->expects($this->once())->method('addCategoryIds');
718719
$collectionMock->expects($this->once())->method('getItems')->willReturn([$itemsMock]);
719720
$collectionMock->expects($this->once())->method('getSize')->willReturn(128);
720721
$searchResultsMock = $this->getMock(

dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php

+10
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,16 @@ public function testGetList()
713713

714714
$this->assertNotNull($response['items'][0]['sku']);
715715
$this->assertEquals('simple', $response['items'][0]['sku']);
716+
$isCategoryInformationExist = false;
717+
$index = null;
718+
foreach($response['items'][0]['custom_attributes'] as $key => $customAttribute) {
719+
if ($customAttribute['attribute_code'] == 'category_ids') {
720+
$isCategoryInformationExist = true;
721+
$index = $key;
722+
}
723+
}
724+
$this->assertTrue($isCategoryInformationExist, 'Category information wasn\'t set');
725+
$this->assertEquals([2], $response['items'][0]['custom_attributes'][$index]['value']);
716726
}
717727

718728
/**

0 commit comments

Comments
 (0)