4
4
* See COPYING.txt for license details.
5
5
*/
6
6
7
- /**
8
- * Directory module observer
9
- *
10
- * @author Magento Core Team <core@magentocommerce.com>
11
- */
12
-
13
7
namespace Magento \Directory \Model ;
14
8
9
+ use Magento \Backend \App \Area \FrontNameResolver ;
10
+ use Magento \Directory \Model \Currency \Import \Factory ;
11
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
12
+ use Magento \Framework \Mail \Template \TransportBuilder ;
13
+ use Magento \Framework \Translate \Inline \StateInterface ;
14
+ use Magento \Store \Model \ScopeInterface ;
15
+ use Magento \Store \Model \Store ;
16
+ use Magento \Store \Model \StoreManagerInterface ;
17
+
15
18
/**
16
- * Class Observer
17
- *
18
- * @package Magento\Directory\Model
19
+ * Import currency rates
19
20
*/
20
21
class Observer
21
22
{
22
- const CRON_STRING_PATH = 'crontab/default/jobs/currency_rates_update/schedule/cron_expr ' ;
23
+ public const CRON_STRING_PATH = 'crontab/default/jobs/currency_rates_update/schedule/cron_expr ' ;
23
24
24
- const IMPORT_ENABLE = 'currency/import/enabled ' ;
25
+ public const IMPORT_ENABLE = 'currency/import/enabled ' ;
25
26
26
- const IMPORT_SERVICE = 'currency/import/service ' ;
27
+ public const IMPORT_SERVICE = 'currency/import/service ' ;
27
28
28
- const XML_PATH_ERROR_TEMPLATE = 'currency/import/error_email_template ' ;
29
+ public const XML_PATH_ERROR_TEMPLATE = 'currency/import/error_email_template ' ;
29
30
30
- const XML_PATH_ERROR_IDENTITY = 'currency/import/error_email_identity ' ;
31
+ public const XML_PATH_ERROR_IDENTITY = 'currency/import/error_email_identity ' ;
31
32
32
- const XML_PATH_ERROR_RECIPIENT = 'currency/import/error_email ' ;
33
+ public const XML_PATH_ERROR_RECIPIENT = 'currency/import/error_email ' ;
33
34
34
35
/**
35
- * @var \Magento\Directory\Model\Currency\Import\ Factory
36
+ * @var Factory
36
37
*/
37
38
protected $ _importFactory ;
38
39
39
40
/**
40
41
* Core store config
41
42
*
42
- * @var \Magento\Framework\App\Config\ ScopeConfigInterface
43
+ * @var ScopeConfigInterface
43
44
*/
44
45
protected $ _scopeConfig ;
45
46
46
47
/**
47
- * @var \Magento\Framework\Mail\Template\ TransportBuilder
48
+ * @var TransportBuilder
48
49
*/
49
50
protected $ _transportBuilder ;
50
51
51
52
/**
52
- * @var \Magento\Store\Model\ StoreManagerInterface
53
+ * @var StoreManagerInterface
53
54
*/
54
55
protected $ _storeManager ;
55
56
56
57
/**
57
- * @var \Magento\Directory\Model\ CurrencyFactory
58
+ * @var CurrencyFactory
58
59
*/
59
60
protected $ _currencyFactory ;
60
61
61
62
/**
62
- * @var \Magento\Framework\Translate\Inline\ StateInterface
63
+ * @var StateInterface
63
64
*/
64
65
protected $ inlineTranslation ;
65
66
66
67
/**
67
- * @param \Magento\Directory\Model\Currency\Import\ Factory $importFactory
68
- * @param \Magento\Framework\App\Config\ ScopeConfigInterface $scopeConfig
69
- * @param \Magento\Framework\Mail\Template\ TransportBuilder $transportBuilder
70
- * @param \Magento\Store\Model\ StoreManagerInterface $storeManager
71
- * @param \Magento\Directory\Model\ CurrencyFactory $currencyFactory
72
- * @param \Magento\Framework\Translate\Inline\ StateInterface $inlineTranslation
68
+ * @param Factory $importFactory
69
+ * @param ScopeConfigInterface $scopeConfig
70
+ * @param TransportBuilder $transportBuilder
71
+ * @param StoreManagerInterface $storeManager
72
+ * @param CurrencyFactory $currencyFactory
73
+ * @param StateInterface $inlineTranslation
73
74
*/
74
75
public function __construct (
75
- \ Magento \ Directory \ Model \ Currency \ Import \ Factory $ importFactory ,
76
- \ Magento \ Framework \ App \ Config \ ScopeConfigInterface $ scopeConfig ,
77
- \ Magento \ Framework \ Mail \ Template \ TransportBuilder $ transportBuilder ,
78
- \ Magento \ Store \ Model \ StoreManagerInterface $ storeManager ,
79
- \ Magento \ Directory \ Model \ CurrencyFactory $ currencyFactory ,
80
- \ Magento \ Framework \ Translate \ Inline \ StateInterface $ inlineTranslation
76
+ Factory $ importFactory ,
77
+ ScopeConfigInterface $ scopeConfig ,
78
+ TransportBuilder $ transportBuilder ,
79
+ StoreManagerInterface $ storeManager ,
80
+ CurrencyFactory $ currencyFactory ,
81
+ StateInterface $ inlineTranslation
81
82
) {
82
83
$ this ->_importFactory = $ importFactory ;
83
84
$ this ->_scopeConfig = $ scopeConfig ;
@@ -94,16 +95,17 @@ public function __construct(
94
95
* @return void
95
96
* @throws \Exception
96
97
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
98
+ * @SuppressWarnings(PHPMD.CyclomaticComplexity)
97
99
*/
98
100
public function scheduledUpdateCurrencyRates ($ schedule )
99
101
{
100
102
$ importWarnings = [];
101
103
if (!$ this ->_scopeConfig ->getValue (
102
104
self ::IMPORT_ENABLE ,
103
- \ Magento \ Store \ Model \ ScopeInterface::SCOPE_STORE
105
+ ScopeInterface::SCOPE_STORE
104
106
) || !$ this ->_scopeConfig ->getValue (
105
107
self ::CRON_STRING_PATH ,
106
- \ Magento \ Store \ Model \ ScopeInterface::SCOPE_STORE
108
+ ScopeInterface::SCOPE_STORE
107
109
)
108
110
) {
109
111
return ;
@@ -113,7 +115,7 @@ public function scheduledUpdateCurrencyRates($schedule)
113
115
$ rates = [];
114
116
$ service = $ this ->_scopeConfig ->getValue (
115
117
self ::IMPORT_SERVICE ,
116
- \ Magento \ Store \ Model \ ScopeInterface::SCOPE_STORE
118
+ ScopeInterface::SCOPE_STORE
117
119
);
118
120
if ($ service ) {
119
121
try {
@@ -137,32 +139,33 @@ public function scheduledUpdateCurrencyRates($schedule)
137
139
138
140
$ errorRecipient = $ this ->_scopeConfig ->getValue (
139
141
self ::XML_PATH_ERROR_RECIPIENT ,
140
- \ Magento \ Store \ Model \ ScopeInterface::SCOPE_STORE
142
+ ScopeInterface::SCOPE_STORE
141
143
);
144
+ $ errorRecipients = !empty ($ errorRecipient ) ? explode (', ' , $ errorRecipient ) : [];
142
145
if (count ($ importWarnings ) == 0 ) {
143
146
$ this ->_currencyFactory ->create ()->saveRates ($ rates );
144
- } elseif ($ errorRecipient ) {
147
+ } elseif (count ( $ errorRecipients ) > 0 ) {
145
148
//if $errorRecipient is not set, there is no sense send email to nobody
146
149
$ this ->inlineTranslation ->suspend ();
147
150
148
151
$ this ->_transportBuilder ->setTemplateIdentifier (
149
152
$ this ->_scopeConfig ->getValue (
150
153
self ::XML_PATH_ERROR_TEMPLATE ,
151
- \ Magento \ Store \ Model \ ScopeInterface::SCOPE_STORE
154
+ ScopeInterface::SCOPE_STORE
152
155
)
153
156
)->setTemplateOptions (
154
157
[
155
- 'area ' => \ Magento \ Backend \ App \ Area \ FrontNameResolver::AREA_CODE ,
156
- 'store ' => \ Magento \ Store \ Model \ Store::DEFAULT_STORE_ID ,
158
+ 'area ' => FrontNameResolver::AREA_CODE ,
159
+ 'store ' => Store::DEFAULT_STORE_ID ,
157
160
]
158
161
)->setTemplateVars (
159
162
['warnings ' => join ("\n" , $ importWarnings )]
160
163
)->setFrom (
161
164
$ this ->_scopeConfig ->getValue (
162
165
self ::XML_PATH_ERROR_IDENTITY ,
163
- \ Magento \ Store \ Model \ ScopeInterface::SCOPE_STORE
166
+ ScopeInterface::SCOPE_STORE
164
167
)
165
- )->addTo ($ errorRecipient );
168
+ )->addTo ($ errorRecipients );
166
169
$ transport = $ this ->_transportBuilder ->getTransport ();
167
170
$ transport ->sendMessage ();
168
171
0 commit comments