/app/code/core/Mage/Adminhtml/Block/System/Currency/Rate/Matrix.php
https://bitbucket.org/jokusafet/magento2 · PHP · 97 lines · 54 code · 12 blank · 31 comment · 5 complexity · ea59124543f79ffa56de391919acaaf7 MD5 · raw file
- <?php
- /**
- * Magento
- *
- * NOTICE OF LICENSE
- *
- * This source file is subject to the Open Software License (OSL 3.0)
- * that is bundled with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://opensource.org/licenses/osl-3.0.php
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@magentocommerce.com so we can send you a copy immediately.
- *
- * DISCLAIMER
- *
- * Do not edit or add to this file if you wish to upgrade Magento to newer
- * versions in the future. If you wish to customize Magento for your
- * needs please refer to http://www.magentocommerce.com for more information.
- *
- * @category Mage
- * @package Mage_Adminhtml
- * @copyright Copyright (c) 2012 X.commerce, Inc. (http://www.magentocommerce.com)
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
- */
- /**
- * Manage currency block
- *
- * @category Mage
- * @package Mage_Adminhtml
- * @author Magento Core Team <core@magentocommerce.com>
- */
- class Mage_Adminhtml_Block_System_Currency_Rate_Matrix extends Mage_Adminhtml_Block_Template
- {
- protected $_template = 'system/currency/rate/matrix.phtml';
- protected function _prepareLayout()
- {
- $newRates = Mage::getSingleton('Mage_Adminhtml_Model_Session')->getRates();
- Mage::getSingleton('Mage_Adminhtml_Model_Session')->unsetData('rates');
- $currencyModel = Mage::getModel('Mage_Directory_Model_Currency');
- $currencies = $currencyModel->getConfigAllowCurrencies();
- $defaultCurrencies = $currencyModel->getConfigBaseCurrencies();
- $oldCurrencies = $this->_prepareRates($currencyModel->getCurrencyRates($defaultCurrencies, $currencies));
- foreach( $currencies as $currency ) {
- foreach( $oldCurrencies as $key => $value ) {
- if( !array_key_exists($currency, $oldCurrencies[$key]) ) {
- $oldCurrencies[$key][$currency] = '';
- }
- }
- }
- foreach( $oldCurrencies as $key => $value ) {
- ksort($oldCurrencies[$key]);
- }
- sort($currencies);
- $this->setAllowedCurrencies($currencies)
- ->setDefaultCurrencies($defaultCurrencies)
- ->setOldRates($oldCurrencies)
- ->setNewRates($this->_prepareRates($newRates));
- return parent::_prepareLayout();
- }
- protected function getRatesFormAction()
- {
- return $this->getUrl('*/*/saveRates');
- }
- protected function _prepareRates($array)
- {
- if( !is_array($array) ) {
- return $array;
- }
- foreach ($array as $key => $rate) {
- foreach ($rate as $code => $value) {
- $parts = explode('.', $value);
- if( sizeof($parts) == 2 ) {
- $parts[1] = str_pad(rtrim($parts[1], 0), 4, '0', STR_PAD_RIGHT);
- $array[$key][$code] = join('.', $parts);
- } elseif( $value > 0 ) {
- $array[$key][$code] = number_format($value, 4);
- } else {
- $array[$key][$code] = null;
- }
- }
- }
- return $array;
- }
- }