Mygento_Geoip_Helper_Data   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 0
dl 0
loc 54
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getSize() 0 10 1
A unGZip() 0 10 2
A init() 0 7 2
A setCity() 0 6 1
A _getQuote() 0 4 1
A getCurrentCity() 0 8 2
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