Skip to content

Commit 027c974

Browse files
authored
Merge pull request #7 from magento-commerce/SEARCH-510
Fixed SEARCH-510
2 parents 181f8f3 + e312695 commit 027c974

File tree

6 files changed

+310
-3
lines changed

6 files changed

+310
-3
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogDataExporter\Model\Indexer;
9+
10+
use Magento\Indexer\Model\Indexer;
11+
12+
/**
13+
* Class IndexInvalidationManager
14+
*
15+
* Invalidates indexes by preconfigured events
16+
*/
17+
class IndexInvalidationManager
18+
{
19+
/**
20+
* @var Indexer
21+
*/
22+
private $indexer;
23+
24+
/**
25+
* @var array
26+
*/
27+
private $invalidationEvents;
28+
29+
/**
30+
* IndexInvalidationManager constructor.
31+
*
32+
* @param Indexer $indexer
33+
* @param array $invalidationEvents
34+
*/
35+
public function __construct(
36+
Indexer $indexer,
37+
array $invalidationEvents
38+
) {
39+
$this->indexer = $indexer;
40+
$this->invalidationEvents = $invalidationEvents;
41+
}
42+
43+
/**
44+
* Invalidates all indexes subscribed on event
45+
*
46+
* @param string $eventName
47+
*/
48+
public function invalidate(string $eventName): void
49+
{
50+
$indexers = isset($this->invalidationEvents[$eventName]) ? $this->invalidationEvents[$eventName] : [];
51+
foreach ($indexers as $indexer) {
52+
$this->indexer->load($indexer)->invalidate();
53+
}
54+
}
55+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace Magento\CatalogDataExporter\Plugin\Index;
11+
12+
use Magento\CatalogDataExporter\Model\Indexer\IndexInvalidationManager;
13+
use Magento\Store\Model\ResourceModel\Group;
14+
15+
/**
16+
* Class InvalidateOnGroupChange
17+
*
18+
* Invalidates indexes on Store Group change
19+
*/
20+
class InvalidateOnGroupChange
21+
{
22+
/**
23+
* @var IndexInvalidationManager
24+
*/
25+
private $invalidationManager;
26+
27+
/**
28+
* @var string
29+
*/
30+
private $invalidationEvent;
31+
32+
/**
33+
* InvalidateOnChange constructor.
34+
*
35+
* @param IndexInvalidationManager $invalidationManager
36+
* @param string $invalidationEvent
37+
*/
38+
public function __construct(
39+
IndexInvalidationManager $invalidationManager,
40+
string $invalidationEvent = 'group_changed'
41+
) {
42+
$this->invalidationManager = $invalidationManager;
43+
$this->invalidationEvent = $invalidationEvent;
44+
}
45+
46+
/**
47+
* Invalidate on save
48+
*
49+
* @param Group $subject
50+
* @param Group $result
51+
* @return Group
52+
*
53+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
54+
*/
55+
public function afterSave(Group $subject, Group $result)
56+
{
57+
$this->invalidationManager->invalidate($this->invalidationEvent);
58+
return $result;
59+
}
60+
61+
/**
62+
* Invalidate on delete
63+
*
64+
* @param Group $subject
65+
* @param Group $result
66+
* @return Group
67+
*
68+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
69+
*/
70+
public function afterDelete(Group $subject, Group $result)
71+
{
72+
$this->invalidationManager->invalidate($this->invalidationEvent);
73+
return $result;
74+
}
75+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace Magento\CatalogDataExporter\Plugin\Index;
11+
12+
use Magento\CatalogDataExporter\Model\Indexer\IndexInvalidationManager;
13+
use Magento\Store\Model\ResourceModel\Store;
14+
15+
/**
16+
* Class InvalidateOnGroupChange
17+
*
18+
* Invalidates indexes on Store change
19+
*/
20+
class InvalidateOnStoreChange
21+
{
22+
/**
23+
* @var IndexInvalidationManager
24+
*/
25+
private $invalidationManager;
26+
27+
/**
28+
* @var string
29+
*/
30+
private $invalidationEvent;
31+
32+
/**
33+
* InvalidateOnChange constructor.
34+
*
35+
* @param IndexInvalidationManager $invalidationManager
36+
* @param string $invalidationEvent
37+
*/
38+
public function __construct(
39+
IndexInvalidationManager $invalidationManager,
40+
string $invalidationEvent = 'group_changed'
41+
) {
42+
$this->invalidationManager = $invalidationManager;
43+
$this->invalidationEvent = $invalidationEvent;
44+
}
45+
46+
/**
47+
* Invalidate on save
48+
*
49+
* @param Store $subject
50+
* @param Store $result
51+
* @return Store
52+
*
53+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
54+
*/
55+
public function afterSave(Store $subject, Store $result)
56+
{
57+
$this->invalidationManager->invalidate($this->invalidationEvent);
58+
return $result;
59+
}
60+
61+
/**
62+
* Invalidate on delete
63+
*
64+
* @param Store $subject
65+
* @param Store $result
66+
* @return Store
67+
*
68+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
69+
*/
70+
public function afterDelete(Store $subject, Store $result)
71+
{
72+
$this->invalidationManager->invalidate($this->invalidationEvent);
73+
return $result;
74+
}
75+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace Magento\CatalogDataExporter\Plugin\Index;
11+
12+
use Magento\CatalogDataExporter\Model\Indexer\IndexInvalidationManager;
13+
use Magento\Store\Model\ResourceModel\Website;
14+
15+
class InvalidateOnWebsiteChange
16+
{
17+
/**
18+
* @var IndexInvalidationManager
19+
*/
20+
private $invalidationManager;
21+
22+
/**
23+
* @var string
24+
*/
25+
private $invalidationEvent;
26+
27+
/**
28+
* InvalidateOnChange constructor.
29+
*
30+
* @param IndexInvalidationManager $invalidationManager
31+
* @param string $invalidationEvent
32+
*/
33+
public function __construct(
34+
IndexInvalidationManager $invalidationManager,
35+
string $invalidationEvent = 'website_changed'
36+
) {
37+
$this->invalidationManager = $invalidationManager;
38+
$this->invalidationEvent = $invalidationEvent;
39+
}
40+
41+
/**
42+
* Invalidate on save
43+
*
44+
* @param Website $subject
45+
* @param Website $result
46+
* @return Website
47+
*
48+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
49+
*/
50+
public function afterSave(Website $subject, Website $result)
51+
{
52+
$this->invalidationManager->invalidate($this->invalidationEvent);
53+
return $result;
54+
}
55+
56+
/**
57+
* Invalidate on delete
58+
*
59+
* @param Website $subject
60+
* @param Website $result
61+
* @return Website
62+
*
63+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
64+
*/
65+
public function afterDelete(Website $subject, Website $result)
66+
{
67+
$this->invalidationManager->invalidate($this->invalidationEvent);
68+
return $result;
69+
}
70+
}

app/code/Magento/CatalogDataExporter/etc/di.xml

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,6 @@
444444
</argument>
445445
</arguments>
446446
</type>
447-
448447
<virtualType name="Magento\CatalogDataExporter\Model\Provider\Product\Downloadable\LinkSampleUrlProvider"
449448
type="Magento\CatalogDataExporter\Model\Provider\Product\Downloadable\SampleUrlProvider">
450449
<arguments>
@@ -460,12 +459,42 @@
460459
</argument>
461460
</arguments>
462461
</type>
463-
464462
<type name="Magento\Framework\Setup\Declaration\Schema\Operations\AddColumn">
465463
<arguments>
466464
<argument name="triggers" xsi:type="array">
467465
<item name="migrateDataFromJSON" xsi:type="object">Magento\CatalogDataExporter\Plugin\DDLTrigger\MigrateDataFromJSON</item>
468466
</argument>
469467
</arguments>
470468
</type>
469+
<!-- Indexes mass-invalidation logic -->
470+
<type name="Magento\CatalogDataExporter\Model\Indexer\IndexInvalidationManager">
471+
<arguments>
472+
<argument name="invalidationEvents" xsi:type="array">
473+
<item name="store_changed" xsi:type="array">
474+
<item name="products" xsi:type="string">catalog_data_exporter_products</item>
475+
<item name="categories" xsi:type="string">catalog_data_exporter_product_attributes</item>
476+
<item name="product_attributes" xsi:type="string">catalog_data_exporter_categories</item>
477+
</item>
478+
<item name="website_changed" xsi:type="array">
479+
<item name="products" xsi:type="string">catalog_data_exporter_products</item>
480+
<item name="categories" xsi:type="string">catalog_data_exporter_product_attributes</item>
481+
<item name="product_attributes" xsi:type="string">catalog_data_exporter_categories</item>
482+
</item>
483+
<item name="group_changed" xsi:type="array">
484+
<item name="products" xsi:type="string">catalog_data_exporter_products</item>
485+
<item name="categories" xsi:type="string">catalog_data_exporter_product_attributes</item>
486+
<item name="product_attributes" xsi:type="string">catalog_data_exporter_categories</item>
487+
</item>
488+
</argument>
489+
</arguments>
490+
</type>
491+
<type name="Magento\Store\Model\ResourceModel\Website">
492+
<plugin name="invalidate_feed_index_on_store_change" type="Magento\CatalogDataExporter\Plugin\Index\InvalidateOnWebsiteChange" />
493+
</type>
494+
<type name="Magento\Store\Model\ResourceModel\Group">
495+
<plugin name="invalidate_feed_index_on_group_change" type="Magento\CatalogDataExporter\Plugin\Index\InvalidateOnGroupChange" />
496+
</type>
497+
<type name="Magento\Store\Model\ResourceModel\Store">
498+
<plugin name="invalidate_feed_index_on_website_change" type="Magento\CatalogDataExporter\Plugin\Index\InvalidateOnStoreChange" />
499+
</type>
471500
</config>

app/code/Magento/ConfigurableProductDataExporter/Test/Integration/ConfigurableProductsTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,10 @@ private function validateVariantsData(ProductInterface $product, array $extract,
196196
'selections' => $this->getVariantSelections($childProduct, $attributeCodes)
197197
];
198198
}
199-
$this->assertEquals($variants, $extract['feedData']['variants']);
199+
$actualVariants = $extract['feedData']['variants'];
200+
usort($actualVariants, function ($a, $b){return $a['sku'] <=> $b['sku'];});
201+
usort($variants, function ($a, $b){return $a['sku'] <=> $b['sku'];});
202+
$this->assertEquals($variants, $actualVariants);
200203
}
201204

202205
/**

0 commit comments

Comments
 (0)