Fretala - Version 1.0.0

Version Notes

Integration with the API Freta.lá

Makes a call to api and returns the value of freight and delivery time.

Download this release

Release Info

Developer Uecommerce
Extension Fretala
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/community/Uecommerce/Fretala/Block/Adminhtml/Sales/Order/View/Tab/Info/Fretala.php ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Uecommerce
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * DISCLAIMER
12
+ *
13
+ * Do not edit or add to this file if you wish to upgrade the extension
14
+ * to newer versions in the future. If you wish to customize the extension
15
+ * for your needs please refer to http://www.uecommerce.com.br/ for more information
16
+ *
17
+ * @category Uecommerce
18
+ * @package Uecommerce_Fretala
19
+ * @copyright Copyright (c) 2014 Uecommerce (http://www.uecommerce.com.br/)
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ /**
24
+ * Fretala module
25
+ *
26
+ * @category Uecommerce
27
+ * @package Uecommerce_Fretala
28
+ * @author Uecommerce Dev Team
29
+ */
30
+ class Uecommerce_Fretala_Block_Adminhtml_Sales_Order_View_Tab_Info_Fretala extends Mage_Adminhtml_Block_Template
31
+ {
32
+ protected $shippingConfigPath;
33
+
34
+ public function fretalaShippingExists(){
35
+
36
+ $orderId = Mage::registry('current_order')->getIncrementId();
37
+
38
+ try{
39
+ $fretala = Mage::getSingleton('fretala/api_fretala')->getFrete($orderId);
40
+
41
+ }catch(Exception $e){
42
+
43
+ switch (get_class($e)) {
44
+ case 'ValidationException':
45
+ Mage::getModel('adminnotification/inbox')->add(3, 'Freta.lá - Erro de validação da requisição do frete', 'Retorno: <b>'.$e->getMessage().'</b><br>','', true);
46
+ $fretala = false;
47
+ break;
48
+
49
+ case 'BadRequestException':
50
+ Mage::getModel('adminnotification/inbox')->add(1, 'Freta.lá - Erro na requisição do frete', '<b>Erro de conexão:</b> - '.$e->getMessage(),'', true);
51
+ $fretala = 'error';
52
+ break;
53
+
54
+ case 'InternalErrorException':
55
+ Mage::getModel('adminnotification/inbox')->add(1, 'Freta.lá - Erro na requisição do frete', 'Retorno: <b>'.$e->getMessage().'</b>', '',true);
56
+ $fretala = 'error';
57
+ break;
58
+
59
+ case 'NotFoundException':
60
+ //Mage::getModel('adminnotification/inbox')->add(1, 'Freta.lá -Erro na requisição do frete', 'Retorno: <b>'.$e->getMessage().'</b>');
61
+ $fretala = false;
62
+ break;
63
+
64
+ default:
65
+ Mage::getModel('adminnotification/inbox')->add(1, 'Freta.lá - Erro na requisição do frete', 'Retorno: <b>'.$e->getMessage().'</b>');
66
+ break;
67
+ }
68
+ if(!$fretala || $fretala == 'error'){
69
+ Mage::logException($e);
70
+ Mage::log('Criação do frete - '.$e->getMessage());
71
+ }
72
+
73
+
74
+ }
75
+
76
+ return $fretala;
77
+ }
78
+
79
+ public function getParamsCreate(){
80
+ $order = Mage::registry('current_order');
81
+ $customerStreet = '';
82
+ foreach($order->getShippingAddress()->getStreet() as $street){
83
+ $customerStreet .= $street.' ';
84
+ }
85
+ $streetStore = Mage::helper('fretala')->validStreetNumber($this->getShippingConfig('street_line1'));
86
+ $frete = array(
87
+ "id" => $order->getIncrementId(),
88
+ "productValue" => $order->getSubtotal()*100,
89
+ "fromNumber" => (int)$streetStore[1],
90
+ "fromStreet" => $streetStore[0],
91
+ "fromCity" => $this->getShippingConfig('city'),
92
+ "fromState" => $this->getShippingConfig('region_id'),
93
+ "toStreet" => $customerStreet,
94
+ "toCity" => $order->getShippingAddress()->getCity(),
95
+ "toState" => $order->getShippingAddress()->getRegion()
96
+ );
97
+ return json_encode($frete);
98
+ }
99
+
100
+ public function getShippingConfig($config){
101
+ if(empty($this->shippingConfigPath)){
102
+ $this->shippingConfigPath = 'shipping/origin/';
103
+ }
104
+ return Mage::getStoreConfig($this->shippingConfigPath.$config,$this->storeId);
105
+ }
106
+
107
+ public function getOrder(){
108
+ return Mage::registry('current_order');
109
+ }
110
+
111
+ }
app/code/community/Uecommerce/Fretala/Helper/Data.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Uecommerce
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * DISCLAIMER
12
+ *
13
+ * Do not edit or add to this file if you wish to upgrade the extension
14
+ * to newer versions in the future. If you wish to customize the extension
15
+ * for your needs please refer to http://www.uecommerce.com.br/ for more information
16
+ *
17
+ * @category Uecommerce
18
+ * @package Uecommerce_Fretala
19
+ * @copyright Copyright (c) 2014 Uecommerce (http://www.uecommerce.com.br/)
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ /**
24
+ * Fretala module
25
+ *
26
+ * @category Uecommerce
27
+ * @package Uecommerce_Fretala
28
+ * @author Uecommerce Dev Team
29
+ */
30
+ class Uecommerce_Fretala_Helper_Data extends Mage_Core_Helper_Abstract
31
+ {
32
+
33
+ public function validPostcode($postcode){
34
+ $cep = trim(str_replace('-','',$postcode));
35
+ $avaliaCep = preg_match('/^[0-9]{5,5}([- ]?[0-9]{3,3})?$/', $postcode);
36
+ return $avaliaCep;
37
+ }
38
+
39
+ public function validStreetNumber($street){
40
+ if(strpos($street,',') !== false){
41
+ $street = explode(',',$street);
42
+ if(count($street) ==2){
43
+ if(is_numeric($street[1])){
44
+
45
+ return array($street[0],str_replace(' ','',$street[1]));
46
+ }else{
47
+ return false;
48
+ }
49
+ }else{
50
+ return false;
51
+ }
52
+
53
+ }else{
54
+ return false;
55
+ }
56
+ }
57
+ }
app/code/community/Uecommerce/Fretala/Model/Api/Fretala.php ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Uecommerce
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * DISCLAIMER
12
+ *
13
+ * Do not edit or add to this file if you wish to upgrade the extension
14
+ * to newer versions in the future. If you wish to customize the extension
15
+ * for your needs please refer to http://www.uecommerce.com.br/ for more information
16
+ *
17
+ * @category Uecommerce
18
+ * @package Uecommerce_Fretala
19
+ * @copyright Copyright (c) 2014 Uecommerce (http://www.uecommerce.com.br/)
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ /**
24
+ * Fretala module
25
+ *
26
+ * @category Uecommerce
27
+ * @package Uecommerce_Fretala
28
+ * @author Uecommerce Dev Team
29
+ */
30
+ define("FRETALA_SANDBOX_URL", "https://sandbox.freta.la");
31
+ define("FRETALA_PRODUCTION_URL", "https://api.freta.la");
32
+
33
+ class ValidationException extends Exception{}
34
+ class BadRequestException extends Exception{}
35
+ class InternalErrorException extends Exception{}
36
+ class NotFoundException extends Exception{}
37
+
38
+
39
+ class Uecommerce_Fretala_Model_Api_Fretala extends Mage_Core_Model_Abstract
40
+ {
41
+ private $token;
42
+ private $environment;
43
+ private $postfields;
44
+ private $getfield;
45
+ private $clientId;
46
+ private $clientSecret;
47
+ private $username;
48
+ private $password;
49
+ public $url;
50
+
51
+ protected function getConfigData($config){
52
+ return Mage::getStoreConfig('carriers/fretala/'.$config,Mage::app()->getStore()->getStoreId());
53
+ }
54
+
55
+ public function __construct() {
56
+
57
+ $this->_init('fretala/api_fretala');
58
+ $this->environment = $this->getConfigData('environment');
59
+ if (!in_array("curl", get_loaded_extensions())) {
60
+ throw new Exception("You need to install cURL, see: http://curl.haxx.se/docs/install.html");
61
+ }
62
+
63
+ if(!isset($this->environment)) {
64
+ throw new Exception("environment wasn\"t set");
65
+ }
66
+
67
+ if(!in_array($this->environment, array("sandbox", "production"))) {
68
+ throw new Exception("environment must be production or sandbox");
69
+ }
70
+ if($this->environment == "production") {
71
+ $this->url = FRETALA_PRODUCTION_URL;
72
+ } else {
73
+ $this->url = FRETALA_SANDBOX_URL;
74
+ }
75
+
76
+ $this->clientId = $this->getConfigData('client_id');
77
+ $this->clientSecret = $this->getConfigData('client_secret');
78
+ $this->username = $this->getConfigData('login_email');
79
+ $this->password = $this->getConfigData('login_password');
80
+
81
+ $this->token = '';
82
+ }
83
+
84
+ public function authenticate() {
85
+ $data = array(
86
+ "grant_type" => "password",
87
+ "username" => $this->username,
88
+ "password" => $this->password
89
+ );
90
+ $res = $this->performRequest("POST", "/authenticate", json_encode($data), true);
91
+ $this->token = $res->access_token;
92
+ return $res->access_token;
93
+ }
94
+
95
+ public function getCards() {
96
+ $this->authenticate();
97
+ return $this->performRequest("GET", "/cards");
98
+ }
99
+
100
+ public function getFrete($code) {
101
+ $this->authenticate();
102
+ return $this->performRequest("GET", "/fretes/code/".$code);
103
+ }
104
+
105
+ public function insertCard($card) {
106
+ $this->authenticate();
107
+ return $this->performRequest("POST", "/cards", json_encode($card));
108
+ }
109
+
110
+ public function deleteCard($cardToken) {
111
+ $this->authenticate();
112
+ return $this->performRequest("DELETE", "/cards/".$cardToken);
113
+ }
114
+
115
+ public function insertFrete($frete) {
116
+ $this->authenticate();
117
+ return $this->performRequest("POST", "/fretes", json_encode($frete));
118
+ }
119
+
120
+ public function cost($cost) {
121
+ return $this->performRequest("POST", "/fretes/cost", json_encode($cost));
122
+ }
123
+
124
+ private function buildHeaders($auth = false) {
125
+ $headers = array();
126
+ if($auth) {
127
+ $headers[] = "Authorization: Basic " . base64_encode($this->clientId.':'.$this->clientSecret);
128
+ } else if($this->token != "") {
129
+ $headers[] = "Authorization: Bearer " . $this->token;
130
+ }
131
+ $headers[] = "Content-Type: application/json";
132
+ return $headers;
133
+ }
134
+
135
+ /**
136
+ * Perform the actual data retrieval from the API
137
+ *
138
+ * @param string $type GET, POST, PUT or DELETE
139
+ * @param string $path endpoint path
140
+ * @param string $path data to be send in POST or PUT requests
141
+ *
142
+ * @return string json If $return param is true, returns json data.
143
+ */
144
+ private function performRequest($type, $path, $data=null, $auth=false) {
145
+ $options = array(
146
+ CURLOPT_HTTPHEADER => $this->buildHeaders($auth),
147
+ CURLOPT_HEADER => false,
148
+ CURLOPT_URL => $this->url,
149
+ CURLOPT_RETURNTRANSFER => true,
150
+ CURLOPT_TIMEOUT => 60,
151
+ CURLOPT_URL => $this->url . $path
152
+ );
153
+
154
+ if ($type == "POST") {
155
+ $options[CURLOPT_POSTFIELDS] = $data;
156
+ } else if($type == "DELETE") {
157
+ $options[CURLOPT_CUSTOMREQUEST] = "DELETE";
158
+ } else if($type == "PUT") {
159
+ $options[CURLOPT_CUSTOMREQUEST] = "PUT";
160
+ $options[CURLOPT_POSTFIELDS] = $data;
161
+ }
162
+
163
+ $feed = curl_init();
164
+ curl_setopt_array($feed, $options);
165
+ $json = json_decode(curl_exec($feed));
166
+ $status = curl_getinfo($feed, CURLINFO_HTTP_CODE);
167
+ if($status != 200 && $status != 204) {
168
+ $err_msg = property_exists($json, 'message') ? $json->message : $json->error_description;
169
+ if($status == 422) {
170
+ throw new ValidationException($err_msg);
171
+ } else if($status == 400) {
172
+ throw new BadRequestException($err_msg);
173
+ } else if($status == 500) {
174
+ throw new InternalErrorException($err_msg);
175
+ } else if($status == 404) {
176
+ throw new NotFoundException($err_msg);
177
+ } else {
178
+ throw new Exception($err_msg);
179
+ }
180
+ }
181
+ curl_close($feed);
182
+ $this->token = '';
183
+ return $json;
184
+ }
185
+ }
app/code/community/Uecommerce/Fretala/Model/Api/Fretela.php ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Uecommerce
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * DISCLAIMER
12
+ *
13
+ * Do not edit or add to this file if you wish to upgrade the extension
14
+ * to newer versions in the future. If you wish to customize the extension
15
+ * for your needs please refer to http://www.uecommerce.com.br/ for more information
16
+ *
17
+ * @category Uecommerce
18
+ * @package Uecommerce_Fretala
19
+ * @copyright Copyright (c) 2014 Uecommerce (http://www.uecommerce.com.br/)
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ /**
24
+ * Fretala module
25
+ *
26
+ * @category Uecommerce
27
+ * @package Uecommerce_Fretala
28
+ * @author Uecommerce Dev Team
29
+ */
30
+ define("FRETALA_SANDBOX_URL", "https://sandbox.freta.la");
31
+ define("FRETALA_PRODUCTION_URL", "https://api.freta.la");
32
+
33
+ class ValidationException extends Exception{}
34
+ class BadRequestException extends Exception{}
35
+ class InternalErrorException extends Exception{}
36
+
37
+ class Uecommerce_Fretela_Model_Api_Fretela extends Mage_Core_Model_Abstract
38
+ {
39
+ private $token;
40
+ private $environment;
41
+ private $postfields;
42
+ private $getfield;
43
+ private $clientId;
44
+ private $clientSecret;
45
+ private $username;
46
+ private $password;
47
+ public $url;
48
+
49
+ public function __construct(){
50
+ $this->_init('fretela/api_fretela');
51
+ }
52
+
53
+ public function setSettings($environment, array $settings) {
54
+ Mage::log('passou por aqui');
55
+
56
+
57
+ if (!in_array("curl", get_loaded_extensions())) {
58
+ throw new Exception("You need to install cURL, see: http://curl.haxx.se/docs/install.html");
59
+ }
60
+
61
+ if(!isset($environment)) {
62
+ throw new Exception("environment wasn\"t set");
63
+ }
64
+
65
+ if(!in_array($environment, array("sandbox", "production"))) {
66
+ throw new Exception("environment must be production or sandbox");
67
+ }
68
+
69
+ $this->environment = $environment;
70
+ if($environment == "production") {
71
+ $this->url = FRETALA_PRODUCTION_URL;
72
+ } else {
73
+ $this->url = FRETALA_SANDBOX_URL;
74
+ }
75
+
76
+ $this->clientId = $settings["clientId"];
77
+ $this->clientSecret = $settings["clientSecret"];
78
+ $this->username = $settings["username"];
79
+ $this->password = $settings["password"];
80
+
81
+ $this->token = '';
82
+ }
83
+
84
+ public function authenticate() {
85
+ $data = array(
86
+ "grant_type" => "password",
87
+ "username" => $this->username,
88
+ "password" => $this->password
89
+ );
90
+ $res = $this->performRequest("POST", "/authenticate", json_encode($data), true);
91
+ $this->token = $res->access_token;
92
+ return $res->access_token;
93
+ }
94
+
95
+ public function getCards() {
96
+ $this->authenticate();
97
+ return $this->performRequest("GET", "/cards");
98
+ }
99
+
100
+ public function insertCard($card) {
101
+ $this->authenticate();
102
+ return $this->performRequest("POST", "/cards", json_encode($card));
103
+ }
104
+
105
+ public function deleteCard($cardToken) {
106
+ $this->authenticate();
107
+ return $this->performRequest("DELETE", "/cards/".$cardToken);
108
+ }
109
+
110
+ public function insertFrete($frete) {
111
+ $this->authenticate();
112
+ return $this->performRequest("POST", "/fretes", json_encode($frete));
113
+ }
114
+
115
+ public function cost($cost) {
116
+ return $this->performRequest("POST", "/fretes/cost", json_encode($cost));
117
+ }
118
+
119
+ private function buildHeaders($auth = false) {
120
+ $headers = array();
121
+ if($auth) {
122
+ $headers[] = "Authorization: Basic " . base64_encode($this->clientId.':'.$this->clientSecret);
123
+ } else if($this->token != "") {
124
+ $headers[] = "Authorization: Bearer " . $this->token;
125
+ }
126
+ $headers[] = "Content-Type: application/json";
127
+ return $headers;
128
+ }
129
+
130
+ /**
131
+ * Perform the actual data retrieval from the API
132
+ *
133
+ * @param string $type GET, POST, PUT or DELETE
134
+ * @param string $path endpoint path
135
+ * @param string $path data to be send in POST or PUT requests
136
+ *
137
+ * @return string json If $return param is true, returns json data.
138
+ */
139
+ private function performRequest($type, $path, $data=null, $auth=false) {
140
+ $options = array(
141
+ CURLOPT_HTTPHEADER => $this->buildHeaders($auth),
142
+ CURLOPT_HEADER => false,
143
+ CURLOPT_URL => $this->url,
144
+ CURLOPT_RETURNTRANSFER => true,
145
+ CURLOPT_TIMEOUT => 10,
146
+ CURLOPT_URL => $this->url . $path
147
+ );
148
+
149
+ if ($type == "POST") {
150
+ $options[CURLOPT_POSTFIELDS] = $data;
151
+ } else if($type == "DELETE") {
152
+ $options[CURLOPT_CUSTOMREQUEST] = "DELETE";
153
+ } else if($type == "PUT") {
154
+ $options[CURLOPT_CUSTOMREQUEST] = "PUT";
155
+ $options[CURLOPT_POSTFIELDS] = $data;
156
+ }
157
+
158
+ $feed = curl_init();
159
+ curl_setopt_array($feed, $options);
160
+ $json = json_decode(curl_exec($feed));
161
+ $status = curl_getinfo($feed, CURLINFO_HTTP_CODE);
162
+ if($status != 200 && $status != 204) {
163
+ $err_msg = property_exists($json, 'message') ? $json->message : $json->error_description;
164
+ if($status == 422) {
165
+ throw new ValidationException($err_msg);
166
+ } else if($status = 400) {
167
+ throw new BadRequestException($err_msg);
168
+ } else if($status = 500) {
169
+ throw new InternalErrorException($err_msg);
170
+ } else {
171
+ throw new Exception($err_msg);
172
+ }
173
+ }
174
+ curl_close($feed);
175
+ $this->token = '';
176
+ return $json;
177
+ }
178
+ }
app/code/community/Uecommerce/Fretala/Model/Api/Teste.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php
2
+ class Uecommerce_Fretala_Model_Teste
3
+ {
4
+ public function __construct(){
5
+ Mage::log('OKOKOKOKOK');
6
+ }
7
+ }
app/code/community/Uecommerce/Fretala/Model/Carrier/Fretala.php ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Uecommerce
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * DISCLAIMER
12
+ *
13
+ * Do not edit or add to this file if you wish to upgrade the extension
14
+ * to newer versions in the future. If you wish to customize the extension
15
+ * for your needs please refer to http://www.uecommerce.com.br/ for more information
16
+ *
17
+ * @category Uecommerce
18
+ * @package Uecommerce_Fretala
19
+ * @copyright Copyright (c) 2014 Uecommerce (http://www.uecommerce.com.br/)
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ /**
24
+ * Fretala module
25
+ *
26
+ * @category Uecommerce
27
+ * @package Uecommerce_Fretala
28
+ * @author Uecommerce Dev Team
29
+ */
30
+
31
+ class Uecommerce_Fretala_Model_Carrier_Fretala extends Mage_Shipping_Model_Carrier_Abstract implements Mage_Shipping_Model_Carrier_Interface
32
+ {
33
+ protected $_code = 'fretala';
34
+
35
+ public function collectRates(Mage_Shipping_Model_Rate_Request $request) {
36
+ //Mage::log(Mage::getStoreConfig('shipping/origin/street_line1',Mage::app()->getStore()->getStoreId()));
37
+ $storeId = Mage::app()->getStore()->getStoreId();
38
+ if(!$this->getConfigData('active') || !$this->isValidProductsInCart()
39
+ || !Mage::helper('fretala')->validStreetNumber(Mage::getStoreConfig('shipping/origin/street_line1',$storeId))
40
+ )
41
+ {
42
+ return false;
43
+ }
44
+ $result = Mage::getModel('shipping/rate_result');
45
+ $route = array(
46
+ "from" => array(
47
+ //"number" => "234",
48
+ "street" => Mage::getStoreConfig('shipping/origin/street_line1',$storeId),
49
+ "city" => Mage::getStoreConfig('shipping/origin/city',$storeId),
50
+ "state" => Mage::getStoreConfig('shipping/origin/region_id',$storeId)
51
+ ),
52
+ "to" => $this->getAreaQuote()->getShippingAddress()->getPostcode()
53
+ );
54
+ try{
55
+ $fretelaApi = Mage::getModel('fretala/api_fretala');
56
+
57
+ $shipping = $fretelaApi->cost($route);
58
+ //Mage::log($shipping);
59
+ $shipping->price = $shipping->price/100;
60
+ $method = Mage::getModel('shipping/rate_result_method');
61
+ $method->setCarrier($this->_code)
62
+ ->setCarrierTitle($this->getConfigData('title'))
63
+ ->setMethod('fretala')
64
+ ->setMethodTitle($this->getConfigData('name').' ('.$shipping->deadline.') - ')
65
+ ->setPrice($shipping->price)
66
+ ->setCost($shipping->price);
67
+
68
+
69
+ $result->append($method);
70
+
71
+ }catch(Exception $e){
72
+ switch (get_class($e)) {
73
+ case 'ValidationException':
74
+ //Mage::log('ValidationException: '.$e->getMessage());
75
+ if(Mage::getStoreConfig('carriers/fretala/notification_validation',$storeId)){
76
+ $dados = 'Para o cep: '.$route['to'];
77
+ Mage::getModel('adminnotification/inbox')->add(3, 'Freta.lá - Erro de validação na precificação', 'Retorno: <b>'.$e->getMessage().'</b><br> '.$dados, '', true);
78
+ }
79
+ break;
80
+
81
+ case 'BadRequestException':
82
+ Mage::logException($e);
83
+ Mage::log('Precificação - '.$e->getMessage());
84
+ Mage::log($route);
85
+ Mage::getModel('adminnotification/inbox')->add(1, 'Freta.lá - Erro de validação na precificação', '<b>Erro de conexão</b>', true);
86
+
87
+ break;
88
+
89
+ case 'InternalErrorException':
90
+ Mage::logException($e);
91
+ Mage::log('Precificação - '.$e->getMessage());
92
+ Mage::log($route);
93
+ Mage::getModel('adminnotification/inbox')->add(1, 'Freta.lá - Erro de validação na precificação', 'Retorno: <b>'.$e->getMessage().'</b>', true);
94
+ break;
95
+
96
+ case 'NotFoundException':
97
+ Mage::logException($e);
98
+ Mage::log('Precificação - '.$e->getMessage());
99
+ Mage::log($route);
100
+ Mage::getModel('adminnotification/inbox')->add(1, 'Freta.lá - Erro de validação na precificação', 'Sistema Freta.la fora do ar.', true);
101
+ break;
102
+
103
+ default:
104
+ # code...
105
+ break;
106
+ }
107
+ }
108
+
109
+ return $result;
110
+
111
+ }
112
+
113
+ public function getAllowedMethods() {
114
+
115
+ return array('fretala'=>$this->getConfigData('name'));
116
+ }
117
+
118
+ public function isTrackingAvailable() {
119
+
120
+ }
121
+
122
+ public function getAreaQuote(){
123
+ if (Mage::app()->getStore()->isAdmin()) {
124
+ $quote = Mage::getSingleton('adminhtml/session_quote')->getQuote();
125
+ } else {
126
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
127
+ }
128
+ return $quote;
129
+ }
130
+
131
+ public function isValidProductsInCart(){
132
+ $items = $this->getAreaQuote()->getAllVisibleItems();
133
+ foreach($items as $item){
134
+ $product = $item->getProduct();
135
+ if(!$product->getData('fretala_vip_delivery')){
136
+ return false;
137
+ }
138
+ return true;
139
+ }
140
+ }
141
+ }
app/code/community/Uecommerce/Fretala/Model/Observer.php ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Uecommerce
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * DISCLAIMER
12
+ *
13
+ * Do not edit or add to this file if you wish to upgrade the extension
14
+ * to newer versions in the future. If you wish to customize the extension
15
+ * for your needs please refer to http://www.uecommerce.com.br/ for more information
16
+ *
17
+ * @category Uecommerce
18
+ * @package Uecommerce_Fretala
19
+ * @copyright Copyright (c) 2014 Uecommerce (http://www.uecommerce.com.br/)
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ /**
24
+ * Fretala module
25
+ *
26
+ * @category Uecommerce
27
+ * @package Uecommerce_Fretala
28
+ * @author Uecommerce Dev Team
29
+ */
30
+ class Uecommerce_Fretala_Model_Observer
31
+ {
32
+ protected $shippingConfigPath;
33
+ protected $storeId;
34
+ public function checkSettings($observer){
35
+ $controller = $observer->getEvent()->getControllerAction();
36
+ if($controller->getFullActionName() == 'adminhtml_system_config_edit' && $controller->getRequest()->getParam('section') == 'carriers'){
37
+ $this->shippingConfigPath = 'shipping/origin/';
38
+ $this->storeId = Mage::app()->getStore()->getStoreId();
39
+ $street = $this->getShippingConfig('street_line1');
40
+ $postcode = $this->getShippingConfig('postcode');
41
+ $streetNumber = $this->validStreet($street);
42
+ if($this->getShippingConfig('region_id') == ''
43
+ || $postcode == ''
44
+ || !$this->validPostcode($postcode)
45
+ || $this->getShippingConfig('city') == ''
46
+ || $street == ''
47
+ || !$streetNumber)
48
+ {
49
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('fretala')->__('There is something wrong with the address settings from the store, %s click here check %s','<a href="'.$controller->getUrl('adminhtml/system_config/edit/section/shipping').'">','</a>'));
50
+ }
51
+
52
+ }
53
+ }
54
+
55
+ public function getShippingConfig($config){
56
+ return Mage::getStoreConfig($this->shippingConfigPath.$config,$this->storeId);
57
+ }
58
+
59
+ public function validPostcode($postcode) {
60
+ $validPostcode = Mage::helper('fretala')->validPostcode($postcode);
61
+ if(!$validPostcode){
62
+ Mage::getSingleton('adminhtml/session')->addNotice(Mage::helper('fretala')->__('The format of the postcode should be xxxxx-xxx or xxxxxxxx'));
63
+ }
64
+ return $validPostcode;
65
+ }
66
+
67
+ public function validStreet($street){
68
+ $validStreet = Mage::helper('fretala')->validStreetNumber($street);
69
+ if(!$validStreet){
70
+ Mage::getSingleton('adminhtml/session')->addNotice(Mage::helper('fretala')->__('The format of the address of your shop is incorrect, please follow the following format: Street, number'));
71
+ }
72
+ return $validStreet;
73
+ }
74
+
75
+ public function createShipping($observer){
76
+ if(Mage::getStoreConfig('carriers/fretala/shipping_mode',Mage::app()->getStore()->getStoreId()) == 'automatic'){
77
+ $shippingMethod = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getShippingMethod();
78
+ if($shippingMethod == 'fretala_fretala'){
79
+ $this->shippingConfigPath = 'shipping/origin/';
80
+ $order = $observer->getOrder();
81
+ $customerStreet = '';
82
+ foreach($order->getShippingAddress()->getStreet() as $street){
83
+ $customerStreet .= $street.' ';
84
+ }
85
+ $streetStore = Mage::helper('fretala')->validStreetNumber($this->getShippingConfig('street_line1'));
86
+
87
+ $frete = array(
88
+ "id" => $order->getIncrementId(),
89
+ "productValue" => $order->getSubtotal()*100,
90
+ "from" => array(
91
+ "number" => (int)$streetStore[1],
92
+ "street" => $streetStore[0],
93
+ "city" => $this->getShippingConfig('city'),
94
+ "state" => $this->getShippingConfig('region_id')
95
+ ),
96
+ "to" => array(
97
+ //"number" => "2500",
98
+ "street" => $customerStreet,
99
+ "city" => $order->getShippingAddress()->getCity(),
100
+ "state" => $order->getShippingAddress()->getRegion()
101
+ )
102
+ );
103
+
104
+ try{
105
+ Mage::getSingleton('fretala/api_fretala')->insertFrete($frete);
106
+ }catch(Exception $e){
107
+ switch (get_class($e)) {
108
+ case 'ValidationException':
109
+ Mage::getModel('adminnotification/inbox')->add(3, 'Freta.lá - Erro de validação na criação do frete', 'Retorno: <b>'.$e->getMessage().'</b><br>','', true);
110
+ break;
111
+
112
+ case 'BadRequestException':
113
+ Mage::getModel('adminnotification/inbox')->add(1, 'Freta.lá - Erro na criação do frete', '<b>Erro de conexão:</b> - '.$e->getMessage(),'', true);
114
+
115
+ break;
116
+
117
+ case 'InternalErrorException':
118
+ Mage::getModel('adminnotification/inbox')->add(1, 'Freta.lá - Erro na criação do frete', 'Retorno: <b>'.$e->getMessage().'</b>', '',true);
119
+ break;
120
+
121
+ case 'NotFoundException':
122
+ Mage::getModel('adminnotification/inbox')->add(1, 'Freta.lá -Erro na criação do frete', 'Retorno: <b>'.$e->getMessage().'</b>');
123
+
124
+ default:
125
+ Mage::getModel('adminnotification/inbox')->add(1, 'Freta.lá - Erro na criação do frete', 'Retorno: <b>'.$e->getMessage().'</b>');
126
+ break;
127
+ }
128
+ Mage::logException($e);
129
+ Mage::log('Criação do frete - '.$e->getMessage());
130
+ Mage::log($frete);
131
+ }
132
+
133
+ }
134
+ }
135
+ }
136
+ }
app/code/community/Uecommerce/Fretala/Model/Resource/Eav/Mysql4/Setup.php ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Uecommerce
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * DISCLAIMER
13
+ *
14
+ * Do not edit or add to this file if you wish to upgrade the extension
15
+ * to newer versions in the future. If you wish to customize the extension
16
+ * for your needs please refer to http://www.uecommerce.com.br/ for more information
17
+ *
18
+ * @category Uecommerce
19
+ * @package Uecommerce_Fretala
20
+ * @copyright Copyright (c) 2014 Uecommerce (http://www.uecommerce.com.br/)
21
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
22
+ */
23
+
24
+ /**
25
+ * Fretala module
26
+ *
27
+ * @category Uecommerce
28
+ * @package Uecommerce_Fretala
29
+ * @author Uecommerce Dev Team
30
+ */
31
+ class Uecommerce_Fretala_Model_Resource_Eav_Mysql4_Setup extends Mage_Eav_Model_Entity_Setup {
32
+ /*
33
+ * @return array
34
+ */
35
+
36
+ public function getDefaultEntities() {
37
+ return array(
38
+ 'catalog_product' => array(
39
+ 'entity_model' => 'catalog/product',
40
+ 'attribute_model' => 'catalog/resource_eav_attribute',
41
+ 'additional_attribute_table' => 'catalog/eav_attribute',
42
+ 'entity_attribute_collection' => 'catalog/product_attribute_collection',
43
+ 'table' => 'catalog/product',
44
+ 'attributes' => array(
45
+ 'fretala_vip_delivery' => array(
46
+ 'group' => 'General',
47
+ 'label' => 'Freta.la Vip Delivery',
48
+ 'type' => 'int',
49
+ 'input' => 'select',
50
+ 'default' => '1',
51
+ 'source' => 'eav/entity_attribute_source_boolean',
52
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
53
+ 'visible' => true,
54
+ 'required' => true,
55
+ 'user_defined' => false,
56
+ 'searchable' => false,
57
+ 'filterable' => false,
58
+ 'comparable' => false,
59
+ 'visible_on_front' => false,
60
+ 'visible_in_advanced_search' => false,
61
+ 'unique' => false
62
+ ),
63
+ )
64
+ )
65
+ );
66
+ }
67
+
68
+ }
app/code/community/Uecommerce/Fretala/Model/Source/Environment.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Uecommerce
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * DISCLAIMER
12
+ *
13
+ * Do not edit or add to this file if you wish to upgrade the extension
14
+ * to newer versions in the future. If you wish to customize the extension
15
+ * for your needs please refer to http://www.uecommerce.com.br/ for more information
16
+ *
17
+ * @category Uecommerce
18
+ * @package Uecommerce_Fretala
19
+ * @copyright Copyright (c) 2014 Uecommerce (http://www.uecommerce.com.br/)
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ /**
24
+ * Fretala module
25
+ *
26
+ * @category Uecommerce
27
+ * @package Uecommerce_Fretala
28
+ * @author Uecommerce Dev Team
29
+ */
30
+ class Uecommerce_Fretala_Model_Source_Environment extends Mage_Core_Model_Config_Data
31
+ {
32
+ public function toOptionArray(){
33
+ return array(
34
+ array('label'=>Mage::helper('fretala')->__('Production'),'value'=>'production'),
35
+ array('label'=>Mage::helper('fretala')->__('Sandbox'),'value'=>'sandbox')
36
+ );
37
+ }
38
+ }
app/code/community/Uecommerce/Fretala/Model/Source/Manualautomatic.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Uecommerce
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * DISCLAIMER
12
+ *
13
+ * Do not edit or add to this file if you wish to upgrade the extension
14
+ * to newer versions in the future. If you wish to customize the extension
15
+ * for your needs please refer to http://www.uecommerce.com.br/ for more information
16
+ *
17
+ * @category Uecommerce
18
+ * @package Uecommerce_Fretala
19
+ * @copyright Copyright (c) 2014 Uecommerce (http://www.uecommerce.com.br/)
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ /**
24
+ * Fretala module
25
+ *
26
+ * @category Uecommerce
27
+ * @package Uecommerce_Fretala
28
+ * @author Uecommerce Dev Team
29
+ */
30
+ class Uecommerce_Fretala_Model_Source_Manualautomatic extends Mage_Core_Model_Config_Data
31
+ {
32
+ public function toOptionArray(){
33
+ return array(
34
+ array('label'=>Mage::helper('fretala')->__('Manual'),'value'=>'manual'),
35
+ array('label'=>Mage::helper('fretala')->__('Automatic'),'value'=>'automatic')
36
+ );
37
+ }
38
+ }
app/code/community/Uecommerce/Fretala/controllers/Adminhtml/FretalaController.php ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Uecommerce
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * DISCLAIMER
12
+ *
13
+ * Do not edit or add to this file if you wish to upgrade the extension
14
+ * to newer versions in the future. If you wish to customize the extension
15
+ * for your needs please refer to http://www.uecommerce.com.br/ for more information
16
+ *
17
+ * @category Uecommerce
18
+ * @package Uecommerce_Fretala
19
+ * @copyright Copyright (c) 2014 Uecommerce (http://www.uecommerce.com.br/)
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ /**
24
+ * Fretala module
25
+ *
26
+ * @category Uecommerce
27
+ * @package Uecommerce_Fretala
28
+ * @author Uecommerce Dev Team
29
+ */
30
+ class Uecommerce_Fretala_Adminhtml_FretalaController extends Mage_Adminhtml_Controller_Action
31
+ {
32
+ public function createshippingAction(){
33
+ $request = $this->getRequest();
34
+ if($request->isPost()){
35
+ $frete = $request->getPost();
36
+ unset($frete['form_key']);
37
+
38
+ try{
39
+ $frete = array(
40
+ 'id' => $frete['id'],
41
+ 'productValue' => $frete['productValue'],
42
+ 'from' => array(
43
+ 'number' => $frete['fromNumber'],
44
+ 'street' => $frete['fromStreet'],
45
+ 'city' => $frete['fromCity'],
46
+ 'state' => $frete['fromState']
47
+ ),
48
+ 'to' => array(
49
+ 'street' => $frete['toStreet'],
50
+ 'city' => $frete['toCity'],
51
+ 'state' => $frete['toState']
52
+ )
53
+ );
54
+ Mage::getSingleton('fretala/api_fretala')->insertFrete($frete);
55
+ $return = $this->__('ok');
56
+ }catch(Exception $e){
57
+ switch (get_class($e)) {
58
+ case 'ValidationException':
59
+ Mage::getModel('adminnotification/inbox')->add(3, 'Freta.lá - Erro de validação na criação do frete', 'Retorno: <b>'.$e->getMessage().'</b><br>','', true);
60
+
61
+ break;
62
+
63
+ case 'BadRequestException':
64
+ Mage::getModel('adminnotification/inbox')->add(1, 'Freta.lá - Erro na criação do frete', '<b>Erro de conexão:</b> - '.$e->getMessage(),'', true);
65
+ break;
66
+
67
+ case 'InternalErrorException':
68
+ Mage::getModel('adminnotification/inbox')->add(1, 'Freta.lá - Erro na criação do frete', 'Retorno: <b>'.$e->getMessage().'</b>', '',true);
69
+ break;
70
+
71
+ case 'NotFoundException':
72
+ Mage::getModel('adminnotification/inbox')->add(1, 'Freta.lá -Erro na criação do frete', 'Retorno: <b>'.$e->getMessage().'</b>');
73
+ break;
74
+
75
+ default:
76
+ Mage::getModel('adminnotification/inbox')->add(1, 'Freta.lá - Erro na criação do frete', 'Retorno: <b>'.$e->getMessage().'</b>');
77
+ break;
78
+ }
79
+
80
+ Mage::logException($e);
81
+ Mage::log('Criação do frete - '.$e->getMessage());
82
+ $return = 0;
83
+ }
84
+ }
85
+ $this->getResponse()->setHeader('Content-type', 'application/json');
86
+ $this->getResponse()->setBody($return);
87
+ }
88
+ }
app/code/community/Uecommerce/Fretala/etc/config.xml ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Uecommerce
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * DISCLAIMER
13
+ *
14
+ * Do not edit or add to this file if you wish to upgrade the extension
15
+ * to newer versions in the future. If you wish to customize the extension
16
+ * for your needs please refer to http://www.uecommerce.com.br/ for more information
17
+ *
18
+ * @category Uecommerce
19
+ * @package Uecommerce_Fretala
20
+ * @copyright Copyright (c) 2014 Uecommerce (http://www.uecommerce.com.br/)
21
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
22
+ */
23
+
24
+ /**
25
+ * Fretala module
26
+ *
27
+ * @category Uecommerce
28
+ * @package Uecommerce_Fretala
29
+ * @author Uecommerce Dev Team
30
+ */
31
+ -->
32
+ <config>
33
+ <modules>
34
+ <Uecommerce_Fretala>
35
+ <version>1.0.0</version>
36
+ </Uecommerce_Fretala>
37
+ </modules>
38
+ <global>
39
+ <helpers>
40
+ <fretala>
41
+ <class>Uecommerce_Fretala_Helper</class>
42
+ </fretala>
43
+ </helpers>
44
+ <blocks>
45
+ <fretala>
46
+ <class>Uecommerce_Fretala_Block</class>
47
+ </fretala>
48
+ </blocks>
49
+ <models>
50
+ <fretala>
51
+ <class>Uecommerce_Fretala_Model</class>
52
+ </fretala>
53
+ </models>
54
+ <resources>
55
+ <fretala_setup>
56
+ <setup>
57
+ <module>Uecommerce_Fretala</module>
58
+ <class>Uecommerce_Fretala_Model_Resource_Eav_Mysql4_Setup</class>
59
+ </setup>
60
+ <connection>
61
+ <use>core_setup</use>
62
+ </connection>
63
+ </fretala_setup>
64
+ <fretala_write>
65
+ <connection>
66
+ <use>core_write</use>
67
+ </connection>
68
+ </fretala_write>
69
+ <fretala_read>
70
+ <connection>
71
+ <use>core_read</use>
72
+ </connection>
73
+ </fretala_read>
74
+ </resources>
75
+ <sales>
76
+ <quote>
77
+ <item>
78
+ <product_attributes>
79
+ <fretala_vip_delivery />
80
+ </product_attributes>
81
+ </item>
82
+ </quote>
83
+ <shipping>
84
+ <carriers>
85
+ <fretala>
86
+ <class>Uecommerce_Fretala_Model_Carrier_Fretala</class>
87
+ </fretala>
88
+ </carriers>
89
+ </shipping>
90
+ </sales>
91
+ <events>
92
+ <sales_order_place_after>
93
+ <observers>
94
+ <fretala>
95
+ <class>fretala/observer</class>
96
+ <method>createShipping</method>
97
+ </fretala>
98
+ </observers>
99
+ </sales_order_place_after>
100
+ </events>
101
+ </global>
102
+ <admin>
103
+ <routers>
104
+ <fretala>
105
+ <use>admin</use>
106
+ <args>
107
+ <module>Uecommerce_Fretala</module>
108
+ <frontName>fretala</frontName>
109
+ </args>
110
+ </fretala>
111
+ </routers>
112
+ </admin>
113
+ <adminhtml>
114
+ <events>
115
+ <controller_action_predispatch>
116
+ <observers>
117
+ <fretala>
118
+ <type>singleton</type>
119
+ <class>fretala/observer</class>
120
+ <method>checkSettings</method>
121
+ </fretala>
122
+ </observers>
123
+ </controller_action_predispatch>
124
+ </events>
125
+ <translate>
126
+ <modules>
127
+ <fretala>
128
+ <files>
129
+ <default>Fretala.csv</default>
130
+ </files>
131
+ </fretala>
132
+ </modules>
133
+ </translate>
134
+ <layout>
135
+ <updates>
136
+ <fretala>
137
+ <file>fretala.xml</file>
138
+ </fretala>
139
+ </updates>
140
+ </layout>
141
+ </adminhtml>
142
+ <default>
143
+ <carriers>
144
+ <fretala>
145
+ <active>1</active>
146
+ <model>fretala/carrier_fretala</model>
147
+ <title><![CDATA[Freta.lá]]></title>
148
+ <name>Entrega Vip</name>
149
+ <report_error>1</report_error>
150
+ <client_id>ecommerce</client_id>
151
+ <client_secret>Q6eH4nxD</client_secret>
152
+ </fretala>
153
+ </carriers>
154
+ </default>
155
+ </config>
app/code/community/Uecommerce/Fretala/etc/system.xml ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Uecommerce
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * DISCLAIMER
13
+ *
14
+ * Do not edit or add to this file if you wish to upgrade the extension
15
+ * to newer versions in the future. If you wish to customize the extension
16
+ * for your needs please refer to http://www.uecommerce.com.br/ for more information
17
+ *
18
+ * @category Uecommerce
19
+ * @package Uecommerce_Fretala
20
+ * @copyright Copyright (c) 2014 Uecommerce (http://www.uecommerce.com.br/)
21
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
22
+ */
23
+
24
+ /**
25
+ * Fretala module
26
+ *
27
+ * @category Uecommerce
28
+ * @package Uecommerce_Fretala
29
+ * @author Uecommerce Dev Team
30
+ */
31
+ -->
32
+ <config>
33
+ <sections>
34
+ <carriers>
35
+ <groups>
36
+ <fretala>
37
+ <label><![CDATA[<img src="https://freta.la/images/magento/logo2.png" width="60"/> ]]></label>
38
+ <sort_order>0</sort_order>
39
+ <show_in_default>1</show_in_default>
40
+ <show_in_website>1</show_in_website>
41
+ <show_in_store>1</show_in_store>
42
+ <comment><![CDATA[<div style="padding:5px 10px; background:#359ade;color:white"><img style="vertical-align:middle;width:75px" src="https://freta.la/images/magento/logo-icon.png"/><img src="https://freta.la/images/magento/logo2.png" style="vertical-align:middle" /><br><p style="margin-left:4px">A MAIS PODEROSA PLATAFORMA DE FRETES URBANOS EXPRESSOS.
43
+ </p><br><b>INFORMAÇÕES</b><br><ul><li> - Antes de fazer o pedido de frete, é necessário inserir um cartão de crédito para ser utilizado. <a href="https://freta.la/dashboard" style="color:white" target="_blank">Clique aqui</a> para inserir seu cartão.</li>
44
+ <li> - Verifique se os dados de sua loja estão corretos, pois é com base neles que o <b>Freta.lá</b> retornará para seu cliente a melhor escolha de frete. Verifique na seção: Sistema > Configurações > Configurações de Entrega.</li></ul></div>]]></comment>
45
+ <fields>
46
+ <mode_heading translate="label">
47
+ <label>Settings</label>
48
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
49
+ <sort_order>0</sort_order>
50
+ <show_in_default>1</show_in_default>
51
+ <show_in_website>1</show_in_website>
52
+ <show_in_store>0</show_in_store>
53
+ </mode_heading>
54
+ <active translate="label">
55
+ <label>Enabled</label>
56
+ <frontend_type>select</frontend_type>
57
+ <source_model>adminhtml/system_config_source_enabledisable</source_model>
58
+ <sort_order>1</sort_order>
59
+ <show_in_default>1</show_in_default>
60
+ <show_in_website>1</show_in_website>
61
+ <show_in_store>1</show_in_store>
62
+ </active>
63
+ <shipping_mode translate="label">
64
+ <label>Mode Setting Request Freight</label>
65
+ <frontend_type>select</frontend_type>
66
+ <source_model>fretala/source_manualautomatic</source_model>
67
+ <sort_order>2</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
+ </shipping_mode>
72
+ <environment translate="label">
73
+ <label>Environment</label>
74
+ <frontend_type>select</frontend_type>
75
+ <source_model>fretala/source_environment</source_model>
76
+ <sort_order>3</sort_order>
77
+ <show_in_default>1</show_in_default>
78
+ <show_in_website>1</show_in_website>
79
+ <show_in_store>1</show_in_store>
80
+ </environment>
81
+ <credentials_heading translate="label">
82
+ <label>Credentials</label>
83
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
84
+ <sort_order>10</sort_order>
85
+ <show_in_default>1</show_in_default>
86
+ <show_in_website>1</show_in_website>
87
+ <show_in_store>0</show_in_store>
88
+ </credentials_heading>
89
+ <client_id translate="label">
90
+ <label>Client ID</label>
91
+ <frontend_type>text</frontend_type>
92
+ <sort_order>11</sort_order>
93
+ <show_in_default>1</show_in_default>
94
+ <show_in_website>1</show_in_website>
95
+ <show_in_store>1</show_in_store>
96
+ </client_id>
97
+ <client_secret translate="label">
98
+ <label>Client Secret</label>
99
+ <frontend_type>text</frontend_type>
100
+ <sort_order>12</sort_order>
101
+ <show_in_default>1</show_in_default>
102
+ <show_in_website>1</show_in_website>
103
+ <show_in_store>1</show_in_store>
104
+ </client_secret>
105
+ <login_email translate="label">
106
+ <label>Login</label>
107
+ <frontend_type>text</frontend_type>
108
+ <sort_order>13</sort_order>
109
+ <show_in_default>1</show_in_default>
110
+ <show_in_website>1</show_in_website>
111
+ <show_in_store>1</show_in_store>
112
+ </login_email>
113
+ <login_password translate="label">
114
+ <label>Password</label>
115
+ <frontend_type>password</frontend_type>
116
+ <sort_order>14</sort_order>
117
+ <show_in_default>1</show_in_default>
118
+ <show_in_website>1</show_in_website>
119
+ <show_in_store>1</show_in_store>
120
+ </login_password>
121
+ <reports_heading translate="label">
122
+ <label>Error Notifications</label>
123
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
124
+ <sort_order>20</sort_order>
125
+ <show_in_default>1</show_in_default>
126
+ <show_in_website>1</show_in_website>
127
+ <show_in_store>0</show_in_store>
128
+ </reports_heading>
129
+ <notification_validation translate="label comment">
130
+ <label>Notification of Validation</label>
131
+ <frontend_type>select</frontend_type>
132
+ <source_model>adminhtml/system_config_source_yesno</source_model>
133
+ <sort_order>21</sort_order>
134
+ <show_in_default>1</show_in_default>
135
+ <show_in_website>1</show_in_website>
136
+ <show_in_store>1</show_in_store>
137
+ <comment>Regarding freight quotes for customers.</comment>
138
+ </notification_validation>
139
+ <!--<notification_badrequest>
140
+ <label>Notification of Bad Request</label>
141
+ <frontend_type>select</frontend_type>
142
+ <source_model>adminhtml/system_config_source_yesno</source_model>
143
+ <sort_order>22</sort_order>
144
+ <show_in_default>1</show_in_default>
145
+ <show_in_website>1</show_in_website>
146
+ <show_in_store>1</show_in_store>
147
+ </notification_badrequest>
148
+ <notification_internalerror>
149
+ <label>Notification of Internal Error</label>
150
+ <frontend_type>select</frontend_type>
151
+ <source_model>adminhtml/system_config_source_yesno</source_model>
152
+ <sort_order>23</sort_order>
153
+ <show_in_default>1</show_in_default>
154
+ <show_in_website>1</show_in_website>
155
+ <show_in_store>1</show_in_store>
156
+ </notification_internalerror>-->
157
+ <!--<report_error translate="label">
158
+ <label>Rerport Errors via E-mail</label>
159
+ <frontend_type>select</frontend_type>
160
+ <source_model>adminhtml/system_config_source_yesno</source_model>
161
+ <sort_order>24</sort_order>
162
+ <show_in_default>1</show_in_default>
163
+ <show_in_website>1</show_in_website>
164
+ <show_in_store>1</show_in_store>
165
+ <comment>Highly recommend leaving enabled</comment>
166
+ </report_error>
167
+ <report_email translate="label">
168
+ <label>Email</label>
169
+ <frontend_type>text</frontend_type>
170
+ <sort_order>25</sort_order>
171
+ <show_in_default>1</show_in_default>
172
+ <show_in_website>1</show_in_website>
173
+ <show_in_store>1</show_in_store>
174
+ <depends><report_error>1</report_error></depends>
175
+ </report_email>-->
176
+ </fields>
177
+ </fretala>
178
+ </groups>
179
+ </carriers>
180
+ </sections>
181
+ </config>
app/code/community/Uecommerce/Fretala/sql/fretala_setup/mysql4-install-1.0.0.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+ $installer = $this;
3
+ $installer->startSetup();
4
+ $installer->installEntities();
5
+ $installer->endSetup();
app/design/adminhtml/default/default/layout/fretala.xml ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Uecommerce
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * DISCLAIMER
13
+ *
14
+ * Do not edit or add to this file if you wish to upgrade the extension
15
+ * to newer versions in the future. If you wish to customize the extension
16
+ * for your needs please refer to http://www.uecommerce.com.br/ for more information
17
+ *
18
+ * @category Uecommerce
19
+ * @package Uecommerce_Fretala
20
+ * @copyright Copyright (c) 2014 Uecommerce (http://www.uecommerce.com.br/)
21
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
22
+ */
23
+
24
+ /**
25
+ * Fretala module
26
+ *
27
+ * @category Uecommerce
28
+ * @package Uecommerce_Fretala
29
+ * @author Uecommerce Dev Team
30
+ */
31
+ -->
32
+ <layout>
33
+ <adminhtml_sales_order_view>
34
+ <reference name="order_tab_info">
35
+ <action method="setTemplate">
36
+ <template>fretala/sales/order/view/tab/info.phtml</template>
37
+ </action>
38
+ <block type="fretala/adminhtml_sales_order_view_tab_info_fretala" name="fretala" template="fretala/sales/order/view/tab/info/fretala.phtml"/>
39
+ </reference>
40
+ </adminhtml_sales_order_view>
41
+ </layout>
app/design/adminhtml/default/default/template/fretala/sales/order/view/tab/info.phtml ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Uecommerce
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * DISCLAIMER
12
+ *
13
+ * Do not edit or add to this file if you wish to upgrade the extension
14
+ * to newer versions in the future. If you wish to customize the extension
15
+ * for your needs please refer to http://www.uecommerce.com.br/ for more information
16
+ *
17
+ * @category Uecommerce
18
+ * @package Uecommerce_Fretala
19
+ * @copyright Copyright (c) 2014 Uecommerce (http://www.uecommerce.com.br/)
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ /**
24
+ * Fretala module
25
+ *
26
+ * @category Uecommerce
27
+ * @package Uecommerce_Fretala
28
+ * @author Uecommerce Dev Team
29
+ */
30
+ ?>
31
+ <?php /** @var $this Mage_Adminhtml_Block_Sales_Order_View_Tab_Info */ ?>
32
+ <?php $_order = $this->getOrder() ?>
33
+ <div>
34
+ <div id="order-messages">
35
+ <?php echo $this->getChildHtml('order_messages') ?>
36
+ </div>
37
+ <?php echo $this->getChildHtml('order_info') ?>
38
+ <input type="hidden" name="order_id" value="<?php echo $_order->getId() ?>"/>
39
+ <?php if ($_order->getIsVirtual()): ?>
40
+ <div class="box-right">
41
+ <?php else: ?>
42
+ <div class="box-left">
43
+ <?php endif; ?>
44
+ <!--Payment Method-->
45
+ <div class="entry-edit">
46
+ <div class="entry-edit-head">
47
+ <h4 class="icon-head head-payment-method"><?php echo Mage::helper('sales')->__('Payment Information') ?></h4>
48
+ </div>
49
+ <fieldset>
50
+ <?php echo $this->getPaymentHtml() ?>
51
+ <div><?php echo Mage::helper('sales')->__('Order was placed using %s', $_order->getOrderCurrencyCode()) ?></div>
52
+ </fieldset>
53
+ </div>
54
+ </div>
55
+ <?php if (!$_order->getIsVirtual()): ?>
56
+ <div class="box-right">
57
+ <!--Shipping Method-->
58
+ <div class="entry-edit">
59
+ <div class="entry-edit-head">
60
+ <h4 class="icon-head head-shipping-method"><?php echo Mage::helper('sales')->__('Shipping &amp; Handling Information') ?></h4>
61
+ </div>
62
+ <fieldset>
63
+ <?php echo $this->getChildHtml('fretala'); ?>
64
+ <?php if ($_order->getTracksCollection()->count()) : ?>
65
+ <a href="#" id="linkId" onclick="popWin('<?php echo $this->helper('shipping')->getTrackingPopupUrlBySalesModel($_order) ?>','trackorder','width=800,height=600,resizable=yes,scrollbars=yes')" title="<?php echo $this->__('Track Order') ?>"><?php echo $this->__('Track Order') ?></a>
66
+ <br/>
67
+ <?php endif; ?>
68
+ <?php if ($_order->getShippingDescription()): ?>
69
+ <strong><?php echo $this->escapeHtml($_order->getShippingDescription()) ?></strong>
70
+
71
+ <?php if ($this->helper('tax')->displayShippingPriceIncludingTax()): ?>
72
+ <?php $_excl = $this->displayShippingPriceInclTax($_order); ?>
73
+ <?php else: ?>
74
+ <?php $_excl = $this->displayPriceAttribute('shipping_amount', false, ' '); ?>
75
+ <?php endif; ?>
76
+ <?php $_incl = $this->displayShippingPriceInclTax($_order); ?>
77
+
78
+ <?php echo $_excl; ?>
79
+ <?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
80
+ (<?php echo $this->__('Incl. Tax'); ?> <?php echo $_incl; ?>)
81
+ <?php endif; ?>
82
+ <?php else: ?>
83
+ <?php echo $this->helper('sales')->__('No shipping information available'); ?>
84
+ <?php endif; ?>
85
+ </fieldset>
86
+ </div>
87
+ </div>
88
+ <?php endif; ?>
89
+ <div class="clear"></div>
90
+ <?php echo $this->getGiftOptionsHtml() ?>
91
+ <div class="clear"></div>
92
+ <div class="entry-edit">
93
+ <div class="entry-edit-head">
94
+ <h4 class="icon-head head-products"><?php echo Mage::helper('sales')->__('Items Ordered') ?></h4>
95
+ </div>
96
+ </div>
97
+ <?php echo $this->getItemsHtml() ?>
98
+ <div class="clear"></div>
99
+
100
+ <div class="box-left">
101
+ <div class="entry-edit">
102
+ <div class="entry-edit-head">
103
+ <h4><?php echo Mage::helper('sales')->__('Comments History') ?></h4>
104
+ </div>
105
+ <fieldset><?php echo $this->getChildHtml('order_history') ?></fieldset>
106
+ </div>
107
+ </div>
108
+ <div class="box-right entry-edit">
109
+ <div class="entry-edit-head"><h4><?php echo Mage::helper('sales')->__('Order Totals') ?></h4></div>
110
+ <div class="order-totals"><?php echo $this->getChildHtml('order_totals') ?></div>
111
+ </div>
112
+ <div class="clear"></div>
113
+ </div>
114
+
115
+ <?php echo $this->getChildHtml('popup_window');?>
116
+ <script type="text/javascript">
117
+ //<![CDATA[
118
+ /**
119
+ * Retrieve gift options tooltip content
120
+ */
121
+ function getGiftOptionsTooltipContent(itemId) {
122
+ var contentLines = [];
123
+ var headerLine = null;
124
+ var contentLine = null;
125
+
126
+ $$('#gift_options_data_' + itemId + ' .gift-options-tooltip-content').each(function (element) {
127
+ if (element.down(0)) {
128
+ headerLine = element.down(0).innerHTML;
129
+ contentLine = element.down(0).next().innerHTML;
130
+ if (contentLine.length > 30) {
131
+ contentLine = contentLine.slice(0,30) + '...';
132
+ }
133
+ contentLines.push(headerLine + ' ' + contentLine);
134
+ }
135
+ });
136
+ return contentLines.join('<br/>');
137
+ }
138
+ giftOptionsTooltip.setTooltipContentLoaderFunction(getGiftOptionsTooltipContent);
139
+ //]]>
140
+ </script>
app/design/adminhtml/default/default/template/fretala/sales/order/view/tab/info/fretala.phtml ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $fretala = $this->fretalaShippingExists();
3
+ if(!$fretala): ?>
4
+ <div id="fretala_container" style="border: 1px solid #FFD967 !important;background: url('<?php echo $this->getSkinUrl('images/note_msg_icon.gif'); ?>') no-repeat scroll 5px 5px #FFFBF0 !important;color: #3D6611 !important;padding:5px 10px 10px 25px; margin-bottom:5px;">
5
+ <?php echo $this->__('This request has not yet created the freight Freta.lá'); ?>
6
+ <br/>
7
+ <button id="fretala" onclick="createFretala();" title="<?php echo $this->__('Create freight in Freta.la'); ?>" type="button" class="scalable go" style=""><span><span><span><?php echo $this->__('Create freight in Freta.la'); ?></span></span></span></button>
8
+ <br>
9
+
10
+ </div>
11
+ <script type="text/javascript">
12
+ paramsCreate = <?php echo $this->getParamsCreate(); ?>;
13
+
14
+ function createFretala(){
15
+ new Ajax.Request('<?php echo Mage::helper('adminhtml')->getUrl('fretala/adminhtml_fretala/createshipping') ?>',
16
+ {
17
+ method:'post',
18
+ parameters: paramsCreate,
19
+ onSuccess: function(transport) {
20
+ if (transport.responseText != 0) {
21
+ if(transport.responseText){
22
+ $('fretala_container').update('<?php echo $this->__("Shipping created!") ?>');
23
+ }
24
+
25
+ } else {
26
+ alert('falha');
27
+ }
28
+ }
29
+
30
+ }
31
+ );
32
+ return false;
33
+ }
34
+ </script>
35
+ <?php endif;?>
36
+ <?php if($fretala == 'error'): ?>
37
+ <div style="padding: 5px 5px 5px 25px; font-weight:bold; background: url('<?php echo $this->getSkinUrl('images/error_msg_icon.gif'); ?>') no-repeat scroll 5px 5px #FAEBE7 !important;border: 1px solid #F16048 !important;
38
+ color: #DF280A !important;margin-bottom:5px">
39
+ <?php echo $this->__('There was an error communicating with the webservice Freta.la. Please check your notifications.'); ?>
40
+ </div>
41
+ <?php endif; ?>
42
+
app/etc/modules/Fretala.xml ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" ?>
2
+ <!--
3
+ /**
4
+ * Uecommerce
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * DISCLAIMER
13
+ *
14
+ * Do not edit or add to this file if you wish to upgrade the extension
15
+ * to newer versions in the future. If you wish to customize the extension
16
+ * for your needs please refer to http://www.uecommerce.com.br/ for more information
17
+ *
18
+ * @category Uecommerce
19
+ * @package Uecommerce_Fretala
20
+ * @copyright Copyright (c) 2014 Uecommerce (http://www.uecommerce.com.br/)
21
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
22
+ */
23
+
24
+ /**
25
+ * Fretala module
26
+ *
27
+ * @category Uecommerce
28
+ * @package Uecommerce_Fretala
29
+ * @author Uecommerce Dev Team
30
+ */
31
+ -->
32
+ <config>
33
+ <modules>
34
+ <Uecommerce_Fretala>
35
+ <active>true</active>
36
+ <codePool>community</codePool>
37
+ </Uecommerce_Fretala>
38
+ </modules>
39
+ </config>
app/locale/pt_BR/Fretala.csv ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "Freta.la Vip Delivery","Entrega VIP Freta.lá"
2
+ "Credentials","Credenciais"
3
+ "Mode Setting Request Freight","Modo de pedido de Frete"
4
+ "Password","Senha"
5
+ "Highly recommend leaving enabled","Altamente recomendável deixar habilitado"
6
+ "There is something wrong with the address settings from the store, %s click here check %s","Há algo errado com as configurações de endereço da loja, %s clique aqui e verifique. %s"
7
+ "The format of the postcode should be xxxxx-xxx or xxxxxxxx","O formato do cep deve ser xxxxx-xxx ou xxxxxxxx"
8
+ "The format of the address of your shop is incorrect, please follow the following format: Street, number","O formato do endereço da sua loja está incorreto, por favor siga o seguinte formato: Rua Rio de Janeiro, 234"
9
+ "Settings","Configurações"
10
+ "Error Notifications","Notificações de Erros"
11
+ "Notification of Validation","Notificações de validações"
12
+ "Regarding freight quotes for customers.","Referente às cotações de frete pelos clientes."
13
+ "Automatic","Automático"
14
+ "There was an error communicating with the webservice Freta.la. Please check your notifications.","Houve um erro na comunicação com o webservice Freta.la. Por favor verifique suas notificações."
15
+ "This request has not yet created the freight Freta.lá","Este pedido não possui frete criado no Freta.lá"
16
+ "Create freight in Freta.la","Criar frete no freta.la"
17
+ "Shipping created!","Frete criado com sucesso!"
package.xml ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Fretala</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL 3.0)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Integration with http://freta.la platform. Displays new shipping methods based on Freta.l&#xE1; platform.</summary>
10
+ <description>&lt;a href="http://freta.la"&gt; Freta.l&#xE1; &lt;/a&gt; is a freight platform with the objective of working with clients that reside on the same area of your store. The Magento module makes a connection with the platform &lt;a href="http://freta.la"&gt; Freta.l&#xE1; &lt;/a&gt; that checks if the client is quoting freight resides in the same location that your store, returns a value and a deadline for his client.&#xD;
11
+ &#xD;
12
+ &lt;a href="http://freta.la"&gt;Freta.l&#xE1;&lt;/a&gt; &#xE9; uma plataforma de fretes com o objetivo de trabalhar com clientes que residem a mesma regi&#xE3;o de sua loja. O m&#xF3;dulo Magento faz uma liga&#xE7;&#xE3;o com a plataforma &lt;a href="http://freta.la"&gt;Freta.l&#xE1;&lt;/a&gt; que verifica se o cliente que est&#xE1; cotando o frete reside na mesma localidade que sua loja, retorna um valor e um prazo para seu cliente.&#xD;
13
+ &#xD;
14
+ ENTREGUE MAIS R&#xC1;PIDO&#xD;
15
+ &#xD;
16
+ Com o Freta.l&#xE1;, voc&#xEA; pode oferecer ao cliente da sua regi&#xE3;o a op&#xE7;&#xE3;o de Entrega VIP Freta.l&#xE1;, com entrega no mesmo dia da compra! Nosso sistema calcula de forma inteligente os melhores pre&#xE7;os e dispara o chamado para nossos parceiros locais, que s&#xE3;o empresas de motofrete regulamentadas para exercer o transporte dos seus produtos.&#xD;
17
+ &#xD;
18
+ &#xD;
19
+ ENVIE COM SEGURAN&#xC7;A&#xD;
20
+ &#xD;
21
+ Depois disso, ser&#xE1; enviado pelo nosso parceiro local um motoboy para realizar a entrega. N&#xF3;s garantimos a realiza&#xE7;&#xE3;o da miss&#xE3;o em at&#xE9; 4h ap&#xF3;s disparada a ordem de retirada, para pedidos at&#xE9; as 14h. E pensando na seguran&#xE7;a, nos responsabilizamos pelas suas entregas em caso de perdas, roubos e danos, ler condi&#xE7;&#xF5;es em nossos &lt;a href="http://freta.la/termos.html"&gt;Termos e Condi&#xE7;&#xF5;es&lt;/a&gt;.&#xD;
22
+ &#xD;
23
+ &#xD;
24
+ </description>
25
+ <notes>Integration with the API Freta.l&#xE1;&#xD;
26
+ &#xD;
27
+ Makes a call to api and returns the value of freight and delivery time.</notes>
28
+ <authors><author><name>Uecommerce</name><user>uecommerceraf</user><email>rafael@uecommerce.com.br</email></author></authors>
29
+ <date>2014-09-19</date>
30
+ <time>23:32:01</time>
31
+ <contents><target name="magecommunity"><dir name="Uecommerce"><dir name="Fretala"><dir name="Block"><dir name="Adminhtml"><dir name="Sales"><dir name="Order"><dir name="View"><dir name="Tab"><dir name="Info"><file name="Fretala.php" hash="702bcb808e769796b4806cef34ceb2d8"/></dir></dir></dir></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="456d18cc5cdbe300f1b11898fdc7e815"/></dir><dir name="Model"><dir name="Api"><file name="Fretala.php" hash="220e2620f7564ba1eccd7263897836c6"/><file name="Fretela.php" hash="d7b6c884e251cd688584b822f8f4ca9d"/><file name="Teste.php" hash="e509d42790ed1eb77412289fcd810f24"/></dir><dir name="Carrier"><file name="Fretala.php" hash="321739ca594d30b9608182d83788a9f8"/></dir><file name="Observer.php" hash="1e26f1f9e4ecf3b47abce33f16fc3e1e"/><dir name="Resource"><dir name="Eav"><dir name="Mysql4"><file name="Setup.php" hash="39bf0ce47531545ab0b29ef2ef4eb7df"/></dir></dir></dir><dir name="Source"><file name="Environment.php" hash="da866886c0e94b77d752cfb8f27e9ec3"/><file name="Manualautomatic.php" hash="9783453bfe1660ded560033534237f4d"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="FretalaController.php" hash="ea9b6bcafaefcb37563c865f3c813bbd"/></dir></dir><dir name="etc"><file name="config.xml" hash="c44fb13b49bc435c5e17d73990838251"/><file name="system.xml" hash="ed90f124fbeb8ad62a7726ae12f97e8f"/></dir><dir name="sql"><dir name="fretala_setup"><file name="mysql4-install-1.0.0.php" hash="6526a3a052424c86eda0613096e7e75f"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="fretala.xml" hash="2cb53c793083bb6e5797ebeb1ffcc7d7"/></dir><dir name="template"><dir name="fretala"><dir name="sales"><dir name="order"><dir name="view"><dir name="tab"><dir name="info"><file name="fretala.phtml" hash="597a31d2ac27fbffa22a852992ffaef3"/></dir><file name="info.phtml" hash="5bf557c0bcd3fc07aed72dc3b1ae46ba"/></dir></dir></dir></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Fretala.xml" hash="dc5a741e0ca1edc2490711f09be59da0"/></dir></target><target name="magelocale"><dir><dir name="pt_BR"><file name="Fretala.csv" hash="20f6a6539a6e9ecf2be3baabd450906e"/></dir></dir></target></contents>
32
+ <compatible/>
33
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
34
+ </package>