13
13
namespace BitBag \SyliusElasticsearchPlugin \EventListener ;
14
14
15
15
use BitBag \SyliusElasticsearchPlugin \Refresher \ResourceRefresherInterface ;
16
- use Sylius \Component \Core \Model \Product ;
16
+ use Sylius \Component \Core \Model \ProductInterface ;
17
+ use Sylius \Component \Core \Model \ProductVariantInterface ;
17
18
use Sylius \Component \Product \Model \ProductAttribute ;
19
+ use Sylius \Component \Product \Model \ProductOption ;
18
20
use Sylius \Component \Resource \Model \ResourceInterface ;
19
21
use Sylius \Component \Resource \Repository \RepositoryInterface ;
20
22
use Symfony \Component \EventDispatcher \GenericEvent ;
@@ -28,14 +30,18 @@ final class ResourceIndexListener implements ResourceIndexListenerInterface
28
30
29
31
private RepositoryInterface $ attributeRepository ;
30
32
33
+ private RepositoryInterface $ optionRepository ;
34
+
31
35
public function __construct (
32
36
ResourceRefresherInterface $ resourceRefresher ,
33
37
array $ persistersMap ,
34
- RepositoryInterface $ attributeRepository
38
+ RepositoryInterface $ attributeRepository ,
39
+ RepositoryInterface $ optionRepository
35
40
) {
36
41
$ this ->resourceRefresher = $ resourceRefresher ;
37
42
$ this ->persistersMap = $ persistersMap ;
38
43
$ this ->attributeRepository = $ attributeRepository ;
44
+ $ this ->optionRepository = $ optionRepository ;
39
45
}
40
46
41
47
public function updateIndex (GenericEvent $ event ): void
@@ -54,11 +60,16 @@ public function updateIndex(GenericEvent $event): void
54
60
$ this ->resourceRefresher ->refresh ($ resource , $ config [self ::SERVICE_ID_KEY ]);
55
61
}
56
62
57
- if ($ resource instanceof Product
58
- && ProductAttribute::class === $ config [self ::MODEL_KEY ]
59
- ) {
60
- foreach ($ this ->attributeRepository ->findAll () as $ attribute ) {
61
- $ this ->resourceRefresher ->refresh ($ attribute , $ config [self ::SERVICE_ID_KEY ]);
63
+ if ($ resource instanceof ProductInterface || $ resource instanceof ProductVariantInterface) {
64
+ if (ProductAttribute::class === $ config [self ::MODEL_KEY ]) {
65
+ foreach ($ this ->attributeRepository ->findAll () as $ attribute ) {
66
+ $ this ->resourceRefresher ->refresh ($ attribute , $ config [self ::SERVICE_ID_KEY ]);
67
+ }
68
+ }
69
+ if (ProductOption::class === $ config [self ::MODEL_KEY ]) {
70
+ foreach ($ this ->optionRepository ->findAll () as $ option ) {
71
+ $ this ->resourceRefresher ->refresh ($ option , $ config [self ::SERVICE_ID_KEY ]);
72
+ }
62
73
}
63
74
}
64
75
}
0 commit comments