Databunch_Ems - Version 0.1.0

Version Notes

First release

Download this release

Release Info

Developer DataBunchRussia
Extension Databunch_Ems
Version 0.1.0
Comparing to
See all releases


Version 0.1.0

app/code/community/Databunch/Ems/.DS_Store ADDED
Binary file
app/code/community/Databunch/Ems/Helper/Data.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ class Databunch_Ems_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {}
app/code/community/Databunch/Ems/Model/.DS_Store ADDED
Binary file
app/code/community/Databunch/Ems/Model/Api/Ru.php ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Databunch_Ems_Model_Api_Ru
3
+ {
4
+ /** @var string */
5
+ protected $_apiUri;
6
+ /** @var Zend_Http_Client */
7
+ protected $_httpClient;
8
+
9
+ const REST_METHOD_GET_SERVICE_STATUS = 'ems.test.echo';
10
+ const REST_METHOD_GET_LOCATIONS = 'ems.get.locations';
11
+ const REST_METHOD_GET_MAX_WEIGHT = 'ems.get.max.weight';
12
+ const REST_METHOD_CALCULATE = 'ems.calculate';
13
+
14
+ /**
15
+ * @param null|string $uri
16
+ */
17
+ public function __construct($uri = null)
18
+ {
19
+ if (!empty($uri)) {
20
+ $this->setUri($uri);
21
+ }
22
+ }
23
+
24
+ /**
25
+ * @param string $uri
26
+ * @return $this
27
+ */
28
+ public function setUri($uri)
29
+ {
30
+ if (!Zend_Uri::factory($uri)) {
31
+ Mage::throwException('Invalid API uri.');
32
+ }
33
+ $this->_apiUri = $uri;
34
+
35
+ return $this;
36
+ }
37
+
38
+ /**
39
+ * @return Zend_Http_Client
40
+ */
41
+ protected function _getClient()
42
+ {
43
+ if (is_null($this->_httpClient)) {
44
+ if (!$this->_apiUri) {
45
+ Mage::throwException('Please specify API uri.');
46
+ }
47
+ $this->_httpClient = new Zend_Http_Client($this->_apiUri);
48
+ }
49
+
50
+ return $this->_httpClient->resetParameters(true);
51
+ }
52
+
53
+ /**
54
+ * @param array $parameters
55
+ * @param string $method
56
+ * @return bool|array
57
+ */
58
+ public function makeRequest($parameters, $method = Zend_Http_Client::GET)
59
+ {
60
+ try {
61
+ $client = $this->_getClient();
62
+
63
+ if (Zend_Http_Client::POST == $method) {
64
+ $client->setParameterPost($parameters);
65
+ } else {
66
+ $client->setParameterGet($parameters);
67
+ }
68
+
69
+ $response = $client->request($method);
70
+
71
+ if (200 == $response->getStatus()) {
72
+ $response = Zend_Json::decode($response->getBody());
73
+ if (is_array($response) && isset($response['rsp'], $response['rsp']['stat'])) {
74
+ if ('ok' == $response['rsp']['stat']) {
75
+ return $response['rsp'];
76
+ } else {
77
+ if (isset($response['rsp']['err']['msg'])) {
78
+ $msg = $response['rsp']['err']['msg'];
79
+ } else {
80
+ $msg = 'Server returned unknown error.';
81
+ }
82
+ Mage::throwException('EMS Post API Error: ' . $msg);
83
+ }
84
+ } else {
85
+ Mage::throwException('EMS Post API Error: Incorrect response from server');
86
+ }
87
+ } else {
88
+ Mage::throwException('EMS Post API Error: Response Status = '.$response->getStatus());
89
+ }
90
+ } catch (Exception $e) {
91
+ Mage::logException($e);
92
+ }
93
+
94
+ return false;
95
+ }
96
+
97
+ /**
98
+ * @return bool
99
+ */
100
+ public function isAvailable()
101
+ {
102
+ $response = $this->makeRequest(array(
103
+ 'method' => self::REST_METHOD_GET_SERVICE_STATUS
104
+ ));
105
+
106
+ if ($response && isset($response['stat'], $response['msg'])) {
107
+ if ('ok' == $response['stat'] && 'successeful' == $response['msg']) {
108
+ return true;
109
+ }
110
+ }
111
+
112
+ return false;
113
+ }
114
+ }
app/code/community/Databunch/Ems/Model/Carrier/.DS_Store ADDED
Binary file
app/code/community/Databunch/Ems/Model/Carrier/Ems/Ru.php ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Databunch_Ems_Model_Carrier_Ems_Ru
3
+ extends Mage_Shipping_Model_Carrier_Abstract
4
+ implements Mage_Shipping_Model_Carrier_Interface
5
+ {
6
+ const CARRIER_CODE = 'ems_ru';
7
+
8
+ /** @var Databunch_Ems_Helper_Data */
9
+ protected $_helper;
10
+ /** @var Databunch_Ems_Model_Api_Ru */
11
+ protected $_api;
12
+
13
+ /**
14
+ * @param array $data
15
+ */
16
+ public function __construct(array $data = array())
17
+ {
18
+ $this->_helper = Mage::helper('ems');
19
+ $this->_code = self::CARRIER_CODE;
20
+ parent::__construct($data);
21
+ }
22
+
23
+ /**
24
+ * @return Databunch_Ems_Model_Api_Ru
25
+ */
26
+ public function getApi()
27
+ {
28
+ if (is_null($this->_api)) {
29
+ $this->_api = Mage::getModel('ems/api_ru');
30
+ $this->_api->setUri(trim(trim($this->getConfigData('api_uri')), '/'));
31
+ }
32
+
33
+ return $this->_api;
34
+ }
35
+
36
+ /**
37
+ * CHeck is carrier enabled and service api available
38
+ *
39
+ * @return bool
40
+ */
41
+ protected function _isCarrierAvailable()
42
+ {
43
+ if ($this->getConfigFlag('active') && 'RU' == Mage::getStoreConfig('shipping/origin/country_id')) {
44
+ return $this->getApi()->isAvailable();
45
+ }
46
+
47
+ return false;
48
+ }
49
+
50
+ /**
51
+ * @param int $regionId
52
+ * @param string $regionCode
53
+ * @return bool|string
54
+ */
55
+ protected function _getEmsLocation($regionId, $regionCode)
56
+ {
57
+ $result = false;
58
+
59
+ /** @var Databunch_Ems_Model_Ems_Region $emsRegion */
60
+ $emsRegion = Mage::getModel('ems/ems_region');
61
+ $emsRegion->load($regionId);
62
+ if ($emsRegion->getId()) {
63
+ $emsRegionCode = $emsRegion->getData('ems_code');
64
+ $emsRegionType = $emsRegion->getData('ems_type');
65
+ if ($emsRegionCode) {
66
+ $result = $emsRegionType . '--' . $emsRegionCode;
67
+ }
68
+ }
69
+
70
+ return $result;
71
+ }
72
+
73
+ /**
74
+ * @param Mage_Shipping_Model_Rate_Request $request
75
+ * @return Mage_Shipping_Model_Rate_Result
76
+ */
77
+ public function collectRates(Mage_Shipping_Model_Rate_Request $request)
78
+ {
79
+ Mage::log(__METHOD__, null, 'OneClickOrder_Exception.log');
80
+ if (!$this->_isCarrierAvailable()) {
81
+ return false;
82
+ }
83
+
84
+ /** @var Mage_Directory_Model_Region $storeRegion */
85
+ $storeRegion = Mage::getModel('directory/region');
86
+ $storeRegion->load(Mage::getStoreConfig('shipping/origin/region_id'));
87
+
88
+ $emsFrom = $this->_getEmsLocation($storeRegion->getId(), $storeRegion->getCode());
89
+ $emsTo = $this->_getEmsLocation($request->getDestRegionId(), $request->getDestRegionCode());
90
+ $packageWeight = $request->getPackageWeight();
91
+
92
+ Mage::log($emsFrom, null, 'EMS.log');
93
+ Mage::log($emsTo, null, 'EMS.log');
94
+
95
+ if (!$emsFrom || !$emsTo) {
96
+ return false;
97
+ }
98
+
99
+
100
+ $emsWeightInfo = $this->getApi()->makeRequest(array(
101
+ 'method' => Databunch_Ems_Model_Api_Ru::REST_METHOD_GET_MAX_WEIGHT,
102
+ 'from' => $emsFrom,
103
+ 'to' => $emsTo,
104
+ ));
105
+
106
+ if ($packageWeight > $emsWeightInfo['max_weight']) {
107
+ return false;
108
+ }
109
+
110
+ /** @var $result Mage_Shipping_Model_Rate_Result */
111
+ $result = Mage::getModel('shipping/rate_result');
112
+
113
+ $emsResponse = $this->getApi()->makeRequest(array(
114
+ 'method' => Databunch_Ems_Model_Api_Ru::REST_METHOD_CALCULATE,
115
+ 'from' => $emsFrom,
116
+ 'to' => $emsTo,
117
+ 'weight' => $packageWeight
118
+ ));
119
+
120
+ /** @var $method Mage_Shipping_Model_Rate_Result_Method */
121
+ $method = Mage::getModel('shipping/rate_result_method');
122
+ $method->addData(array(
123
+ 'carrier' => $this->_code,
124
+ 'carrier_title' => $this->getConfigData('name'),
125
+ 'method' => 'default',
126
+ 'method_title' => Mage::helper('ems')->__(
127
+ 'Delivery %d - %d day(s)',
128
+ $emsResponse['term']['min'],
129
+ $emsResponse['term']['max']
130
+ ),
131
+ 'price' => (float) $emsResponse['price'],
132
+ 'cost' => (float) $emsResponse['price'],
133
+ ));
134
+ $result->append($method);
135
+
136
+ return $result;
137
+ }
138
+
139
+ public function getAllowedMethods()
140
+ {
141
+ return array($this->_code => $this->_helper->__('EMS Post'));
142
+ }
143
+ }
app/code/community/Databunch/Ems/Model/Ems/Region.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Databunch_Ems_Model_Ems_Region extends Mage_Core_Model_Abstract
3
+ {
4
+ protected function _construct()
5
+ {
6
+ $this->_init('ems/ems_region');
7
+ }
8
+ }
app/code/community/Databunch/Ems/Model/Resource/.DS_Store ADDED
Binary file
app/code/community/Databunch/Ems/Model/Resource/Ems/Region.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Databunch_Ems_Model_Resource_Ems_Region extends Mage_Core_Model_Resource_Db_Abstract
3
+ {
4
+ protected function _construct()
5
+ {
6
+ $this->_init('ems/ems_region', 'region_id');
7
+ }
8
+ }
app/code/community/Databunch/Ems/etc/config.xml ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Databunch_Ems>
5
+ <version>0.1.0</version>
6
+ </Databunch_Ems>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <ems>
11
+ <class>Databunch_Ems_Model</class>
12
+ <resourceModel>ems_resource</resourceModel>
13
+ </ems>
14
+ <ems_resource>
15
+ <class>Databunch_Ems_Model_Resource</class>
16
+ <entities>
17
+ <ems_region>
18
+ <table>directory_country_region_ems</table>
19
+ </ems_region>
20
+ </entities>
21
+ </ems_resource>
22
+ </models>
23
+ <blocks>
24
+ <ems>
25
+ <class>Databunch_Ems_Block</class>
26
+ </ems>
27
+ </blocks>
28
+ <helpers>
29
+ <ems>
30
+ <class>Databunch_Ems_Helper</class>
31
+ </ems>
32
+ </helpers>
33
+ <resources>
34
+ <ems_setup>
35
+ <setup>
36
+ <module>Databunch_Ems</module>
37
+ </setup>
38
+ </ems_setup>
39
+ </resources>
40
+ </global>
41
+ <default>
42
+ <carriers>
43
+ <ems_ru>
44
+ <active>0</active>
45
+ <allowspecific>0</allowspecific>
46
+ <model>ems/carrier_ems_ru</model>
47
+ <name>EMS Post of Russia</name>
48
+ <title>EMS Post of Russia</title>
49
+ <api_uri>http://emspost.ru/api/rest</api_uri>
50
+ </ems_ru>
51
+ </carriers>
52
+ </default>
53
+ </config>
app/code/community/Databunch/Ems/etc/system.xml ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <carriers>
5
+ <groups>
6
+ <ems_ru translate="label">
7
+ <label>EMS Post</label>
8
+ <frontend_type>text</frontend_type>
9
+ <sort_order>20</sort_order>
10
+ <show_in_default>1</show_in_default>
11
+ <show_in_website>1</show_in_website>
12
+ <show_in_store>1</show_in_store>
13
+ <fields>
14
+ <active translate="label">
15
+ <label>Enabled</label>
16
+ <frontend_type>select</frontend_type>
17
+ <source_model>adminhtml/system_config_source_yesno</source_model>
18
+ <sort_order>10</sort_order>
19
+ <show_in_default>1</show_in_default>
20
+ <show_in_website>1</show_in_website>
21
+ <show_in_store>0</show_in_store>
22
+ </active>
23
+ <name translate="label">
24
+ <label>Method Name</label>
25
+ <frontend_type>text</frontend_type>
26
+ <sort_order>20</sort_order>
27
+ <show_in_default>1</show_in_default>
28
+ <show_in_website>1</show_in_website>
29
+ <show_in_store>1</show_in_store>
30
+ </name>
31
+ <title translate="label">
32
+ <label>Title</label>
33
+ <frontend_type>text</frontend_type>
34
+ <sort_order>30</sort_order>
35
+ <show_in_default>1</show_in_default>
36
+ <show_in_website>1</show_in_website>
37
+ <show_in_store>1</show_in_store>
38
+ </title>
39
+ <api_uri translate="label">
40
+ <label>API Uri</label>
41
+ <frontend_type>text</frontend_type>
42
+ <sort_order>40</sort_order>
43
+ <show_in_default>1</show_in_default>
44
+ <show_in_website>1</show_in_website>
45
+ <show_in_store>1</show_in_store>
46
+ </api_uri>
47
+ <sort_order translate="label">
48
+ <label>Sort Order</label>
49
+ <frontend_type>text</frontend_type>
50
+ <sort_order>50</sort_order>
51
+ <show_in_default>1</show_in_default>
52
+ <show_in_website>1</show_in_website>
53
+ <show_in_store>0</show_in_store>
54
+ </sort_order>
55
+ <showmethod translate="label">
56
+ <label>Show Method if Not Applicable</label>
57
+ <frontend_type>select</frontend_type>
58
+ <sort_order>80</sort_order>
59
+ <source_model>adminhtml/system_config_source_yesno</source_model>
60
+ <show_in_default>1</show_in_default>
61
+ <show_in_website>1</show_in_website>
62
+ <show_in_store>0</show_in_store>
63
+ </showmethod>
64
+ <specificerrmsg translate="label">
65
+ <label>Displayed Error Message</label>
66
+ <frontend_type>textarea</frontend_type>
67
+ <sort_order>90</sort_order>
68
+ <show_in_default>1</show_in_default>
69
+ <show_in_website>1</show_in_website>
70
+ <show_in_store>1</show_in_store>
71
+ </specificerrmsg>
72
+ </fields>
73
+ </ems_ru>
74
+ </groups>
75
+ </carriers>
76
+ </sections>
77
+ </config>
app/code/community/Databunch/Ems/sql/.DS_Store ADDED
Binary file
app/code/community/Databunch/Ems/sql/ems_setup/install-0.1.0.php ADDED
@@ -0,0 +1,291 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* @var $this Mage_Core_Model_Resource_Setup */
3
+ $this->startSetup();
4
+ /** @var Varien_Db_Adapter_Pdo_Mysql $connection */
5
+ $connection = $this->getConnection();
6
+
7
+ $regions = array(
8
+ array("Республика Адыгея", "AD", "respublika-adygeja"),
9
+ array("Республика Башкортостан", "BA", "respublika-bashkortostan"),
10
+ array("Республика Бурятия", "BU", "respublika-burjatija"),
11
+ array("Республика Алтай", "AL", "respublika-altaj"),
12
+ array("Республика Дагестан", "DA", "respublika-dagestan"),
13
+ array("Республика Ингушетия", "IN", "respublika-ingushetija"),
14
+ array("Кабардино-Балкарская республика", "KB", "kabardino-balkarskaja-respublika"),
15
+ array("Республика Калмыкия", "KL", "respublika-kalmykija"),
16
+ array("Карачаево-Черкесская республика", "KC", "karachaevo-cherkesskaja-respublika"),
17
+ array("Республика Карелия", "KR", "respublika-karelija"),
18
+ array("Республика Коми", "KO", "respublika-komi"),
19
+ array("Республика Марий Эл", "ME", "respublika-marij-el"),
20
+ array("Республика Мордовия", "MO", "respublika-mordovija"),
21
+ array("Республика Саха (Якутия)", "SA", "respublika-saha-yakutija"),
22
+ array("Республика Северная Осетия — Алания", "SE", "respublika-sev.osetija-alanija"),
23
+ array("Республика Татарстан", "TA", "respublika-tatarstan"),
24
+ array("Республика Тыва", "TY", "respublika-tyva"),
25
+ array("Удмуртская республика", "UD", "udmurtskaja-respublika"),
26
+ array("Республика Хакасия", "KK", "respublika-khakasija"),
27
+ array("Чеченская республика", "CE", "chechenskaya-respublika"),
28
+ array("Чувашская республика", "CU", "chuvashskaja-respublika"),
29
+ array("Алтайский край", "ALT", "altajskij-kraj"),
30
+ array("Забайкальский край", "ZAB", "zabajkalskij-kraj"),
31
+ array("Камчатский край", "KAM", "kamchatskij-kraj"),
32
+ array("Краснодарский край", "KDA", "krasnodarskij-kraj"),
33
+ array("Красноярский край", "KYA", "krasnojarskij-kraj"),
34
+ array("Пермский край", "PER", "permskij-kraj"),
35
+ array("Приморский край", "PRI", "primorskij-kraj"),
36
+ array("Ставропольский край", "STA", "stavropolskij-kraj"),
37
+ array("Хабаровский край", "KHA", "khabarovskij-kraj"),
38
+ array("Амурская область", "AMU", "amurskaja-oblast"),
39
+ array("Архангельская область", "ARK", "arhangelskaja-oblast"),
40
+ array("Астраханская область", "AST", "astrahanskaja-oblast"),
41
+ array("Белгородская область", "BEL", "belgorodskaja-oblast"),
42
+ array("Брянская область", "BRY", "brjanskaja-oblast"),
43
+ array("Владимирская область", "VLA", "vladimirskaja-oblast"),
44
+ array("Волгоградская область", "VGG", "volgogradskaja-oblast"),
45
+ array("Вологодская область", "VLG", "vologodskaja-oblast"),
46
+ array("Воронежская область", "VOR", "voronezhskaja-oblast"),
47
+ array("Ивановская область", "IVA", "ivanovskaja-oblast"),
48
+ array("Иркутская область", "IRK", "irkutskaja-oblast"),
49
+ array("Калининградская область", "KGD", "kaliningradskaja-oblast"),
50
+ array("Калужская область", "KLU", "kaluzhskaja-oblast"),
51
+ array("Кемеровская область", "KEM", "kemerovskaja-oblast"),
52
+ array("Кировская область", "KIR", "kirovskaja-oblast"),
53
+ array("Костромская область", "KOS", "kostromskaja-oblast"),
54
+ array("Курганская область", "KGN", "kurganskaja-oblast"),
55
+ array("Курская область", "KRS", "kurskaja-oblast"),
56
+ array("Ленинградская область", "LEN", "leningradskaja-oblast"),
57
+ array("Липецкая область", "LIP", "lipeckaja-oblast"),
58
+ array("Магаданская область", "MAG", "magadanskaja-oblast"),
59
+ array("Московская область", "MOS", "moskovskaja-oblast"),
60
+ array("Мурманская область", "MUR", "murmanskaja-oblast"),
61
+ array("Нижегородская область", "NIZ", "nizhegorodskaja-oblast"),
62
+ array("Новгородская область", "NGR", "novgorodskaja-oblast"),
63
+ array("Новосибирская область", "NVS", "novosibirskaja-oblast"),
64
+ array("Омская область", "OMS", "omskaja-oblast"),
65
+ array("Оренбургская область", "ORE", "orenburgskaja-oblast"),
66
+ array("Орловская область", "ORL", "orlovskaja-oblast"),
67
+ array("Пензенская область", "PNZ", "penzenskaja-oblast"),
68
+ array("Псковская область", "PSK", "pskovskaja-oblast"),
69
+ array("Ростовская область", "ROS", "rostovskaja-oblast"),
70
+ array("Рязанская область", "RYA", "rjazanskaja-oblast"),
71
+ array("Самарская область", "SAM", "samarskaja-oblast"),
72
+ array("Саратовская область", "SAR", "saratovskaja-oblast"),
73
+ array("Сахалинская область", "SAK", "sahalinskaja-oblast"),
74
+ array("Свердловская область", "SVE", "sverdlovskaja-oblast"),
75
+ array("Смоленская область", "SMO", "smolenskaja-oblast"),
76
+ array("Тамбовская область", "TAM", "tambovskaja-oblast"),
77
+ array("Тверская область", "TVE", "tverskaja-oblast"),
78
+ array("Томская область", "TOM", "tomskaja-oblast"),
79
+ array("Тульская область", "TUL", "tulskaja-oblast"),
80
+ array("Тюменская область", "TYU", "tjumenskaja-oblast"),
81
+ array("Ульяновская область", "ULY", "uljanovskaja-oblast"),
82
+ array("Челябинская область", "CHE", "cheljabinskaja-oblast"),
83
+ array("Ярославская область", "YAR", "yaroslavskaja-oblast"),
84
+ array("Еврейская автономная область", "YEV", "evrejskaja-ao"),
85
+ array("Ненецкий автономный округ", "NEN", "neneckij-ao"),
86
+ array("Ханты-Мансийский автономный округ - Югра", "KHM", "khanty-mansijskij-ao"),
87
+ array("Чукотский автономный округ", "CHU", "chukotskij-ao"),
88
+ array("Ямало-Ненецкий автономный округ", "YAN", "yamalo-neneckij-ao"),
89
+ );
90
+
91
+ $cities = array(
92
+ array("abakan","АБАКАН"),
93
+ array("anadyr","АНАДЫРЬ"),
94
+ array("anapa","АНАПА"),
95
+ array("arhangelsk","АРХАНГЕЛЬСК"),
96
+ array("astrahan","АСТРАХАНЬ"),
97
+ array("bajkonur","БАЙКОНУР"),
98
+ array("barnaul","БАРНАУЛ"),
99
+ array("belgorod","БЕЛГОРОД"),
100
+ array("birobidzhan","БИРОБИДЖАН"),
101
+ array("blagoveshhensk","БЛАГОВЕЩЕНСК"),
102
+ array("brjansk","БРЯНСК"),
103
+ array("velikij-novgorod","ВЕЛИКИЙ НОВГОРОД"),
104
+ array("vladivostok","ВЛАДИВОСТОК"),
105
+ array("vladikavkaz","ВЛАДИКАВКАЗ"),
106
+ array("vladimir","ВЛАДИМИР"),
107
+ array("volgograd","ВОЛГОГРАД"),
108
+ array("vologda","ВОЛОГДА"),
109
+ array("vorkuta","ВОРКУТА"),
110
+ array("voronezh","ВОРОНЕЖ"),
111
+ array("gorno-altajsk","ГОРНО-АЛТАЙСК"),
112
+ array("groznyj","ГРОЗНЫЙ"),
113
+ array("dudinka","ДУДИНКА"),
114
+ array("ekaterinburg","ЕКАТЕРИНБУРГ"),
115
+ array("elizovo","ЕЛИЗОВО"),
116
+ array("ivanovo","ИВАНОВО"),
117
+ array("izhevsk","ИЖЕВСК"),
118
+ array("irkutsk","ИРКУТСК"),
119
+ array("ioshkar-ola","ЙОШКАР-ОЛА"),
120
+ array("kazan","КАЗАНЬ"),
121
+ array("kaliningrad","КАЛИНИНГРАД"),
122
+ array("kaluga","КАЛУГА"),
123
+ array("kemerovo","КЕМЕРОВО"),
124
+ array("kirov","КИРОВ"),
125
+ array("kostomuksha","КОСТОМУКША"),
126
+ array("kostroma","КОСТРОМА"),
127
+ array("krasnodar","КРАСНОДАР"),
128
+ array("krasnojarsk","КРАСНОЯРСК"),
129
+ array("kurgan","КУРГАН"),
130
+ array("kursk","КУРСК"),
131
+ array("kyzyl","КЫЗЫЛ"),
132
+ array("lipeck","ЛИПЕЦК"),
133
+ array("magadan","МАГАДАН"),
134
+ array("magnitogorsk","МАГНИТОГОРСК"),
135
+ array("majkop","МАЙКОП"),
136
+ array("mahachkala","МАХАЧКАЛА"),
137
+ array("mineralnye-vody","МИНЕРАЛЬНЫЕ ВОДЫ"),
138
+ array("mirnyj","МИРНЫЙ"),
139
+ array("moskva","МОСКВА"),
140
+ array("murmansk","МУРМАНСК"),
141
+ array("mytishhi","МЫТИЩИ"),
142
+ array("naberezhnye-chelny","НАБЕРЕЖНЫЕ ЧЕЛНЫ"),
143
+ array("nadym","НАДЫМ"),
144
+ array("nazran","НАЗРАНЬ"),
145
+ array("nalchik","НАЛЬЧИК"),
146
+ array("narjan-mar","НАРЬЯН-МАР"),
147
+ array("nerjungri","НЕРЮНГРИ"),
148
+ array("neftejugansk","НЕФТЕЮГАНСК"),
149
+ array("nizhnevartovsk","НИЖНЕВАРТОВСК"),
150
+ array("nizhnij-novgorod","НИЖНИЙ НОВГОРОД"),
151
+ array("novokuzneck","НОВОКУЗНЕЦК"),
152
+ array("novorossijsk","НОВОРОССИЙСК"),
153
+ array("novosibirsk","НОВОСИБИРСК"),
154
+ array("novyj-urengoj","НОВЫЙ УРЕНГОЙ"),
155
+ array("norilsk","НОРИЛЬСК"),
156
+ array("nojabrsk","НОЯБРЬСК"),
157
+ array("omsk","ОМСК"),
158
+ array("orel","ОРЁЛ"),
159
+ array("orenburg","ОРЕНБУРГ"),
160
+ array("penza","ПЕНЗА"),
161
+ array("perm","ПЕРМЬ"),
162
+ array("petrozavodsk","ПЕТРОЗАВОДСК"),
163
+ array("petropavlovsk-kamchatskij","ПЕТРОПАВЛОВСК-КАМЧАТСКИЙ"),
164
+ array("pskov","ПСКОВ"),
165
+ array("rostov-na-donu","РОСТОВ-НА-ДОНУ"),
166
+ array("rjazan","РЯЗАНЬ"),
167
+ array("salehard","САЛЕХАРД"),
168
+ array("samara","САМАРА"),
169
+ array("sankt-peterburg","САНКТ-ПЕТЕРБУРГ"),
170
+ array("saransk","САРАНСК"),
171
+ array("saratov","САРАТОВ"),
172
+ array("smolensk","СМОЛЕНСК"),
173
+ array("sochi","СОЧИ"),
174
+ array("stavropol","СТАВРОПОЛЬ"),
175
+ array("strezhevoj","СТРЕЖЕВОЙ"),
176
+ array("surgut","СУРГУТ"),
177
+ array("syktyvkar","СЫКТЫВКАР"),
178
+ array("tambov","ТАМБОВ"),
179
+ array("tver","ТВЕРЬ"),
180
+ array("toljatti","ТОЛЬЯТТИ"),
181
+ array("tomsk","ТОМСК"),
182
+ array("tula","ТУЛА"),
183
+ array("tynda","ТЫНДА"),
184
+ array("tjumen","ТЮМЕНЬ"),
185
+ array("ulan-udje","УЛАН-УДЭ"),
186
+ array("uljanovsk","УЛЬЯНОВСК"),
187
+ array("usinsk","УСИНСК"),
188
+ array("ufa","УФА"),
189
+ array("uhta","УХТА"),
190
+ array("khabarovsk","ХАБАРОВСК"),
191
+ array("khanty-mansijsk","ХАНТЫ-МАНСИЙСК"),
192
+ array("kholmsk","ХОЛМСК"),
193
+ array("cheboksary","ЧЕБОКСАРЫ"),
194
+ array("cheljabinsk","ЧЕЛЯБИНСК"),
195
+ array("cherepovec","ЧЕРЕПОВЕЦ"),
196
+ array("cherkessk","ЧЕРКЕССК"),
197
+ array("chita","ЧИТА"),
198
+ array("elista","ЭЛИСТА"),
199
+ array("yuzhno-sahalinsk","ЮЖНО-САХАЛИНСК"),
200
+ array("yakutsk","ЯКУТСК"),
201
+ array("yaroslavl","ЯРОСЛАВЛЬ"),
202
+ array("sevastopol","СЕВАСТОПОЛЬ"),
203
+ array("simferopol","СИМФЕРОПОЛЬ"),
204
+ );
205
+
206
+ $regionTableName = $this->getTable('directory/country_region');
207
+ $emsRegionTableName = $this->getTable('ems/ems_region');
208
+ $table = $connection->newTable($emsRegionTableName);
209
+
210
+ $table->addColumn('region_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 10, array(
211
+ 'nullable' => false,
212
+ 'identity' => false,
213
+ 'unsigned' => true,
214
+ 'primary' => true,
215
+ ), 'Region Id');
216
+
217
+ $table->addColumn('ems_code', Varien_Db_Ddl_Table::TYPE_VARCHAR, 32, array(
218
+ 'nullable' => false,
219
+ 'identity' => false,
220
+ 'unsigned' => true,
221
+ 'primary' => true,
222
+ ), 'Region Id');
223
+
224
+ $table->addColumn('ems_type', Varien_Db_Ddl_Table::TYPE_VARCHAR, 32, array(
225
+ 'nullable' => false,
226
+ 'identity' => false,
227
+ 'unsigned' => true,
228
+ 'primary' => true,
229
+ ), 'Type');
230
+
231
+ $table->addForeignKey(
232
+ $this->getFkName('ems/ems_region', 'region_id', 'directory/country_region', 'region_id'),
233
+ 'region_id', $this->getTable('directory/country_region'), 'region_id',
234
+ Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_NO_ACTION);
235
+
236
+ $connection->createTable($table);
237
+
238
+ $connection->beginTransaction();
239
+ try {
240
+ $connection->delete($regionTableName, 'country_id = "RU"');
241
+
242
+ foreach ($regions as $regionData) {
243
+ $name = $regionData[0];
244
+ $isoCode = $regionData[1];
245
+ $emsCode = $regionData[2];
246
+
247
+ $connection->insert($regionTableName, array(
248
+ 'country_id' => 'RU',
249
+ 'code' => $isoCode,
250
+ 'default_name' => $name,
251
+ ));
252
+
253
+ $connection->insert($emsRegionTableName, array(
254
+ 'region_id' => $connection->lastInsertId(),
255
+ 'ems_code' => $emsCode,
256
+ 'ems_type' => 'region'
257
+ ));
258
+
259
+ $connection->lastInsertId();
260
+ }
261
+ $connection->commit();
262
+ } catch (Exception $e) {
263
+ $connection->rollBack();
264
+ throw $e;
265
+ }
266
+ $connection->beginTransaction();
267
+ try {
268
+ foreach ($cities as $cityData) {
269
+ $name = $cityData[1];
270
+ $emsCode = $cityData[0];
271
+
272
+ $connection->insert($regionTableName, array(
273
+ 'country_id' => 'RU',
274
+ 'code' => $emsCode,
275
+ 'default_name' => $name,
276
+ ));
277
+
278
+ $connection->insert($emsRegionTableName, array(
279
+ 'region_id' => $connection->lastInsertId(),
280
+ 'ems_code' => $emsCode,
281
+ 'ems_type' => 'city'
282
+ ));
283
+
284
+ $connection->lastInsertId();
285
+ }
286
+ $connection->commit();
287
+ } catch (Exception $e) {
288
+ $connection->rollBack();
289
+ throw $e;
290
+ }
291
+ $this->endSetup();
app/etc/modules/Databunch_Ems.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Databunch_Ems>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </Databunch_Ems>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Databunch_Ems</name>
4
+ <version>0.1.0</version>
5
+ <stability>stable</stability>
6
+ <license>OSL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>EMS Russian post shipping module</summary>
10
+ <description>EMS Russian post shipping module</description>
11
+ <notes>First release</notes>
12
+ <authors><author><name>DataBunchRussia</name><user>DataBunchRussia</user><email>info@databunch.ru</email></author></authors>
13
+ <date>2014-10-22</date>
14
+ <time>13:09:03</time>
15
+ <contents><target name="magecommunity"><dir name="Databunch"><dir name="Ems"><dir><dir name="Helper"><file name="Data.php" hash="0e89d1b68e9ce8160cecfdcd1e06979d"/></dir><dir name="Model"><dir name="Api"><file name="Ru.php" hash="0f0cc10c3bf26b16b5a72e538600f657"/></dir><dir name="Carrier"><dir name="Ems"><file name="Ru.php" hash="712b3f8deab22f58fec61576a5c5cf7f"/></dir><file name=".DS_Store" hash="08082f61079d1f83c5a1ae336a283fd6"/></dir><dir name="Ems"><file name="Region.php" hash="f69e4b24e79243df3e1992b7e1264ebe"/></dir><dir name="Resource"><dir name="Ems"><file name="Region.php" hash="af99f0ba52e7f852b66d3402975bdc46"/></dir><file name=".DS_Store" hash="08082f61079d1f83c5a1ae336a283fd6"/></dir><file name=".DS_Store" hash="97b5813d157d50b38fa3323cf45f7bc1"/></dir><dir name="etc"><file name="config.xml" hash="8704d554f452225241d7d0828009c5c5"/><file name="system.xml" hash="3fab7385cf666525361118a09ad70263"/></dir><dir name="sql"><dir name="ems_setup"><file name="install-0.1.0.php" hash="fc5f103eb81c02f4cfc3650e3c614715"/></dir><file name=".DS_Store" hash="1cb10540b1bd5199e1b712a6fc2c6639"/></dir></dir><file name=".DS_Store" hash="88520624416343f24d49c8f19e8e3d07"/></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Databunch_Ems.xml" hash="45cfb66cdb3716c0fd94eacc9bfefe48"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.4.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>