15
15
use Magento \Store \Model \ScopeInterface ;
16
16
use Magento \Store \Model \Store ;
17
17
use Magento \MediaStorage \Helper \File \Storage \Database ;
18
+ use \Magento \Directory \Api \CountryInformationAcquirerInterface ;
19
+ use \Magento \Directory \Model \RegionFactory ;
18
20
19
21
/**
20
22
* Template model class.
@@ -58,6 +60,16 @@ abstract class AbstractTemplate extends AbstractModel implements TemplateTypesIn
58
60
*/
59
61
const XML_PATH_DESIGN_EMAIL_LOGO_HEIGHT = 'design/email/logo_height ' ;
60
62
63
+ /**
64
+ * Email country id
65
+ */
66
+ const XML_PATH_GENERAL_STORE_INFORMATION_COUNTRY_ID = 'general/store_information/country_id ' ;
67
+
68
+ /**
69
+ * Email region id
70
+ */
71
+ const XML_PATH_GENERAL_STORE_INFORMATION_REGION_ID = 'general/store_information/region_id ' ;
72
+
61
73
/**
62
74
* Configuration of design package for template
63
75
*
@@ -165,6 +177,16 @@ abstract class AbstractTemplate extends AbstractModel implements TemplateTypesIn
165
177
*/
166
178
private $ urlModel ;
167
179
180
+ /**
181
+ * @var \Magento\Directory\Api\CountryInformationAcquirerInterface
182
+ */
183
+ protected $ countryInformationAcquirerInterface ;
184
+
185
+ /**
186
+ * @var \Magento\Directory\Model\RegionFactory
187
+ */
188
+ protected $ regionFactory ;
189
+
168
190
/**
169
191
* @var Database
170
192
*/
@@ -183,6 +205,8 @@ abstract class AbstractTemplate extends AbstractModel implements TemplateTypesIn
183
205
* @param \Magento\Email\Model\TemplateFactory $templateFactory
184
206
* @param \Magento\Framework\Filter\FilterManager $filterManager
185
207
* @param \Magento\Framework\UrlInterface $urlModel
208
+ * @param CountryInformationAcquirerInterface $countryInformationAcquirerInterface
209
+ * @param RegionFactory $regionFactory
186
210
* @param array $data
187
211
* @param Database $fileStorageDatabase
188
212
*
@@ -201,6 +225,8 @@ public function __construct(
201
225
\Magento \Email \Model \TemplateFactory $ templateFactory ,
202
226
\Magento \Framework \Filter \FilterManager $ filterManager ,
203
227
\Magento \Framework \UrlInterface $ urlModel ,
228
+ CountryInformationAcquirerInterface $ countryInformationAcquirerInterface ,
229
+ RegionFactory $ regionFactory ,
204
230
array $ data = [],
205
231
Database $ fileStorageDatabase = null
206
232
) {
@@ -216,6 +242,8 @@ public function __construct(
216
242
$ this ->templateFactory = $ templateFactory ;
217
243
$ this ->filterManager = $ filterManager ;
218
244
$ this ->urlModel = $ urlModel ;
245
+ $ this ->countryInformationAcquirerInterface = $ countryInformationAcquirerInterface ;
246
+ $ this ->regionFactory = $ regionFactory ;
219
247
$ this ->fileStorageDatabase = $ fileStorageDatabase ?:
220
248
\Magento \Framework \App \ObjectManager::getInstance ()->get (Database::class);
221
249
parent ::__construct ($ context , $ registry , null , null , $ data );
@@ -512,6 +540,12 @@ protected function addEmailVariables($variables, $storeId)
512
540
$ store
513
541
);
514
542
}
543
+ if (!isset ($ variables ['store_country ' ])) {
544
+ $ variables ['store_country ' ] = $ this ->getCountryName ($ store );
545
+ }
546
+ if (!isset ($ variables ['store_region ' ])) {
547
+ $ variables ['store_region ' ] = $ this ->getRegionName ($ store );
548
+ }
515
549
// If template is text mode, don't include styles
516
550
if (!$ this ->isPlain () && !isset ($ variables ['template_styles ' ])) {
517
551
$ variables ['template_styles ' ] = $ this ->getTemplateStyles ();
@@ -773,4 +807,46 @@ public function getUrl(Store $store, $route = '', $params = [])
773
807
}
774
808
return $ url ->getUrl ($ route , $ params );
775
809
}
810
+
811
+ /**
812
+ * Get country name for the specified store.
813
+ *
814
+ * @param Store $store
815
+ * @return string
816
+ */
817
+ protected function getCountryName ($ store )
818
+ {
819
+ $ countryName = '' ;
820
+ $ store = $ this ->storeManager ->getStore ($ store );
821
+ $ countryId = $ this ->scopeConfig ->getValue (
822
+ self ::XML_PATH_GENERAL_STORE_INFORMATION_COUNTRY_ID ,
823
+ ScopeInterface::SCOPE_STORE ,
824
+ $ store
825
+ );
826
+ if ($ countryId ) {
827
+ $ countryName = $ this ->countryInformationAcquirerInterface ->getCountryInfo ($ countryId )->getFullNameLocale ();
828
+ }
829
+ return $ countryName ;
830
+ }
831
+
832
+ /**
833
+ * Get region name for the specified store.
834
+ *
835
+ * @param Store $store
836
+ * @return string
837
+ */
838
+ protected function getRegionName ($ store )
839
+ {
840
+ $ regionName = '' ;
841
+ $ store = $ this ->storeManager ->getStore ($ store );
842
+ $ regionId = $ this ->scopeConfig ->getValue (
843
+ self ::XML_PATH_GENERAL_STORE_INFORMATION_REGION_ID ,
844
+ ScopeInterface::SCOPE_STORE ,
845
+ $ store
846
+ );
847
+ if ($ regionId ) {
848
+ $ regionName = $ this ->regionFactory ->create ()->load ($ regionId )->getName ();
849
+ }
850
+ return $ regionName ;
851
+ }
776
852
}
0 commit comments