1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Adminhtml
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27:
28: /**
29: * Config locale allowed currencies backend
30: *
31: * @category Mage
32: * @package Mage_Adminhtml
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: class Mage_Adminhtml_Model_System_Config_Backend_Locale extends Mage_Core_Model_Config_Data
36: {
37:
38: /**
39: * Enter description here...
40: *
41: * @return Mage_Adminhtml_Model_System_Config_Backend_Locale
42: */
43: protected function _afterSave()
44: {
45: $collection = Mage::getModel('core/config_data')
46: ->getCollection()
47: ->addPathFilter('currency/options');
48:
49: $values = explode(',', $this->getValue());
50: $exceptions = array();
51:
52: foreach ($collection as $data) {
53: $match = false;
54: $scopeName = Mage::helper('adminhtml')->__('Default scope');
55:
56: if (preg_match('/(base|default)$/', $data->getPath(), $match)) {
57: if (!in_array($data->getValue(), $values)) {
58: $currencyName = Mage::app()->getLocale()->currency($data->getValue())->getName();
59: if ($match[1] == 'base') {
60: $fieldName = Mage::helper('adminhtml')->__('Base currency');
61: }
62: else {
63: $fieldName = Mage::helper('adminhtml')->__('Display default currency');
64: }
65:
66: switch ($data->getScope()) {
67: case 'default':
68: $scopeName = Mage::helper('adminhtml')->__('Default scope');
69: break;
70:
71: case 'website':
72: $websiteName = Mage::getModel('core/website')->load($data->getScopeId())->getName();
73: $scopeName = Mage::helper('adminhtml')->__('website(%s) scope', $websiteName);
74: break;
75:
76: case 'store':
77: $storeName = Mage::getModel('core/store')->load($data->getScopeId())->getName();
78: $scopeName = Mage::helper('adminhtml')->__('store(%s) scope', $storeName);
79: break;
80: }
81:
82: $exceptions[] = Mage::helper('adminhtml')->__('Currency "%s" is used as %s in %s.', $currencyName, $fieldName, $scopeName);
83: }
84: }
85: }
86: if ($exceptions) {
87: Mage::throwException(join("\n", $exceptions));
88: }
89:
90: return $this;
91: }
92:
93: }
94: