Skip to content

Commit bbe1184

Browse files
authored
Better admin/config validation for allowed currencies (OpenMage#2597)
1 parent c27098e commit bbe1184

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Currency/Default.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,17 @@ class Mage_Adminhtml_Model_System_Config_Backend_Currency_Default extends Mage_A
3737
*/
3838
protected function _afterSave()
3939
{
40+
$allowedCurrencies = $this->_getAllowedCurrencies();
41+
42+
if (!is_array($allowedCurrencies)) {
43+
Mage::throwException(Mage::helper('adminhtml')->__('At least one currency has to be allowed.'));
44+
}
45+
4046
if (!in_array($this->getValue(), $this->_getInstalledCurrencies())) {
4147
Mage::throwException(Mage::helper('adminhtml')->__('Selected default display currency is not available in installed currencies.'));
4248
}
4349

44-
if (!in_array($this->getValue(), $this->_getAllowedCurrencies())) {
50+
if (!in_array($this->getValue(), $allowedCurrencies)) {
4551
Mage::throwException(Mage::helper('adminhtml')->__('Selected default display currency is not available in allowed currencies.'));
4652
}
4753

app/code/core/Mage/Directory/etc/system.xml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
<show_in_default>1</show_in_default>
6868
<show_in_website>1</show_in_website>
6969
<show_in_store>1</show_in_store>
70-
<can_be_empty>1</can_be_empty>
70+
<validate>required-entry</validate>
7171
</allow>
7272
</fields>
7373
</options>
@@ -93,6 +93,9 @@
9393
<show_in_default>1</show_in_default>
9494
<show_in_website>0</show_in_website>
9595
<show_in_store>0</show_in_store>
96+
<depends>
97+
<active>1</active>
98+
</depends>
9699
</timeout>
97100
<api_key translate="label">
98101
<label>API Key</label>
@@ -102,6 +105,9 @@
102105
<show_in_default>1</show_in_default>
103106
<show_in_website>0</show_in_website>
104107
<show_in_store>0</show_in_store>
108+
<depends>
109+
<active>1</active>
110+
</depends>
105111
</api_key>
106112
</fields>
107113
</currencyconverterapi>
@@ -127,6 +133,9 @@
127133
<show_in_default>1</show_in_default>
128134
<show_in_website>0</show_in_website>
129135
<show_in_store>0</show_in_store>
136+
<depends>
137+
<active>1</active>
138+
</depends>
130139
</timeout>
131140
<api_key translate="label">
132141
<label>API Access Key</label>
@@ -136,6 +145,9 @@
136145
<show_in_default>1</show_in_default>
137146
<show_in_website>0</show_in_website>
138147
<show_in_store>0</show_in_store>
148+
<depends>
149+
<active>1</active>
150+
</depends>
139151
</api_key>
140152
</fields>
141153
</fixerio>
@@ -162,6 +174,9 @@
162174
<show_in_default>1</show_in_default>
163175
<show_in_website>1</show_in_website>
164176
<show_in_store>1</show_in_store>
177+
<depends>
178+
<enabled>1</enabled>
179+
</depends>
165180
</error_email>
166181
<error_email_identity translate="label">
167182
<label>Error Email Sender</label>
@@ -171,6 +186,9 @@
171186
<show_in_default>1</show_in_default>
172187
<show_in_website>1</show_in_website>
173188
<show_in_store>0</show_in_store>
189+
<depends>
190+
<enabled>1</enabled>
191+
</depends>
174192
</error_email_identity>
175193
<error_email_template translate="label">
176194
<label>Error Email Template</label>
@@ -180,6 +198,9 @@
180198
<show_in_default>1</show_in_default>
181199
<show_in_website>1</show_in_website>
182200
<show_in_store>0</show_in_store>
201+
<depends>
202+
<enabled>1</enabled>
203+
</depends>
183204
</error_email_template>
184205
<frequency translate="label">
185206
<label>Frequency</label>
@@ -189,6 +210,9 @@
189210
<show_in_default>1</show_in_default>
190211
<show_in_website>1</show_in_website>
191212
<show_in_store>1</show_in_store>
213+
<depends>
214+
<enabled>1</enabled>
215+
</depends>
192216
</frequency>
193217
<service translate="label">
194218
<label>Service</label>
@@ -199,6 +223,9 @@
199223
<show_in_default>1</show_in_default>
200224
<show_in_website>1</show_in_website>
201225
<show_in_store>1</show_in_store>
226+
<depends>
227+
<enabled>1</enabled>
228+
</depends>
202229
</service>
203230
<time translate="label">
204231
<label>Start Time</label>
@@ -207,6 +234,9 @@
207234
<show_in_default>1</show_in_default>
208235
<show_in_website>1</show_in_website>
209236
<show_in_store>1</show_in_store>
237+
<depends>
238+
<enabled>1</enabled>
239+
</depends>
210240
</time>
211241
</fields>
212242
</import>

app/locale/en_US/Mage_Adminhtml.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,3 +1288,4 @@
12881288
"website(%s) scope","website(%s) scope"
12891289
"{{base_url}} is not recommended to use in a production environment to declare the Base Unsecure URL / Base Secure URL. It is highly recommended to change this value in your Magento <a href=""%s"">configuration</a>.","{{base_url}} is not recommended to use in a production environment to declare the Base Unsecure URL / Base Secure URL. It is highly recommended to change this value in your Magento <a href=""%s"">configuration</a>."
12901290
"Powered by OpenMage","Powered by OpenMage"
1291+
"At least one currency has to be allowed.","At least one currency has to be allowed."

0 commit comments

Comments
 (0)