Skip to content

Commit

Permalink
Merge pull request #150 from leszczuu/fix/reindex-products-after-order
Browse files Browse the repository at this point in the history
Changed event to sylius.order.post_complete
  • Loading branch information
patrick477 authored Dec 3, 2020
2 parents 33485b0 + b2c7813 commit 4f8692b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
8 changes: 6 additions & 2 deletions src/EventListener/OrderProductsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
namespace BitBag\SyliusElasticsearchPlugin\EventListener;

use BitBag\SyliusElasticsearchPlugin\Refresher\ResourceRefresherInterface;
use Sylius\Component\Core\Model\Order;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\OrderItem;
use Sylius\Component\Core\Model\OrderItemInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
use Webmozart\Assert\Assert;

final class OrderProductsListener
{
Expand All @@ -32,8 +33,11 @@ public function __construct(ResourceRefresherInterface $resourceRefresher, strin
$this->productPersister = $productPersister;
}

public function updateOrderProducts(OrderInterface $order): void
public function updateOrderProducts(GenericEvent $event): void
{
$order = $event->getSubject();
Assert::isInstanceOf($order, OrderInterface::class);

/** @var OrderItemInterface $orderItem */
foreach ($order->getItems() as $orderItem) {
$this->resourceRefresher->refresh($orderItem->getProduct(), $this->productPersister);
Expand Down
1 change: 0 additions & 1 deletion src/Resources/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ imports:
- { resource: "indexes/bitbag_option_taxons.yml" }
- { resource: "indexes/bitbag_attribute_taxons.yml" }
- { resource: "indexes/bitbag_shop_facets.yml" }
- { resource: "state_machine/sylius_order.yaml" }

parameters:
bitbag_es_host: localhost
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/services/event_listener.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<service id="bitbag_sylius_elasticsearch_plugin.event_listener.order_products" class="BitBag\SyliusElasticsearchPlugin\EventListener\OrderProductsListener" public="true">
<argument type="service" id="bitbag.sylius_elasticsearch_plugin.refresher.resource" />
<argument type="string">fos_elastica.object_persister.bitbag_shop_product.default</argument>
<tag name="kernel.event_listener" event="sylius.order.post_complete" method="updateOrderProducts" />
</service>
</services>
</container>
8 changes: 0 additions & 8 deletions src/Resources/config/state_machine/sylius_order.yaml

This file was deleted.

0 comments on commit 4f8692b

Please sign in to comment.