Version Notes
. Refactor for compatibility
Download this release
Release Info
Developer | Intelipost |
Extension | Intelipost |
Version | 0.8.3 |
Comparing to | |
See all releases |
Code changes from version 1.0.0 to 0.8.3
app/code/local/Intelipost/Shipping/Model/Carrier/Intelipost.php~
DELETED
@@ -1,211 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
require_once Mage::getBaseDir('code') . '/local/Intelipost/Shipping/Model/Resource/Quote.php';
|
4 |
-
require_once Mage::getBaseDir('code') . '/local/Intelipost/Shipping/Model/Resource/Volume.php';
|
5 |
-
|
6 |
-
class Intelipost_Shipping_Model_Carrier_Intelipost
|
7 |
-
extends Mage_Shipping_Model_Carrier_Abstract
|
8 |
-
implements Mage_Shipping_Model_Carrier_Interface
|
9 |
-
{
|
10 |
-
protected $_code = 'intelipost';
|
11 |
-
protected $_helper = null;
|
12 |
-
|
13 |
-
private $_zipCodeRegex = '/[0-9]{2}\.?[0-9]{3}-?[0-9]{3}/';
|
14 |
-
|
15 |
-
public function collectRates(Mage_Shipping_Model_Rate_Request $request) {
|
16 |
-
$this->_helper = Mage::helper('intelipost');
|
17 |
-
|
18 |
-
if (!$this->getConfigFlag('active')) {
|
19 |
-
Mage::log('Intelipost is inactive', null, 'intelipost.log');
|
20 |
-
return false;
|
21 |
-
}
|
22 |
-
|
23 |
-
$originZipCode = $this->getConfigData('zipcode');
|
24 |
-
$destinationZipCode = $request->getDestPostcode();
|
25 |
-
|
26 |
-
if (!preg_match($this->_zipCodeRegex, $originZipCode) || !preg_match($this->_zipCodeRegex, $destinationZipCode)) {
|
27 |
-
Mage::log('Invalid zip code ' . $originZipCode . ' or ' . $destinationZipCode, null, 'intelipost.log');
|
28 |
-
return false;
|
29 |
-
}
|
30 |
-
|
31 |
-
// only numbers allowed
|
32 |
-
$originZipCode = preg_replace('/[^0-9]/', '', $originZipCode);
|
33 |
-
$destinationZipCode = preg_replace('/[^0-9]/', '', $destinationZipCode);
|
34 |
-
|
35 |
-
$weight = $request->getPackageWeight();
|
36 |
-
if ($weight <= 0) {
|
37 |
-
$this->_throwError('weightzeroerror', 'Weight zero', __LINE__);
|
38 |
-
}
|
39 |
-
|
40 |
-
// weight must be in Kg
|
41 |
-
if($this->getConfigData('weight_type') == 'gr') {
|
42 |
-
$weight = number_format($weight/1000, 2, '.', '');
|
43 |
-
}else{
|
44 |
-
// TODO: do the weight defaults to Kg if it is not gr?
|
45 |
-
$weight = number_format($weight, 2, '.', '');
|
46 |
-
}
|
47 |
-
|
48 |
-
$price = $request->getPackageValue();
|
49 |
-
|
50 |
-
$encryption = Mage::getSingleton('core/encryption');
|
51 |
-
// $account = $encryption->decrypt($this->getConfigData('account'));
|
52 |
-
// $password = $encryption->decrypt($this->getConfigData('password'));
|
53 |
-
$api_key = $encryption->decrypt($this->getConfigData('apikey'));
|
54 |
-
// $token = $encryption->decrypt($this->getConfigData('token'));
|
55 |
-
|
56 |
-
if(!isset($account) || !isset($password) || !isset($api_key) || !isset($token) ||
|
57 |
-
!is_string($account) || !is_string($password) || !is_string($api_key) || !is_string($token)
|
58 |
-
){
|
59 |
-
Mage::log('Intelipost not configured', null, 'intelipost.log');
|
60 |
-
Mage::log('account: ' . $account, null, 'intelipost.log');
|
61 |
-
// take care to not log the password
|
62 |
-
Mage::log('password length: ' . strlen($password) , null, 'intelipost.log');
|
63 |
-
return false;
|
64 |
-
}
|
65 |
-
|
66 |
-
$item_list = Mage::getModel('checkout/cart')->getQuote()->getAllVisibleItems();
|
67 |
-
$productsCount = count($item_list);
|
68 |
-
|
69 |
-
$quote = new Intelipost_Model_Request_Quote();
|
70 |
-
$quote->origin_zip_code = $originZipCode;
|
71 |
-
$quote->destination_zip_code = $destinationZipCode;
|
72 |
-
|
73 |
-
if (!$request->getAllItems()) {
|
74 |
-
Mage::log('Cart is empty', null, 'intelipost.log');
|
75 |
-
return false;
|
76 |
-
}
|
77 |
-
|
78 |
-
// if notification is disabled we send the request anyways (changed on version 0.0.2)
|
79 |
-
$dimension_check = $this->getConfigData('notification');
|
80 |
-
|
81 |
-
$i=0;
|
82 |
-
foreach ($item_list as $item) {
|
83 |
-
$product = $item->getProduct();
|
84 |
-
|
85 |
-
$volume = new Intelipost_Model_Request_Volume();
|
86 |
-
$volume->volume_type = 'BOX';
|
87 |
-
|
88 |
-
if (!$this->isDimensionSet($product)) {
|
89 |
-
Mage::log('Product does not have dimensions set', null, 'intelipost.log');
|
90 |
-
|
91 |
-
if ($dimension_check) {
|
92 |
-
$this->notifyProductsDimension($item_list);
|
93 |
-
return false;
|
94 |
-
}
|
95 |
-
}else{
|
96 |
-
$volume->width = $product->getVolumeLargura();
|
97 |
-
$volume->height = $product->getVolumeAltura();
|
98 |
-
$volume->length = $product->getVolumeComprimento();
|
99 |
-
}
|
100 |
-
|
101 |
-
$volume->weight = number_format(floatval($item->getWeight()), 2, ',', '') * $item->getQty();
|
102 |
-
$volume->cost_of_goods = number_format(floatval($item->getPrice()), 2, ',', '') * $item->getQty();
|
103 |
-
|
104 |
-
array_push($quote->volumes, $volume);
|
105 |
-
}
|
106 |
-
|
107 |
-
$body = json_encode($quote);
|
108 |
-
|
109 |
-
$s = curl_init();
|
110 |
-
curl_setopt($s, CURLOPT_TIMEOUT, 5000);
|
111 |
-
curl_setopt($s, CURLOPT_URL, "https://api.intelipost.com.br/api/v1/quote");
|
112 |
-
/*if ($username != null && $password != null) {
|
113 |
-
curl_setopt($s, CURLOPT_USERPWD, $username . ":" . $password);
|
114 |
-
}*/
|
115 |
-
curl_setopt($s, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Accept: application/json", "api_key: $api_key"/*, "token: $token"*/));
|
116 |
-
curl_setopt($s, CURLOPT_POST, true);
|
117 |
-
curl_setopt($s, CURLOPT_ENCODING , "");
|
118 |
-
curl_setopt($s, CURLOPT_RETURNTRANSFER, 1);
|
119 |
-
curl_setopt($s, CURLOPT_POSTFIELDS, $body);
|
120 |
-
$responseBody = curl_exec($s);
|
121 |
-
|
122 |
-
$response = json_decode($responseBody);
|
123 |
-
// echo $responseBody;
|
124 |
-
curl_close($s);
|
125 |
-
|
126 |
-
$result = Mage::getModel('shipping/rate_result');
|
127 |
-
|
128 |
-
foreach ($response->content->delivery_options as $deliveryOption) {
|
129 |
-
$method = Mage::getModel('shipping/rate_result_method');
|
130 |
-
|
131 |
-
$method->setCarrier ('intelipost');
|
132 |
-
$method->setCarrierTitle('Intelipost');
|
133 |
-
$method->setMethod ($deliveryOption->description);
|
134 |
-
$method->setMethodTitle ($deliveryOption->description);
|
135 |
-
$method->setPrice ($deliveryOption->final_shipping_cost);
|
136 |
-
$method->setCost ($deliveryOption->provider_shipping_cost);
|
137 |
-
|
138 |
-
$result->append($method);
|
139 |
-
}
|
140 |
-
|
141 |
-
return $result;
|
142 |
-
}
|
143 |
-
|
144 |
-
public function getAllowedMethods() {
|
145 |
-
return array($this->_code => $this->getConfigData('name'));
|
146 |
-
}
|
147 |
-
|
148 |
-
private function isDimensionSet($product) {
|
149 |
-
$volume_altura = $product->getData('volume_altura');
|
150 |
-
$volume_largura = $product->getData('volume_largura');
|
151 |
-
$volume_comprimento = $product->getData('volume_comprimento');
|
152 |
-
|
153 |
-
if ($volume_comprimento == '' || (int)$volume_comprimento == 0
|
154 |
-
|| $volume_largura == '' || (int)$volume_largura == 0
|
155 |
-
|| $volume_altura == '' || (int)$volume_altura == 0
|
156 |
-
) {
|
157 |
-
return false;
|
158 |
-
}
|
159 |
-
|
160 |
-
return true;
|
161 |
-
}
|
162 |
-
|
163 |
-
private function notifyProductsDimension($item_list) {
|
164 |
-
$notification = Mage::getSingleton('adminnotification/inbox');
|
165 |
-
$message = $this->_helper->__('The following products do not have dimension set:');
|
166 |
-
|
167 |
-
$message .= '<ul>';
|
168 |
-
foreach ($item_list as $item) {
|
169 |
-
$product = $item->getProduct();
|
170 |
-
|
171 |
-
if (!$this->isDimensionSet($product)) {
|
172 |
-
$message .= '<li>';
|
173 |
-
$message .= sprintf(
|
174 |
-
'<a href="%s">',
|
175 |
-
Mage::helper('adminhtml')->getUrl(
|
176 |
-
'adminhtml/catalog_product/edit',
|
177 |
-
array( 'id' => $product->getId())
|
178 |
-
)
|
179 |
-
);
|
180 |
-
$message .= $item->getName();
|
181 |
-
$message .= '</a>';
|
182 |
-
$message .= '</li>';
|
183 |
-
}
|
184 |
-
}
|
185 |
-
$message .= '</ul>';
|
186 |
-
|
187 |
-
$message .= $this->_helper->__('<small>Disable these notifications in System > Settings > Carriers > Intelipost</small>');
|
188 |
-
|
189 |
-
$notification->add(
|
190 |
-
Mage_AdminNotification_Model_Inbox::SEVERITY_MINOR,
|
191 |
-
$this->_helper->__('Product missing dimensions'),
|
192 |
-
$message
|
193 |
-
);
|
194 |
-
}
|
195 |
-
|
196 |
-
private function formatDeadline($days) {
|
197 |
-
if ($days == 0) {
|
198 |
-
return $this->_helper->__('(same day)');
|
199 |
-
}
|
200 |
-
|
201 |
-
if ($days == 1) {
|
202 |
-
return $this->_helper->__('(1 day)');
|
203 |
-
}
|
204 |
-
|
205 |
-
if ($days == 101) {
|
206 |
-
return $this->_helper->__('(On acknowledgment)');
|
207 |
-
}
|
208 |
-
|
209 |
-
return sprintf($this->_helper->__('(%s days)'), $days);
|
210 |
-
}
|
211 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/local/Intelipost/Shipping/Model/Config/Apikey.php~
DELETED
@@ -1,58 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
require_once Mage::getBaseDir('code') . '/local/Intelipost/Shipping/Model/Resource/Quote.php';
|
4 |
-
require_once Mage::getBaseDir('code') . '/local/Intelipost/Shipping/Model/Resource/Volume.php';
|
5 |
-
|
6 |
-
class Intelipost_Shipping_Model_Config_Apikey
|
7 |
-
extends Mage_Adminhtml_Model_System_Config_Backend_Encrypted
|
8 |
-
{
|
9 |
-
|
10 |
-
public function save() {
|
11 |
-
$api_key = $this->getValue();
|
12 |
-
// $token = $this->getData('groups/intelipost/fields/token/value');
|
13 |
-
// $password = $this->getData('groups/intelipost/fields/password/value');
|
14 |
-
// $username = $this->getData('groups/intelipost/fields/account/value');
|
15 |
-
$helper = Mage::helper('intelipost');
|
16 |
-
|
17 |
-
$volume = new Intelipost_Model_Request_Volume();
|
18 |
-
$volume->weight = 10;
|
19 |
-
$volume->volume_type = 'BOX';
|
20 |
-
$volume->cost_of_goods = "10";
|
21 |
-
$volume->width = 1;
|
22 |
-
$volume->height = 1;
|
23 |
-
$volume->length = 1;
|
24 |
-
|
25 |
-
$quote = new Intelipost_Model_Request_Quote();
|
26 |
-
$quote->origin_zip_code = "04037-002";
|
27 |
-
$quote->destination_zip_code = "04037-002";
|
28 |
-
array_push($quote->volumes, $volume);
|
29 |
-
|
30 |
-
$body = json_encode($quote);
|
31 |
-
$s = curl_init();
|
32 |
-
curl_setopt($s, CURLOPT_TIMEOUT, 5000);
|
33 |
-
curl_setopt($s, CURLOPT_URL, "https://api.intelipost.com.br/api/v1/quote");
|
34 |
-
// if ($this->username != null && $this->password != null) {
|
35 |
-
// curl_setopt($s, CURLOPT_USERPWD, $username . ":" . $password);
|
36 |
-
// }
|
37 |
-
curl_setopt($s, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Accept: application/json", "api_key: $api_key"/*, "token: $token"*/));
|
38 |
-
curl_setopt($s, CURLOPT_POST, true);
|
39 |
-
curl_setopt($s, CURLOPT_ENCODING , "");
|
40 |
-
curl_setopt($s, CURLOPT_RETURNTRANSFER, 1);
|
41 |
-
curl_setopt($s, CURLOPT_POSTFIELDS, $body);
|
42 |
-
|
43 |
-
$responseBody = curl_exec($s);
|
44 |
-
Mage::log(var_dump($responseBody, true), null, intelipost.log);
|
45 |
-
$responseBody = curl_exec($s);
|
46 |
-
Mage::log(var_dump($responseBody, true), null, intelipost.log);
|
47 |
-
|
48 |
-
$response = json_decode($responseBody);
|
49 |
-
curl_close($s);
|
50 |
-
|
51 |
-
if (!isset($response->status)) {
|
52 |
-
// Mage::getSingleton('core/session')->addWarning($helper->__('Could not validate username and password!'));
|
53 |
-
Mage::throwException($helper->__('Invalid ApiKey!'));
|
54 |
-
}
|
55 |
-
|
56 |
-
parent::save();
|
57 |
-
}
|
58 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
package.xml
CHANGED
@@ -1,19 +1,18 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Intelipost</name>
|
4 |
-
<version>
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://www.gnu.org/licenses/gpl-2.0.html">GNU General Public License Version 2 (GPLv2)</license>
|
7 |
<channel>community</channel>
|
8 |
<extends/>
|
9 |
<summary>Intelipost</summary>
|
10 |
-
<description>Extens&#xE3;o para utilizar o servi&#xE7;o de cota&#xE7;&#xE3;o do intelipost.com.br
|
11 |
-
|
12 |
-
<
|
13 |
-
<
|
14 |
-
<
|
15 |
-
<
|
16 |
-
<contents><target name="magelocal"><dir><dir name="Intelipost"><dir name="Shipping"><dir name="Helper"><file name="Data.php" hash="7523e254d75d8ec6413164bdfc9484ce"/></dir><dir name="Model"><dir name="Carrier"><file name="Category.php" hash="9e3f8a5013f819dc65c9b84848182c8a"/><file name="Intelipost.php" hash="ed0b097f70db82ca33e0f2107fe2f34d"/><file name="Intelipost.php~" hash="fc48f350e774fae6523449efedbccf62"/></dir><dir name="Config"><file name="Apikey.php" hash="b74ed350e2aad08f58f56caaa2b6f7a4"/><file name="Apikey.php~" hash="9df9c5ccba568dfc991586151894b6b5"/><file name="Password.php" hash="a3b0f867850520e637ed6d1561047093"/><file name="Token.php" hash="ae2ef4b4527f06c17061d6c984fa0a28"/><file name="Useraccount.php" hash="89a67edacda5169a4f58590e6ac24006"/></dir><dir name="Resource"><file name="Quote.php" hash="1f02542b8f6c4a16400da34e723c0541"/><file name="Setup.php" hash="8f10c3277be3454dbf61abb1fb0b06f4"/><file name="Volume.php" hash="e1e8de42eeb5d1e02e7ebc4a2dff6dd0"/></dir></dir><dir name="etc"><file name="config.xml" hash="5e5cf688524df28ee306b11424804363"/><file name="system.xml" hash="ff6564d28de2203c67379147d24fdea7"/></dir><dir name="sql"><dir name="intelipost_setup"><file name="mysql4-install-0.0.1.php" hash="7cbddb7bad3e35cba43d14d8e2308900"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Intelipost_Shipping.xml" hash="285e60144ae15077910cb9200038adb9"/></dir></target><target name="magelocale"><dir><dir name="pt_BR"><file name="Intelipost_Shipping.csv" hash="ae1e673344d004666d04b254556685c5"/></dir></dir></target></contents>
|
17 |
<compatible/>
|
18 |
-
<dependencies><required><php><min>5.
|
19 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Intelipost</name>
|
4 |
+
<version>0.8.3</version>
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://www.gnu.org/licenses/gpl-2.0.html">GNU General Public License Version 2 (GPLv2)</license>
|
7 |
<channel>community</channel>
|
8 |
<extends/>
|
9 |
<summary>Intelipost</summary>
|
10 |
+
<description>Extens&amp;#xE3;o para utilizar o servi&amp;#xE7;o de cota&amp;#xE7;&amp;#xE3;o do intelipost.com.br</description>
|
11 |
+
<notes>. Refactor for compatibility</notes>
|
12 |
+
<authors><author><name>Intelipost</name><user>Intelipost</user><email>it@intelipost.com.br</email></author></authors>
|
13 |
+
<date>2014-04-07</date>
|
14 |
+
<time>12:45:29</time>
|
15 |
+
<contents><target name="magelocal"><dir name="Intelipost"><dir name="Shipping"><dir name="Helper"><file name="Data.php" hash="7523e254d75d8ec6413164bdfc9484ce"/></dir><dir name="Model"><dir name="Carrier"><file name="Category.php" hash="9e3f8a5013f819dc65c9b84848182c8a"/><file name="Intelipost.php" hash="ed0b097f70db82ca33e0f2107fe2f34d"/></dir><dir name="Config"><file name="Apikey.php" hash="b74ed350e2aad08f58f56caaa2b6f7a4"/><file name="Password.php" hash="a3b0f867850520e637ed6d1561047093"/><file name="Token.php" hash="ae2ef4b4527f06c17061d6c984fa0a28"/><file name="Useraccount.php" hash="89a67edacda5169a4f58590e6ac24006"/></dir><dir name="Resource"><file name="Quote.php" hash="1f02542b8f6c4a16400da34e723c0541"/><file name="Setup.php" hash="8f10c3277be3454dbf61abb1fb0b06f4"/><file name="Volume.php" hash="e1e8de42eeb5d1e02e7ebc4a2dff6dd0"/></dir></dir><dir name="etc"><file name="config.xml" hash="5e5cf688524df28ee306b11424804363"/><file name="system.xml" hash="ff6564d28de2203c67379147d24fdea7"/></dir><dir name="sql"><dir name="intelipost_setup"><file name="mysql4-install-0.0.1.php" hash="7cbddb7bad3e35cba43d14d8e2308900"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Intelipost_Shipping.xml" hash="285e60144ae15077910cb9200038adb9"/></dir></target><target name="magelocale"><dir name="pt_BR"><file name="Intelipost_Shipping.csv" hash="ae1e673344d004666d04b254556685c5"/></dir></target></contents>
|
|
|
16 |
<compatible/>
|
17 |
+
<dependencies><required><php><min>5.3.0</min><max>5.5.0</max></php></required></dependencies>
|
18 |
</package>
|