Skip to content

Commit b9c57c8

Browse files
committed
Merge remote-tracking branch 'l3/ACP2E-673' into PR_L3_05_04_2022
2 parents 616e04f + 36a0b31 commit b9c57c8

File tree

2 files changed

+215
-66
lines changed

2 files changed

+215
-66
lines changed

app/code/Magento/CatalogRule/Model/Indexer/ReindexRuleProduct.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function execute(Rule $rule, $batchCount, $useAdditionalTable = false)
124124
: $toTimeInAdminTz;
125125

126126
foreach ($productIds as $productId => $validationByWebsite) {
127-
if (empty($validationByWebsite[$websiteId])) {
127+
if (!isset($validationByWebsite[$websiteId]) || $validationByWebsite[$websiteId] === null) {
128128
continue;
129129
}
130130

app/code/Magento/CatalogRule/Test/Unit/Model/Indexer/ReindexRuleProductTest.php

Lines changed: 214 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ class ReindexRuleProductTest extends TestCase
5252
*/
5353
private $ruleMock;
5454

55+
/**
56+
* @var string
57+
*/
58+
private $adminTimeZone;
59+
60+
/**
61+
* @var string
62+
*/
63+
private $websiteTz;
64+
5565
/**
5666
* @inheritDoc
5767
*/
@@ -71,6 +81,9 @@ protected function setUp(): void
7181
$this->localeDateMock,
7282
true
7383
);
84+
85+
$this->adminTimeZone = 'America/Chicago';
86+
$this->websiteTz = 'America/Los_Angeles';
7487
}
7588

7689
/**
@@ -106,8 +119,6 @@ public function testExecuteIfRuleWithoutWebsiteIds(): void
106119
public function testExecute(): void
107120
{
108121
$websiteId = 3;
109-
$adminTimeZone = 'America/Chicago';
110-
$websiteTz = 'America/Los_Angeles';
111122
$productIds = [
112123
4 => [$websiteId => 1],
113124
5 => [$websiteId => 1],
@@ -119,8 +130,8 @@ public function testExecute(): void
119130

120131
$this->localeDateMock->method('getConfigTimezone')
121132
->willReturnMap([
122-
[ScopeInterface::SCOPE_WEBSITE, self::ADMIN_WEBSITE_ID, $adminTimeZone],
123-
[ScopeInterface::SCOPE_WEBSITE, $websiteId, $websiteTz]
133+
[ScopeInterface::SCOPE_WEBSITE, self::ADMIN_WEBSITE_ID, $this->adminTimeZone],
134+
[ScopeInterface::SCOPE_WEBSITE, $websiteId, $this->websiteTz]
124135
]);
125136

126137
$batchRows = [
@@ -176,19 +187,14 @@ public function testExecute(): void
176187
}
177188

178189
/**
190+
* @param array $websitesIds
191+
* @param array $productIds
192+
* @param array $batchRows
179193
* @return void
194+
* @dataProvider executeDataProvider
180195
*/
181-
public function testExecuteWithExcludedWebsites(): void
196+
public function testExecuteWithExcludedWebsites(array $websitesIds, array $productIds, array $batchRows): void
182197
{
183-
$websitesIds = [1, 2, 3];
184-
$adminTimeZone = 'America/Chicago';
185-
$websiteTz = 'America/Los_Angeles';
186-
$productIds = [
187-
1 => [1 => 1],
188-
2 => [2 => 1],
189-
3 => [3 => 1]
190-
];
191-
192198
$this->prepareResourceMock();
193199
$this->prepareRuleMock($websitesIds, $productIds, [10, 20]);
194200

@@ -203,68 +209,211 @@ public function testExecuteWithExcludedWebsites(): void
203209

204210
$this->localeDateMock->method('getConfigTimezone')
205211
->willReturnMap([
206-
[ScopeInterface::SCOPE_WEBSITE, self::ADMIN_WEBSITE_ID, $adminTimeZone],
207-
[ScopeInterface::SCOPE_WEBSITE, 1, $websiteTz],
208-
[ScopeInterface::SCOPE_WEBSITE, 2, $websiteTz],
209-
[ScopeInterface::SCOPE_WEBSITE, 3, $websiteTz]
212+
[ScopeInterface::SCOPE_WEBSITE, self::ADMIN_WEBSITE_ID, $this->adminTimeZone],
213+
[ScopeInterface::SCOPE_WEBSITE, 1, $this->websiteTz],
214+
[ScopeInterface::SCOPE_WEBSITE, 2, $this->websiteTz],
215+
[ScopeInterface::SCOPE_WEBSITE, 3, $this->websiteTz]
210216
]);
211217

212-
$batchRows = [
218+
$this->connectionMock
219+
->method('insertMultiple')
220+
->with('catalogrule_product_replica', $batchRows);
221+
222+
self::assertTrue($this->model->execute($this->ruleMock, 100, true));
223+
}
224+
225+
/**
226+
* @return array
227+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
228+
*/
229+
public function executeDataProvider(): array
230+
{
231+
return [
213232
[
214-
'rule_id' => 100,
215-
'from_time' => 1498028400,
216-
'to_time' => 1498892399,
217-
'website_id' => 1,
218-
'customer_group_id' => 20,
219-
'product_id' => 1,
220-
'action_operator' => 'simple_action',
221-
'action_amount' => 43,
222-
'action_stop' => true,
223-
'sort_order' => 1
233+
[1, 2, 3],
234+
[
235+
1 => [1 => 1],
236+
2 => [2 => 1],
237+
3 => [3 => 1]
238+
],
239+
[
240+
[
241+
'rule_id' => 100,
242+
'from_time' => 1498028400,
243+
'to_time' => 1498892399,
244+
'website_id' => 1,
245+
'customer_group_id' => 20,
246+
'product_id' => 1,
247+
'action_operator' => 'simple_action',
248+
'action_amount' => 43,
249+
'action_stop' => true,
250+
'sort_order' => 1
251+
],
252+
[
253+
'rule_id' => 100,
254+
'from_time' => 1498028400,
255+
'to_time' => 1498892399,
256+
'website_id' => 2,
257+
'customer_group_id' => 20,
258+
'product_id' => 2,
259+
'action_operator' => 'simple_action',
260+
'action_amount' => 43,
261+
'action_stop' => true,
262+
'sort_order' => 1
263+
],
264+
[
265+
'rule_id' => 100,
266+
'from_time' => 1498028400,
267+
'to_time' => 1498892399,
268+
'website_id' => 3,
269+
'customer_group_id' => 10,
270+
'product_id' => 3,
271+
'action_operator' => 'simple_action',
272+
'action_amount' => 43,
273+
'action_stop' => true,
274+
'sort_order' => 1
275+
],
276+
[
277+
'rule_id' => 100,
278+
'from_time' => 1498028400,
279+
'to_time' => 1498892399,
280+
'website_id' => 3,
281+
'customer_group_id' => 20,
282+
'product_id' => 3,
283+
'action_operator' => 'simple_action',
284+
'action_amount' => 43,
285+
'action_stop' => true,
286+
'sort_order' => 1
287+
]
288+
]
224289
],
225290
[
226-
'rule_id' => 100,
227-
'from_time' => 1498028400,
228-
'to_time' => 1498892399,
229-
'website_id' => 2,
230-
'customer_group_id' => 20,
231-
'product_id' => 2,
232-
'action_operator' => 'simple_action',
233-
'action_amount' => 43,
234-
'action_stop' => true,
235-
'sort_order' => 1
291+
[1, 2, 3],
292+
[
293+
1 => [1 => true],
294+
2 => [2 => 'true'],
295+
3 => [3 => 0]
296+
],
297+
[
298+
[
299+
'rule_id' => 100,
300+
'from_time' => 1498028400,
301+
'to_time' => 1498892399,
302+
'website_id' => 1,
303+
'customer_group_id' => 20,
304+
'product_id' => 1,
305+
'action_operator' => 'simple_action',
306+
'action_amount' => 43,
307+
'action_stop' => true,
308+
'sort_order' => 1
309+
],
310+
[
311+
'rule_id' => 100,
312+
'from_time' => 1498028400,
313+
'to_time' => 1498892399,
314+
'website_id' => 2,
315+
'customer_group_id' => 20,
316+
'product_id' => 2,
317+
'action_operator' => 'simple_action',
318+
'action_amount' => 43,
319+
'action_stop' => true,
320+
'sort_order' => 1
321+
],
322+
[
323+
'rule_id' => 100,
324+
'from_time' => 1498028400,
325+
'to_time' => 1498892399,
326+
'website_id' => 3,
327+
'customer_group_id' => 10,
328+
'product_id' => 3,
329+
'action_operator' => 'simple_action',
330+
'action_amount' => 43,
331+
'action_stop' => true,
332+
'sort_order' => 1
333+
],
334+
[
335+
'rule_id' => 100,
336+
'from_time' => 1498028400,
337+
'to_time' => 1498892399,
338+
'website_id' => 3,
339+
'customer_group_id' => 20,
340+
'product_id' => 3,
341+
'action_operator' => 'simple_action',
342+
'action_amount' => 43,
343+
'action_stop' => true,
344+
'sort_order' => 1
345+
]
346+
]
236347
],
237348
[
238-
'rule_id' => 100,
239-
'from_time' => 1498028400,
240-
'to_time' => 1498892399,
241-
'website_id' => 3,
242-
'customer_group_id' => 10,
243-
'product_id' => 3,
244-
'action_operator' => 'simple_action',
245-
'action_amount' => 43,
246-
'action_stop' => true,
247-
'sort_order' => 1
349+
[1, 2, 3],
350+
[
351+
1 => [1 => true],
352+
2 => [2 => true],
353+
3 => [3 => null]
354+
],
355+
[
356+
[
357+
'rule_id' => 100,
358+
'from_time' => 1498028400,
359+
'to_time' => 1498892399,
360+
'website_id' => 1,
361+
'customer_group_id' => 20,
362+
'product_id' => 1,
363+
'action_operator' => 'simple_action',
364+
'action_amount' => 43,
365+
'action_stop' => true,
366+
'sort_order' => 1
367+
],
368+
[
369+
'rule_id' => 100,
370+
'from_time' => 1498028400,
371+
'to_time' => 1498892399,
372+
'website_id' => 2,
373+
'customer_group_id' => 20,
374+
'product_id' => 2,
375+
'action_operator' => 'simple_action',
376+
'action_amount' => 43,
377+
'action_stop' => true,
378+
'sort_order' => 1
379+
]
380+
]
248381
],
249382
[
250-
'rule_id' => 100,
251-
'from_time' => 1498028400,
252-
'to_time' => 1498892399,
253-
'website_id' => 3,
254-
'customer_group_id' => 20,
255-
'product_id' => 3,
256-
'action_operator' => 'simple_action',
257-
'action_amount' => 43,
258-
'action_stop' => true,
259-
'sort_order' => 1
383+
[1, 2, 3],
384+
[
385+
1 => [1 => true],
386+
2 => [2 => true],
387+
3 => []
388+
],
389+
[
390+
[
391+
'rule_id' => 100,
392+
'from_time' => 1498028400,
393+
'to_time' => 1498892399,
394+
'website_id' => 1,
395+
'customer_group_id' => 20,
396+
'product_id' => 1,
397+
'action_operator' => 'simple_action',
398+
'action_amount' => 43,
399+
'action_stop' => true,
400+
'sort_order' => 1
401+
],
402+
[
403+
'rule_id' => 100,
404+
'from_time' => 1498028400,
405+
'to_time' => 1498892399,
406+
'website_id' => 2,
407+
'customer_group_id' => 20,
408+
'product_id' => 2,
409+
'action_operator' => 'simple_action',
410+
'action_amount' => 43,
411+
'action_stop' => true,
412+
'sort_order' => 1
413+
]
414+
]
260415
]
261416
];
262-
263-
$this->connectionMock
264-
->method('insertMultiple')
265-
->with('catalogrule_product_replica', $batchRows);
266-
267-
self::assertTrue($this->model->execute($this->ruleMock, 100, true));
268417
}
269418

270419
/**

0 commit comments

Comments
 (0)