Skip to content

Commit 190ec17

Browse files
authored
Merge pull request #159 from crackgm/fix/reindex-product-taxon
Fix/reindex product taxon
2 parents 4402730 + 33c3360 commit 190ec17

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file has been created by developers from BitBag.
7+
* Feel free to contact us once you face any issues or want to start
8+
* another great project.
9+
* You can find more information about us on https://bitbag.shop and write us
10+
* an email on [email protected].
11+
*/
12+
13+
namespace BitBag\SyliusElasticsearchPlugin\EventListener;
14+
15+
use BitBag\SyliusElasticsearchPlugin\Refresher\ResourceRefresherInterface;
16+
use Sylius\Component\Core\Model\ProductTaxonInterface;
17+
use Sylius\Component\Resource\Model\ResourceInterface;
18+
use Symfony\Component\EventDispatcher\GenericEvent;
19+
use Webmozart\Assert\Assert;
20+
21+
final class ProductTaxonIndexListener
22+
{
23+
/** @var ResourceRefresherInterface */
24+
private $resourceRefresher;
25+
26+
/** @var string */
27+
private $objectPersisterId;
28+
29+
public function __construct(ResourceRefresherInterface $resourceRefresher, string $objectPersisterId)
30+
{
31+
$this->resourceRefresher = $resourceRefresher;
32+
$this->objectPersisterId = $objectPersisterId;
33+
}
34+
35+
public function updateIndex(ProductTaxonInterface $productTaxon): void
36+
{
37+
$this->resourceRefresher->refresh($productTaxon->getProduct(), $this->objectPersisterId);
38+
}
39+
}

src/Resources/config/services/event_listener.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
<tag name="kernel.event_listener" event="sylius.product_variant.post_create" method="updateIndex" />
2929
<tag name="kernel.event_listener" event="sylius.product_variant.post_update" method="updateIndex" />
3030
</service>
31+
<service id="bitbag_sylius_elasticsearch_plugin.event_listener.product_taxon_index" class="BitBag\SyliusElasticsearchPlugin\EventListener\ProductTaxonIndexListener">
32+
<argument type="service" id="bitbag.sylius_elasticsearch_plugin.refresher.resource" />
33+
<argument>fos_elastica.object_persister.bitbag_shop_product.default</argument>
34+
<tag name="doctrine.orm.entity_listener" event="postUpdate" method="updateIndex" entity="%sylius.model.product_taxon.class%" />
35+
</service>
3136
<service id="bitbag_sylius_elasticsearch_plugin.event_listener.order_products" class="BitBag\SyliusElasticsearchPlugin\EventListener\OrderProductsListener" public="true">
3237
<argument type="service" id="bitbag.sylius_elasticsearch_plugin.refresher.resource" />
3338
<argument type="string">fos_elastica.object_persister.bitbag_shop_product.default</argument>

0 commit comments

Comments
 (0)