Skip to content

Commit 624f453

Browse files
committed
Merge remote-tracking branch 'l3/MC-39024' into BUGFIX-11-23
2 parents 3f209e7 + 20ce089 commit 624f453

File tree

4 files changed

+124
-2
lines changed

4 files changed

+124
-2
lines changed

app/code/Magento/Catalog/etc/mview.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,15 @@
4949
<table name="catalog_product_entity_decimal" entity_column="entity_id" />
5050
<table name="catalog_product_entity_int" entity_column="entity_id" />
5151
<table name="catalog_product_entity_tier_price" entity_column="entity_id" />
52+
<table name="catalog_product_link" entity_column="product_id" />
5253
</subscriptions>
5354
</view>
5455
<view id="catalog_product_attribute" class="Magento\Catalog\Model\Indexer\Product\Eav" group="indexer">
5556
<subscriptions>
5657
<table name="catalog_product_entity_decimal" entity_column="entity_id" />
5758
<table name="catalog_product_entity_int" entity_column="entity_id" />
5859
<table name="catalog_product_entity_varchar" entity_column="entity_id" />
60+
<table name="catalog_product_link" entity_column="product_id" />
5961
</subscriptions>
6062
</view>
6163
</config>

app/code/Magento/CatalogInventory/etc/mview.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<table name="cataloginventory_stock_item" entity_column="product_id" />
1212
<!--Track product status to trigger stock indexer-->
1313
<table name="catalog_product_entity_int" entity_column="entity_id" />
14+
<table name="catalog_product_link" entity_column="product_id" />
1415
</subscriptions>
1516
</view>
1617
<view id="catalog_product_price" class="Magento\Catalog\Model\Indexer\Product\Price" group="indexer">

app/code/Magento/CatalogRule/etc/mview.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<table name="catalog_product_entity_tier_price" entity_column="entity_id" />
2222
<table name="catalog_product_entity_varchar" entity_column="entity_id" />
2323
<table name="catalog_category_product" entity_column="product_id" />
24+
<table name="catalog_product_link" entity_column="product_id" />
2425
</subscriptions>
2526
</view>
2627
<view id="catalog_product_price" class="Magento\Catalog\Model\Indexer\Product\Price" group="indexer">

dev/tests/api-functional/testsuite/Magento/GroupedProduct/Api/ProductLinkRepositoryTest.php

Lines changed: 120 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,44 @@
77
namespace Magento\GroupedProduct\Api;
88

99
use Magento\TestFramework\Helper\Bootstrap;
10+
use Magento\Indexer\Model\Config;
11+
use Magento\Framework\Indexer\IndexerRegistry;
12+
use Magento\Framework\Webapi\Rest\Request;
1013

1114
class ProductLinkRepositoryTest extends \Magento\TestFramework\TestCase\WebapiAbstract
1215
{
1316
const SERVICE_NAME = 'catalogProductLinkRepositoryV1';
1417
const SERVICE_VERSION = 'V1';
1518
const RESOURCE_PATH = '/V1/products/';
19+
const SERVICE_NAME_SEARCH = 'searchV1';
20+
const RESOURCE_PATH_SEARCH = '/V1/search/';
1621

1722
/**
1823
* @var \Magento\Framework\ObjectManagerInterface
1924
*/
2025
protected $objectManager;
2126

27+
/**
28+
* @var array
29+
*/
30+
private $indexersState;
31+
32+
/**
33+
* @var mixed
34+
*/
35+
private $indexerRegistry;
36+
2237
protected function setUp(): void
2338
{
2439
$this->objectManager = Bootstrap::getObjectManager();
40+
$this->indexerRegistry = $this->objectManager->get(IndexerRegistry::class);
2541
}
2642

2743
/**
2844
* @magentoApiDataFixture Magento/Catalog/_files/product_simple_duplicated.php
2945
* @magentoApiDataFixture Magento/GroupedProduct/_files/product_grouped.php
3046
*/
31-
public function testSave()
47+
public function testSave(): void
3248
{
3349
$productSku = 'grouped-product';
3450
$linkType = 'associated';
@@ -46,7 +62,7 @@ public function testSave()
4662
$serviceInfo = [
4763
'rest' => [
4864
'resourcePath' => self::RESOURCE_PATH . $productSku . '/links',
49-
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT,
65+
'httpMethod' => Request::HTTP_METHOD_PUT,
5066
],
5167
'soap' => [
5268
'service' => self::SERVICE_NAME,
@@ -64,4 +80,106 @@ public function testSave()
6480
});
6581
$this->assertEquals($productData, $actual[2]);
6682
}
83+
84+
/**
85+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple_duplicated.php
86+
* @magentoApiDataFixture Magento/GroupedProduct/_files/product_grouped.php
87+
*/
88+
public function testLinkWithScheduledIndex(): void
89+
{
90+
$this->setIndexScheduled();
91+
$productSkuGrouped = 'grouped-product';
92+
$productSimple = 'simple-1';
93+
$linkType = 'associated';
94+
$productData = [
95+
'sku' => $productSkuGrouped,
96+
'link_type' => $linkType,
97+
'linked_product_type' => 'simple',
98+
'linked_product_sku' => $productSimple,
99+
'position' => 3,
100+
'extension_attributes' => [
101+
'qty' => (float) 300.0000,
102+
],
103+
];
104+
$serviceInfo = [
105+
'rest' => [
106+
'resourcePath' => self::RESOURCE_PATH . $productSkuGrouped . '/links',
107+
'httpMethod' => Request::HTTP_METHOD_PUT,
108+
],
109+
'soap' => [
110+
'service' => self::SERVICE_NAME,
111+
'serviceVersion' => self::SERVICE_VERSION,
112+
'operation' => self::SERVICE_NAME . 'Save',
113+
],
114+
];
115+
$this->_webApiCall($serviceInfo, ['entity' => $productData]);
116+
117+
$searchCriteria = $this->buildSearchCriteria($productSimple);
118+
$serviceInfo = $this->buildSearchServiceInfo($searchCriteria);
119+
$response = $this->_webApiCall($serviceInfo, $searchCriteria);
120+
$this->assertArrayHasKey('search_criteria', $response);
121+
$this->assertArrayHasKey('items', $response);
122+
$this->assertGreaterThan(1, count($response['items']));
123+
$this->assertGreaterThan(0, $response['items'][0]['id']);
124+
$this->restoreIndexMode();
125+
}
126+
127+
/**
128+
* @param string $productSku
129+
* @return array
130+
*/
131+
private function buildSearchCriteria(string $productSku): array
132+
{
133+
return [
134+
'searchCriteria' => [
135+
'request_name' => 'quick_search_container',
136+
'filter_groups' => [
137+
[
138+
'filters' => [
139+
[
140+
'field' => 'search_term',
141+
'value' => $productSku,
142+
]
143+
]
144+
]
145+
]
146+
]
147+
];
148+
}
149+
150+
/**
151+
* @param array $searchCriteria
152+
* @return array
153+
*/
154+
private function buildSearchServiceInfo(array $searchCriteria): array
155+
{
156+
return [
157+
'rest' => [
158+
'resourcePath' => self::RESOURCE_PATH_SEARCH . '?' . http_build_query($searchCriteria),
159+
'httpMethod' => Request::HTTP_METHOD_GET
160+
],
161+
'soap' => [
162+
'service' => self::SERVICE_NAME_SEARCH,
163+
'serviceVersion' => self::SERVICE_VERSION,
164+
'operation' => self::SERVICE_NAME_SEARCH . 'Search'
165+
]
166+
];
167+
}
168+
169+
private function setIndexScheduled(): void
170+
{
171+
$indexerListIds = $this->objectManager->get(Config::class)->getIndexers();
172+
foreach ($indexerListIds as $indexerId) {
173+
$indexer = $this->indexerRegistry->get($indexerId['indexer_id']);
174+
$this->indexersState[$indexerId['indexer_id']] = $indexer->isScheduled();
175+
$indexer->setScheduled(true);
176+
}
177+
}
178+
179+
private function restoreIndexMode(): void
180+
{
181+
foreach ($this->indexersState as $indexerId => $state) {
182+
$this->indexerRegistry->get($indexerId)->setScheduled($state);
183+
}
184+
}
67185
}

0 commit comments

Comments
 (0)