|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* |
|
5
|
|
|
* |
|
6
|
|
|
* @category Mygento |
|
7
|
|
|
* @package Mygento_Geoip |
|
8
|
|
|
* @copyright 2014 NKS LLC. (https://www.mygento.ru) |
|
9
|
|
|
*/ |
|
10
|
|
|
class Mygento_Geoip_Helper_Data extends Mage_Core_Helper_Abstract |
|
11
|
|
|
{ |
|
12
|
|
|
|
|
13
|
|
|
public function getSize($file) |
|
14
|
|
|
{ |
|
15
|
|
|
$ch = curl_init(); |
|
16
|
|
|
curl_setopt($ch, CURLOPT_URL, $file); |
|
17
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
18
|
|
|
curl_setopt($ch, CURLOPT_HEADER, true); |
|
19
|
|
|
curl_setopt($ch, CURLOPT_NOBODY, true); |
|
20
|
|
|
curl_exec($ch); |
|
21
|
|
|
return curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function unGZip($archive, $destination) |
|
25
|
|
|
{ |
|
26
|
|
|
$zip = new ZipArchive; |
|
27
|
|
|
if ($zip->open($archive) === true) { |
|
28
|
|
|
$zip->extractTo($destination . DS); |
|
29
|
|
|
$zip->close(); |
|
30
|
|
|
return true; |
|
31
|
|
|
} |
|
32
|
|
|
return false; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function init() |
|
36
|
|
|
{ |
|
37
|
|
|
if (!Mage::getSingleton('core/session')->getGeoCity()) { |
|
38
|
|
|
$geoIP = Mage::getSingleton('geoip/city'); |
|
39
|
|
|
Mage::getSingleton('core/session')->setGeoCity($geoIP->getCity()); |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function setCity($city) |
|
44
|
|
|
{ |
|
45
|
|
|
Mage::getSingleton('core/session')->setGeoCity($city); |
|
46
|
|
|
$this->_getQuote()->getShippingAddress()->setCity($city); |
|
47
|
|
|
$this->_getQuote()->save(); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function _getQuote() |
|
51
|
|
|
{ |
|
52
|
|
|
return Mage::getModel('checkout/cart')->getQuote(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function getCurrentCity() |
|
56
|
|
|
{ |
|
57
|
|
|
$value = Mage::getSingleton('core/session')->getGeoCity(); |
|
58
|
|
|
if (!$value) { |
|
59
|
|
|
$this->init(); |
|
60
|
|
|
} |
|
61
|
|
|
return Mage::getSingleton('core/session')->getGeoCity(); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|