File tree Expand file tree Collapse file tree 5 files changed +62
-92
lines changed Expand file tree Collapse file tree 5 files changed +62
-92
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 4
4
5
5
use Magento \Framework \App \AreaInterface ;
6
6
use Magento \Framework \App \AreaList ;
7
- use Magento \Framework \App \ObjectManager ;
8
7
use Magento \Framework \App \State ;
9
- use Magento \Store \Model \StoreManagerInterface ;
10
8
11
9
/**
12
- * Load translations for GraphQL requests
10
+ * Load translations on the first instance of a translated string
13
11
*/
14
12
class TranslationLoader
15
13
{
@@ -23,6 +21,11 @@ class TranslationLoader
23
21
*/
24
22
private $ appState ;
25
23
24
+ /**
25
+ * @var bool
26
+ */
27
+ private $ translationsLoaded = false ;
28
+
26
29
/**
27
30
* @param AreaList $areaList
28
31
* @param State $appState
@@ -36,11 +39,16 @@ public function __construct(
36
39
}
37
40
38
41
/**
39
- * Before rendering any string ensure the translation aspect of area is loaded
42
+ * Before render of any localized string ensure the translation data is loaded
43
+ *
44
+ * @throws \Magento\Framework\Exception\LocalizedException
40
45
*/
41
- public function beforeRender (\ Magento \ Framework \ Phrase $ subject )
46
+ public function beforeRender ()
42
47
{
43
- $ area = $ this ->areaList ->getArea ($ this ->appState ->getAreaCode ());
44
- $ area ->load (AreaInterface::PART_TRANSLATE );
48
+ if ($ this ->translationsLoaded === false ) {
49
+ $ area = $ this ->areaList ->getArea ($ this ->appState ->getAreaCode ());
50
+ $ area ->load (AreaInterface::PART_TRANSLATE );
51
+ $ this ->translationsLoaded = true ;
52
+ }
45
53
}
46
54
}
Original file line number Diff line number Diff line change 44
44
<type name =" Magento\Framework\Phrase" >
45
45
<plugin name =" graphQlLocalizationPhrasePlugin" type =" Magento\GraphQl\Plugin\TranslationLoader" />
46
46
</type >
47
- <type name =" Magento\Store\Model\StoreResolver" >
48
- <plugin name =" graphQlLocalizationStoreResolver" type =" Magento\GraphQl\Plugin\StoreResolver" />
49
- </type >
50
47
</config >
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Magento \StoreGraphQl \Plugin ;
4
+
5
+ use Magento \Framework \App \Request \Http as HttpRequest ;
6
+ use Magento \Framework \App \RequestInterface ;
7
+ use Magento \Store \Model \Resolver \Store ;
8
+
9
+ /**
10
+ * Ensure the store resolver gets the correct scope based on the GraphQl header
11
+ */
12
+ class StoreResolver
13
+ {
14
+ /**
15
+ * @var RequestInterface|HttpRequest
16
+ */
17
+ private $ request ;
18
+
19
+ /**
20
+ * @param RequestInterface $request
21
+ */
22
+ public function __construct (
23
+ RequestInterface $ request
24
+ ) {
25
+ $ this ->request = $ request ;
26
+ }
27
+
28
+ /**
29
+ * If no scope is provided and there is a Store header, ensure the correct store code is used
30
+ *
31
+ * @param Store $subject
32
+ * @param null $scopeId
33
+ * @return array
34
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
35
+ */
36
+ public function beforeGetScope (Store $ subject , $ scopeId = null )
37
+ {
38
+ $ storeCode = $ this ->request ->getHeader ('Store ' );
39
+
40
+ if ($ scopeId === null && $ storeCode ) {
41
+ return [$ storeCode ];
42
+ }
43
+ }
44
+ }
Original file line number Diff line number Diff line change 23
23
</argument >
24
24
</arguments >
25
25
</type >
26
+ <type name =" Magento\Store\Model\Resolver\Store" >
27
+ <plugin name =" graphQlLocalizationStoreResolver" type =" Magento\StoreGraphQl\Plugin\StoreResolver" />
28
+ </type >
26
29
</config >
You can’t perform that action at this time.
0 commit comments