Recently, very often the situation is that when you try to enter the admin panel of the online store on the opencart page freezes and then issues a variety of errors, for example, you may receive a 500 or 504 error, that is, the timeout has worked and the connection has been reset.
What is the reason for the error in logging in to the admin panel of Opencart?
It's simple, if you have several types of currencies in the store, then you want the exchange rate to be updated automatically, there is a special function that updates the exchange rate from the Yahoo service at every login to the store admin area. You can either enable automatic updating or turn it off.
If you have automatic updating of currencies in opencart is turned on then your store tries to update the exchange rate when entering the admin panel and refers to the above service, which just causes this error.
If you do not need to automatically update the exchange rate, you change the exchange rate yourself, the simplest solution is to turn off currency updates in the admin panel of opencart. But since you can not enter the admin panel to disable it, just go to any other section, and after you go to the settings and turn off the update, for example, you can go to the category page like this:
1 |
http://vach-domen.ru/admin/index.php?route=catalog/category&token=9dd715885c7c3d38fac8e4ada1bf4039 |
Since the example specifies a completely different token, you will be asked to authorize again, after authorization, you will immediately go to the category section, after you go to the settings and in the localization section turn off the Automatic currency update, the page will probably hang again, but you will not be affected by the settings you can already log in as usual.
But what if automatic currency updates are important to you?
In this case, there are several options for fixing this situation, and now we will look at each of the methods how to fix the error in entering the admin panel in opencart.
1. And so, we will consider the first variant of the decision of problems with an input in the admin panel:
Our task is to make changes to the file /admin/model/localisation/currency.php, we need to add return to the call request. (PS: return returns the result of the function's operation to the place where it was called.)
And so we opened the above file and find in it about 104 lines:
1 |
public function updateCurrencies($force = false) { |
and immediately under this line we insert:
1 |
return; |
That is, we completely disable automatic currency updates. (For those to whom the automatic update still needs this method is not suitable).
Please note - that in some versions the code may differ slightly, for example the above function updateCurrencies can be without $force = false, but it's not important and return is still inserted under this function.
2. Now let's look at the second option for solving the problems of entering the admin panel of the store.
In this example, we specify the time when, in the case of a freeze, the update from Yahoo breaks and skips the update attempt and immediately proceeds to the administrative panel of the store. For this method, open the same file /admin/model/localisation/currency.php and in it we find the line:
1 |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); |
And immediately after it we insert:
1 2 |
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 4); //We are waiting for 4 seconds, after we go to the admin area curl_setopt($curl, CURLOPT_TIMEOUT,4); |
3. Well, the most recent third option will not be editing and adjusting for the Yahoo service, but completely changing the automatic updating of the opencart exchange rates from Yahoo to the CBRF. That is now Opencart will be updated from the courses of the Central Bank of Russia.
This method was kindly provided by one of the users of the Russian-language forum Opencart.
And so, in order to update the currency exchange rates with the CBRF in opencart, you will need all the same /admin/model/localisation/currency.php, only we will not change some parts of the code in it but delete everything completely and replace it with it all the contents of the code below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
<?php class ModelLocalisationCurrency extends Model { public function addCurrency($data) { $this->db->query("INSERT INTO " . DB_PREFIX . "currency SET title = '" . $this->db->escape($data['title']) . "', code = '" . $this->db->escape($data['code']) . "', symbol_left = '" . $this->db->escape($data['symbol_left']) . "', symbol_right = '" . $this->db->escape($data['symbol_right']) . "', decimal_place = '" . $this->db->escape($data['decimal_place']) . "', value = '" . $this->db->escape($data['value']) . "', status = '" . (int)$data['status'] . "', date_modified = NOW()"); $this->cache->delete('currency'); } public function editCurrency($currency_id, $data) { $this->db->query("UPDATE " . DB_PREFIX . "currency SET title = '" . $this->db->escape($data['title']) . "', code = '" . $this->db->escape($data['code']) . "', symbol_left = '" . $this->db->escape($data['symbol_left']) . "', symbol_right = '" . $this->db->escape($data['symbol_right']) . "', decimal_place = '" . $this->db->escape($data['decimal_place']) . "', value = '" . $this->db->escape($data['value']) . "', status = '" . (int)$data['status'] . "', date_modified = NOW() WHERE currency_id = '" . (int)$currency_id . "'"); $this->cache->delete('currency'); } public function deleteCurrency($currency_id) { $this->db->query("DELETE FROM " . DB_PREFIX . "currency WHERE currency_id = '" . (int)$currency_id . "'"); $this->cache->delete('currency'); } public function getCurrency($currency_id) { $query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "currency WHERE currency_id = '" . (int)$currency_id . "'"); return $query->row; } public function getCurrencyByCode($currency) { $query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "currency WHERE code = '" . $this->db->escape($currency) . "'"); return $query->row; } public function getCurrencies($data = array()) { if ($data) { $sql = "SELECT * FROM " . DB_PREFIX . "currency"; $sort_data = array( 'title', 'code', 'value', 'date_modified' ); if (isset($data['sort']) && in_array($data['sort'], $sort_data)) { $sql .= " ORDER BY " . $data['sort']; } else { $sql .= " ORDER BY title"; } if (isset($data['order']) && ($data['order'] == 'DESC')) { $sql .= " DESC"; } else { $sql .= " ASC"; } if (isset($data['start']) || isset($data['limit'])) { if ($data['start'] < 0) { $data['start'] = 0; } if ($data['limit'] < 1) { $data['limit'] = 20; } $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit']; } $query = $this->db->query($sql); return $query->rows; } else { $currency_data = $this->cache->get('currency'); if (!$currency_data) { $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "currency ORDER BY title ASC"); foreach ($query->rows as $result) { $currency_data[$result['code']] = array( 'currency_id' => $result['currency_id'], 'title' => $result['title'], 'code' => $result['code'], 'symbol_left' => $result['symbol_left'], 'symbol_right' => $result['symbol_right'], 'decimal_place' => $result['decimal_place'], 'value' => $result['value'], 'status' => $result['status'], 'date_modified' => $result['date_modified'] ); } $this->cache->set('currency', $currency_data); } return $currency_data; } } public function updateCurrencies() { $query = $this->db->query("SELECT date_modified FROM " . DB_PREFIX . "currency WHERE code != '" . $this->db->escape($this->config->get('config_currency')) . "'"); $cc_value = $this->db->query("SELECT value FROM " . DB_PREFIX . "currency WHERE code = '" . $this->db->escape($this->config->get('config_currency')) . "'"); $i = 0; foreach ($query->rows as $mdate) { if($this->db->escape(date('Y-m-d',strtotime($mdate['date_modified']))) < $this->db->escape(date('Y-m-d', strtotime('now')))) $i++; } $manual_update = isset($this->request->post['manual_update']) ? $this->request->post['manual_update'] : false; if ($i || $cc_value->row['value'] != 1.00000 || $manual_update) { $url = 'http://www.cbr.ru/scripts/XML_daily.asp'; $answer = $this->CheckHttpStatus($url); $this->log->write('ΠΠ±Π½ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ Π²Π°Π»ΡΡ: '); if ($answer != 200) { $this->log->write(" > Π½Π΅ ΡΠ΄Π°Π»ΠΎΡΡ Π·Π°Π³ΡΡΠ·ΠΈΡΡ ΠΊΡΡΡΡ Π²Π°Π»ΡΡ, ΠΎΡΠ²Π΅Ρ ΡΠ΅ΡΠ²Π΅ΡΠ°:" . $answer); } else { if (extension_loaded('curl')) { $data = array(); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://www.cbr.ru/scripts/XML_daily.asp'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $content = curl_exec($ch); curl_close($ch); $doc = new DOMDocument(); $doc->loadXML($content); $root = $doc->documentElement; $curs_date = $root->getAttribute('Date'); $this->log->write(" > ΡΡΠΏΠ΅ΡΠ½ΠΎ Π·Π°Π³ΡΡΠΆΠ΅Π½Ρ ΠΊΡΡΡΡ Π²Π°Π»ΡΡ Π½Π°: ". $curs_date); $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "currency WHERE code != '" . $this->db->escape($this->config->get('config_currency')) . "'"); $valutes = $doc->getElementsByTagName("Valute"); $ret = array(); foreach( $valutes as $valute ) { $icn = $valute->childNodes; $code = $icn->item(1)->nodeValue; $nom = intval($icn->item(2)->nodeValue); $value = floatval(str_replace(",", "." , $icn->item(4)->nodeValue)); $ret[$code] = ($value/$nom); } $cur_val = $this->config->get('config_currency'); if ($cur_val == 'RUB') { foreach ($query->rows as $result) { if($ret[$result['code']]){ $value = 1 / $ret[$result['code']]; if ((float)$value) { $this->db->query("UPDATE " . DB_PREFIX . "currency SET value = '" . (float)$value . "', date_modified = NOW() WHERE code = '" . $this->db->escape($result['code']) . "'"); } } } } else { foreach ($query->rows as $result) { if($result['code'] == 'RUB') { $value = $ret[$cur_val]; if ((float)$value) { $this->db->query("UPDATE " . DB_PREFIX . "currency SET value = '" . (float)$value . "', date_modified = NOW() WHERE code = 'RUB'"); } } else { $value = $ret[$result['code']]; if ((float)$value) { $val = (float)$ret[$cur_val] / (float)$value; $this->db->query("UPDATE " . DB_PREFIX . "currency SET value = '" . $val . "', date_modified = NOW() WHERE code = '" . $this->db->escape($result['code']) . "'"); } } } } $this->db->query("UPDATE " . DB_PREFIX . "currency SET value = '1.00000', date_modified = NOW() WHERE code = '" . $this->db->escape($this->config->get('config_currency')) . "'"); $this->cache->delete('currency'); } } } } public function CheckHttpStatus($url) { $user_agent = 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT, $user_agent); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_VERBOSE, false); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSLVERSION, 3); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); $page = curl_exec($ch); $err = curl_error($ch); if (!empty($err)) return $err; $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); return $httpcode; } public function getTotalCurrencies() { $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "currency"); return $query->row['total']; } } ?> |
Now every time you enter the administrative panel of the store, the site will update the exchange rate from the XML file that is generated by the central bank of Russia.
PS: Note, to use this method, you must have PHP modules such as curl and simplexml on your hosting.
Well, that's all, now you know how to overcome the error in entering the admin panel associated with updating the exchange rate. Good luck to you.
No Comment
You can post first response comment.