File tree Expand file tree Collapse file tree 6 files changed +170
-1
lines changed
app/code/Magento/DirectoryGraphQl Expand file tree Collapse file tree 6 files changed +170
-1
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * Copyright © Magento, Inc. All rights reserved.
4+ * See COPYING.txt for license details.
5+ */
6+ declare (strict_types=1 );
7+
8+ namespace Magento \DirectoryGraphQl \Model \Cache \Tag \Strategy ;
9+
10+ use Magento \Directory \Model \Currency as CurrencyModel ;
11+ use Magento \DirectoryGraphQl \Model \Resolver \Currency \Identity ;
12+ use Magento \Framework \App \Cache \Tag \StrategyInterface ;
13+
14+ /**
15+ * Produce cache tags for currency object.
16+ */
17+ class Currency implements StrategyInterface
18+ {
19+ /**
20+ * @inheritdoc
21+ */
22+ public function getTags ($ object ): array
23+ {
24+ if (!is_object ($ object )) {
25+ throw new \InvalidArgumentException ('Provided argument is not an object ' );
26+ }
27+
28+ if ($ object instanceof CurrencyModel) {
29+ return [Identity::CACHE_TAG ];
30+ }
31+
32+ return [];
33+ }
34+ }
Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * Copyright © Magento, Inc. All rights reserved.
4+ * See COPYING.txt for license details.
5+ */
6+ declare (strict_types=1 );
7+
8+ namespace Magento \DirectoryGraphQl \Model \Cache \Tag \Strategy ;
9+
10+ use Magento \CurrencySymbol \Model \System \Currencysymbol ;
11+ use Magento \Directory \Model \Currency ;
12+ use Magento \DirectoryGraphQl \Model \Resolver \Currency \Identity ;
13+ use Magento \Framework \App \Cache \Tag \StrategyInterface ;
14+ use Magento \Framework \App \Config \ValueInterface ;
15+
16+ /**
17+ * Produce cache tags for currency config.
18+ */
19+ class CurrencyConfig implements StrategyInterface
20+ {
21+ private $ currencyConfigPaths = [
22+ Currency::XML_PATH_CURRENCY_BASE ,
23+ Currency::XML_PATH_CURRENCY_DEFAULT ,
24+ Currency::XML_PATH_CURRENCY_ALLOW ,
25+ Currencysymbol::XML_PATH_CUSTOM_CURRENCY_SYMBOL
26+ ];
27+
28+ /**
29+ * @inheritdoc
30+ */
31+ public function getTags ($ object ): array
32+ {
33+ if (!is_object ($ object )) {
34+ throw new \InvalidArgumentException ('Provided argument is not an object ' );
35+ }
36+
37+ if (
38+ $ object instanceof ValueInterface
39+ && in_array ($ object ->getPath (), $ this ->currencyConfigPaths )
40+ && $ object ->isValueChanged ()
41+ ) {
42+ return [Identity::CACHE_TAG ];
43+ }
44+
45+ return [];
46+ }
47+ }
Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * Copyright © Magento, Inc. All rights reserved.
4+ * See COPYING.txt for license details.
5+ */
6+ declare (strict_types=1 );
7+
8+ namespace Magento \DirectoryGraphQl \Model \Resolver \Currency ;
9+
10+ use Magento \Framework \GraphQl \Query \Resolver \IdentityInterface ;
11+
12+ class Identity implements IdentityInterface
13+ {
14+ /**
15+ * @var string
16+ */
17+ public const CACHE_TAG = 'gql_currency ' ;
18+
19+ public function getIdentities (array $ resolvedData ): array
20+ {
21+ return [self ::CACHE_TAG ];
22+ }
23+ }
Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * Copyright © Magento, Inc. All rights reserved.
4+ * See COPYING.txt for license details.
5+ */
6+ declare (strict_types=1 );
7+
8+ namespace Magento \DirectoryGraphQl \Plugin ;
9+
10+ use Magento \Framework \Event \ManagerInterface ;
11+ use Magento \Directory \Model \Currency as CurrencyModel ;
12+
13+ /**
14+ * Currency plugin
15+ */
16+ class Currency
17+ {
18+ /**
19+ * Application Event Dispatcher
20+ *
21+ * @var ManagerInterface
22+ */
23+ private $ eventManager ;
24+
25+ /**
26+ * @param ManagerInterface $eventManager
27+ */
28+ public function __construct (ManagerInterface $ eventManager )
29+ {
30+ $ this ->eventManager = $ eventManager ;
31+ }
32+
33+ /**
34+ * Add graphql store config tag to the store group cache identities.
35+ *
36+ * @param CurrencyModel $subject
37+ * @param CurrencyModel $result
38+ * @return CurrencyModel
39+ */
40+ public function afterSaveRates (CurrencyModel $ subject , CurrencyModel $ result ): CurrencyModel
41+ {
42+ $ this ->eventManager ->dispatch ('clean_cache_by_tags ' , ['object ' => $ this ]);
43+ return $ result ;
44+ }
45+ }
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" ?>
2+ <!--
3+ /**
4+ * Copyright © Magento, Inc. All rights reserved.
5+ * See COPYING.txt for license details.
6+ */
7+ -->
8+ <config xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance" xsi : noNamespaceSchemaLocation =" urn:magento:framework:ObjectManager/etc/config.xsd" >
9+ <type name =" Magento\Framework\App\Cache\Tag\Strategy\Factory" >
10+ <arguments >
11+ <argument name =" customStrategies" xsi : type =" array" >
12+ <item name =" Magento\Framework\App\Config\ValueInterface" xsi : type =" object" >\Magento\DirectoryGraphQl\Model\Cache\Tag\Strategy\CurrencyConfig</item >
13+ <item name =" Magento\Directory\Model\Currency" xsi : type =" object" >\Magento\DirectoryGraphQl\Model\Cache\Tag\Strategy\Currency</item >
14+ </argument >
15+ </arguments >
16+ </type >
17+ <type name =" Magento\Directory\Model\Currency" >
18+ <plugin name =" afterSaveRate" type =" Magento\DirectoryGraphQl\Plugin\Currency" />
19+ </type >
20+ </config >
Original file line number Diff line number Diff line change 22# See COPYING.txt for license details.
33
44type Query {
5- currency : Currency @resolver (class : " Magento\\ DirectoryGraphQl\\ Model\\ Resolver\\ Currency" ) @doc (description : " Return information about the store's currency." ) @cache (cacheable : false )
5+ currency : Currency @resolver (class : " Magento\\ DirectoryGraphQl\\ Model\\ Resolver\\ Currency" ) @doc (description : " Return information about the store's currency." ) @cache (cacheIdentity : " Magento \\ DirectoryGraphQl \\ Model \\ Resolver \\ Currency \\ Identity " )
66 countries : [Country ] @resolver (class : " Magento\\ DirectoryGraphQl\\ Model\\ Resolver\\ Countries" ) @doc (description : " The countries query provides information for all countries." ) @cache (cacheable : false )
77 country (id : String ): Country @resolver (class : " Magento\\ DirectoryGraphQl\\ Model\\ Resolver\\ Country" ) @doc (description : " The countries query provides information for a single country." ) @cache (cacheable : false )
88}
You can’t perform that action at this time.
0 commit comments