44
55use Algolia \AlgoliaSearch \Exceptions \AlgoliaException ;
66use Algolia \AlgoliaSearch \Helper \ConfigHelper ;
7- use Algolia \AlgoliaSearch \Registry \CurrentCategory ;
87use Algolia \AlgoliaSearch \Service \AlgoliaCredentialsManager ;
9- use Magento \ Catalog \ Model \ Category ;
8+ use Algolia \ AlgoliaSearch \ Service \ RenderingManager ;
109use Magento \Framework \App \Request \Http ;
1110use Magento \Framework \Event \Observer ;
1211use Magento \Framework \Event \ObserverInterface ;
1312use Magento \Framework \Exception \NoSuchEntityException ;
1413use Magento \Framework \View \Layout ;
15- use Magento \Framework \View \Page \Config as PageConfig ;
1614use Magento \Store \Model \StoreManagerInterface ;
1715
1816/**
@@ -22,13 +20,11 @@ class AddAlgoliaAssetsObserver implements ObserverInterface
2220{
2321 public function __construct (
2422 protected ConfigHelper $ config ,
25- protected CurrentCategory $ category ,
23+ protected RenderingManager $ renderingManager ,
2624 protected StoreManagerInterface $ storeManager ,
27- protected PageConfig $ pageConfig ,
2825 protected Http $ request ,
2926 protected AlgoliaCredentialsManager $ algoliaCredentialsManager
30- )
31- {}
27+ ) {}
3228
3329 /**
3430 * @throws NoSuchEntityException|AlgoliaException
@@ -39,42 +35,16 @@ public function execute(Observer $observer): void
3935 if ($ actionName === 'swagger_index_index ' ) {
4036 return ;
4137 }
42- $ storeId = $ this ->storeManager ->getStore ()->getId ();
43- if ($ this ->config ->isEnabledFrontEnd ($ storeId )) {
44- if ($ this ->algoliaCredentialsManager ->checkCredentials ($ storeId )) {
45- if ($ this ->config ->isAutoCompleteEnabled ($ storeId ) || $ this ->config ->isInstantEnabled ($ storeId )) {
46- /** @var Layout $layout */
47- $ layout = $ observer ->getData ('layout ' );
48- $ layout ->getUpdate ()->addHandle ('algolia_search_handle ' );
49-
50- $ this ->loadPreventBackendRenderingHandle ($ layout , $ storeId );
51- }
52- }
53- }
54- }
55-
56- private function loadPreventBackendRenderingHandle (Layout $ layout , int $ storeId ): void
57- {
58- if (!$ this ->config ->preventBackendRendering ($ storeId )) {
59- return ;
60- }
61-
62- $ category = $ this ->category ->get ();
6338
64- if (!$ category ->getId ()) {
65- return ;
66- }
39+ $ storeId = $ this ->storeManager ->getStore ()->getId ();
6740
68- if (! $ this ->config ->replaceCategories ($ storeId )) {
69- return ;
70- }
41+ if ($ this ->config ->isEnabledFrontEnd ( $ storeId ) && $ this -> algoliaCredentialsManager -> checkCredentials ($ storeId )) {
42+ /** @var Layout $layout */
43+ $ layout = $ observer -> getData ( ' layout ' );
7144
72- $ displayMode = $ this ->config ->getBackendRenderingDisplayMode ($ storeId );
73- if ($ displayMode === 'only_products '
74- && $ category ->getData ('display_mode ' ) === \Magento \Catalog \Model \Category::DM_PAGE ) {
75- return ;
45+ $ this ->renderingManager ->handleFrontendAssets ($ layout , $ storeId );
46+ $ this ->renderingManager ->handleBackendRendering ($ layout , $ actionName , $ storeId );
7647 }
77-
78- $ layout ->getUpdate ()->addHandle ('algolia_search_handle_prevent_backend_rendering ' );
7948 }
49+
8050}
0 commit comments