File tree Expand file tree Collapse file tree 3 files changed +64
-0
lines changed Expand file tree Collapse file tree 3 files changed +64
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Algolia \AlgoliaSearch \Observer ;
4
+
5
+ use Algolia \AlgoliaSearch \Registry \CurrentCategory ;
6
+ use Magento \Catalog \Api \Data \CategoryInterface ;
7
+ use Magento \Framework \Event \Observer ;
8
+ use Magento \Framework \Event \ObserverInterface ;
9
+
10
+ class RegisterCurrentCategoryObserver implements ObserverInterface
11
+ {
12
+ /** @var CurrentCategory */
13
+ private CurrentCategory $ currentCategory ;
14
+
15
+ public function __construct (CurrentCategory $ currentCategory ) {
16
+ $ this ->currentCategory = $ currentCategory ;
17
+ }
18
+
19
+ /**
20
+ * @inheritDoc
21
+ */
22
+ public function execute (Observer $ observer )
23
+ {
24
+ /** @var CategoryInterface */
25
+ $ category = $ observer ->getEvent ()->getData ('category ' );
26
+ $ this ->currentCategory ->set ($ category );
27
+ }
28
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Algolia \AlgoliaSearch \Registry ;
4
+
5
+ use Magento \Catalog \Api \CategoryRepositoryInterface ;
6
+ use Magento \Catalog \Api \Data \CategoryInterface ;
7
+ use Magento \Catalog \Api \Data \CategoryInterfaceFactory ;
8
+
9
+ class CurrentCategory
10
+ {
11
+ private CategoryInterface $ category ;
12
+ private CategoryRepositoryInterface $ categoryRepository ;
13
+ private CategoryInterfaceFactory $ categoryFactory ;
14
+
15
+ public function __construct (
16
+ CategoryRepositoryInterface $ categoryRepository ,
17
+ CategoryInterfaceFactory $ categoryFactory
18
+ )
19
+ {
20
+ $ this ->categoryRepository = $ categoryRepository ;
21
+ $ this ->categoryFactory = $ categoryFactory ;
22
+ }
23
+
24
+ public function set (CategoryInterface $ category ): void {
25
+ $ this ->category = $ category ;
26
+ }
27
+
28
+ public function get (): CategoryInterface {
29
+ return $ this ->category ?? $ this ->categoryFactory ->create ();
30
+ }
31
+ }
Original file line number Diff line number Diff line change 23
23
<event name =" checkout_onepage_controller_success_action" >
24
24
<observer name =" algoliasearch_insights_place_order_event" instance =" Algolia\AlgoliaSearch\Observer\Insights\CheckoutOnepageControllerSuccessAction" />
25
25
</event >
26
+
27
+ <!-- Registry -->
28
+ <event name =" catalog_controller_category_init_after" >
29
+ <observer name =" algoliasearch_current_category" instance =" Algolia\AlgoliaSearch\Observer\RegisterCurrentCategoryObserver" />
30
+ </event >
26
31
</config >
You can’t perform that action at this time.
0 commit comments