|
1
|
|
|
<?php
|
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
/** MODULO ADAPTADO POR ODLANIER
|
|
4
|
|
|
* @author Odlanier de Souza Mendes
|
|
5
|
|
|
* @copyright Dlani
|
|
6
|
|
|
* @email [email protected]
|
|
7
|
|
|
* @version 3.0
|
|
8
|
|
|
* */
|
|
9
|
|
|
if (!defined('_PS_VERSION_'))
|
|
10
|
|
|
exit;
|
|
11
|
|
|
|
|
12
|
|
|
class correios extends CarrierModule {
|
|
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
public $id_carrier;
|
|
15
|
|
|
private $_urlWebservice = "http://ws.correios.com.br/calculador/CalcPrecoPrazo.asmx?wsdl";
|
|
16
|
|
|
private $_html = '';
|
|
|
|
|
|
|
17
|
|
|
private $_postErrors = array();
|
|
|
|
|
|
|
18
|
|
|
private $_factorys = array(
|
|
|
|
|
|
|
19
|
|
|
"soapclient" => "SOAP Client",
|
|
20
|
|
|
"nusoap" => "NuSoap"
|
|
21
|
|
|
);
|
|
22
|
|
|
private $_factory = "soapclient";
|
|
23
|
|
|
public $servicos_todos = array(
|
|
24
|
|
|
'04510' => 'PAC',# era '41106' => 'PAC',
|
|
|
|
|
|
|
25
|
|
|
'04014' => 'SEDEX', # era '40010' => 'SEDEX',
|
|
|
|
|
|
|
26
|
|
|
'40215' => 'SEDEX 10',
|
|
27
|
|
|
'40290' => 'SEDEX HOJE',
|
|
28
|
|
|
//'81019' => 'E-SEDEX',
|
|
|
|
|
|
|
29
|
|
|
//'44105' => 'MALOTE',
|
|
|
|
|
|
|
30
|
|
|
//'41017' => 'NORMAL',
|
|
|
|
|
|
|
31
|
|
|
//'40045' => 'SEDEX A COBRAR',
|
|
|
|
|
|
|
32
|
|
|
);
|
|
33
|
|
|
private $_moduleName = 'correios';
|
|
34
|
|
|
|
|
35
|
|
|
function __construct() {
|
|
|
|
|
|
|
36
|
|
|
$this->name = 'correios';
|
|
|
|
|
|
|
37
|
|
|
$this->tab = 'shipping_logistics';
|
|
|
|
|
|
|
38
|
|
|
$this->version = '3.0';
|
|
|
|
|
|
|
39
|
|
|
$this->author = 'Dlani Mendes';
|
|
|
|
|
|
|
40
|
|
|
$this->limited_countries = array('br');
|
|
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
parent::__construct();
|
|
43
|
|
|
|
|
44
|
|
|
/* The parent construct is required for translations */
|
|
45
|
|
|
$this->page = basename(__file__, '.php');
|
|
|
|
|
|
|
46
|
|
|
$this->displayName = $this->l('Frete Correios');
|
|
|
|
|
|
|
47
|
|
|
$this->description = 'Painel de Controle dos Frete Correios.';
|
|
|
|
|
|
|
48
|
|
|
}
|
|
49
|
|
|
|
|
50
|
|
|
function install() {
|
|
|
|
|
|
|
51
|
|
|
if (parent::install() == false or
|
|
|
|
|
|
|
52
|
|
|
$this->registerHook('updateCarrier') == false or
|
|
|
|
|
|
|
53
|
|
|
$this->registerHook('extraCarrier') == false or
|
|
|
|
|
|
|
54
|
|
|
$this->registerHook('beforeCarrier') == false)
|
|
|
|
|
|
|
55
|
|
|
return false;
|
|
56
|
|
|
|
|
57
|
|
|
$this->installCarriers();
|
|
58
|
|
|
|
|
59
|
|
|
return true;
|
|
60
|
|
|
}
|
|
61
|
|
|
|
|
62
|
|
|
/**
|
|
63
|
|
|
*
|
|
64
|
|
|
*/
|
|
65
|
|
|
private function installCarriers() {
|
|
66
|
|
|
$configBase = array(
|
|
67
|
|
|
'id_tax_rules_group' => 0,
|
|
68
|
|
|
'active' => true,
|
|
69
|
|
|
'deleted' => 0,
|
|
70
|
|
|
'shipping_handling' => false,
|
|
71
|
|
|
'range_behavior' => 0,
|
|
72
|
|
|
'delay' => array("br" => "Entrega pelos Correios."),
|
|
73
|
|
|
'id_zone' => 1,
|
|
74
|
|
|
'is_module' => true,
|
|
75
|
|
|
'shipping_external' => true,
|
|
76
|
|
|
'external_module_name' => $this->_moduleName,
|
|
77
|
|
|
'need_range' => true,
|
|
78
|
|
|
'url' => Tools::getHttpHost(true) . "/modules/correios/rastreio.php?objeto=@",
|
|
79
|
|
|
);
|
|
80
|
|
|
|
|
81
|
|
|
$arrayConfigs = array();
|
|
82
|
|
|
foreach ($this->servicos_todos as $codServico => $servico)
|
|
83
|
|
|
$arrayConfigs[] = array(
|
|
84
|
|
|
"name" => "Correios - $servico",
|
|
85
|
|
|
"cod_servico" => $codServico
|
|
86
|
|
|
);
|
|
87
|
|
|
|
|
88
|
|
|
foreach ($arrayConfigs as $config) {
|
|
89
|
|
|
$config = array_merge($configBase, $config);
|
|
90
|
|
|
$this->installExternalCarrier($config);
|
|
|
|
|
|
|
91
|
|
|
}
|
|
92
|
|
|
}
|
|
93
|
|
|
|
|
94
|
|
|
/**
|
|
95
|
|
|
*
|
|
96
|
|
|
* @param type $config
|
|
97
|
|
|
* @return boolean
|
|
98
|
|
|
*/
|
|
99
|
|
|
public function installExternalCarrier($config) {
|
|
100
|
|
|
$check = Db::getInstance()->executeS("SELECT id_carrier FROM " . _DB_PREFIX_ . "carrier WHERE name = '" . $config['name'] . "' ");
|
|
101
|
|
|
if (is_array($check) && !empty($check))
|
|
102
|
|
|
return Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier', array('deleted' => 0), 'UPDATE', ' name = "' . $config['name'] . '" ');
|
|
103
|
|
|
|
|
104
|
|
|
$carrier = new Carrier();
|
|
105
|
|
|
$carrier->name = $config['name'];
|
|
|
|
|
|
|
106
|
|
|
$carrier->url = $config['url'];
|
|
|
|
|
|
|
107
|
|
|
$carrier->id_tax_rules_group = $config['id_tax_rules_group'];
|
|
|
|
|
|
|
108
|
|
|
$carrier->id_zone = $config['id_zone'];
|
|
|
|
|
|
|
109
|
|
|
$carrier->active = $config['active'];
|
|
|
|
|
|
|
110
|
|
|
$carrier->deleted = $config['deleted'];
|
|
|
|
|
|
|
111
|
|
|
$carrier->delay = $config['delay'];
|
|
|
|
|
|
|
112
|
|
|
$carrier->shipping_handling = $config['shipping_handling'];
|
|
|
|
|
|
|
113
|
|
|
$carrier->range_behavior = $config['range_behavior'];
|
|
|
|
|
|
|
114
|
|
|
$carrier->is_module = $config['is_module'];
|
|
|
|
|
|
|
115
|
|
|
$carrier->shipping_external = $config['shipping_external'];
|
|
|
|
|
|
|
116
|
|
|
$carrier->external_module_name = $config['external_module_name'];
|
|
|
|
|
|
|
117
|
|
|
$carrier->need_range = $config['need_range'];
|
|
|
|
|
|
|
118
|
|
|
|
|
119
|
|
|
$languages = Language::getLanguages(true);
|
|
120
|
|
|
foreach ($languages as $language) {
|
|
121
|
|
|
$carrier->delay[(int) $language['id_lang']] = $config['delay']['br'];
|
|
122
|
|
|
}
|
|
123
|
|
|
|
|
124
|
|
|
if ($carrier->add()) {
|
|
|
|
|
|
|
125
|
|
|
$groups = Group::getGroups(true);
|
|
126
|
|
|
foreach ($groups as $group)
|
|
127
|
|
|
Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_group', array('id_carrier' => (int) ($carrier->id), 'id_group' => (int) ($group['id_group'])), 'INSERT');
|
|
|
|
|
|
|
128
|
|
|
|
|
129
|
|
|
$rangePrice = new RangePrice();
|
|
130
|
|
|
$rangePrice->id_carrier = $carrier->id;
|
|
131
|
|
|
$rangePrice->delimiter1 = '0';
|
|
132
|
|
|
$rangePrice->delimiter2 = '0';
|
|
133
|
|
|
$rangePrice->add();
|
|
134
|
|
|
|
|
135
|
|
|
$rangeWeight = new RangeWeight();
|
|
136
|
|
|
$rangeWeight->id_carrier = $carrier->id;
|
|
137
|
|
|
$rangeWeight->delimiter1 = '0';
|
|
138
|
|
|
$rangeWeight->delimiter2 = '30';
|
|
139
|
|
|
$rangeWeight->add();
|
|
140
|
|
|
|
|
141
|
|
|
$zones = Zone::getZones(true);
|
|
142
|
|
|
foreach ($zones as $zone) {
|
|
143
|
|
|
Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_zone', array('id_carrier' => (int) ($carrier->id), 'id_zone' => (int) ($zone['id_zone'])), 'INSERT');
|
|
144
|
|
|
Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_ . 'delivery', array('id_carrier' => (int) ($carrier->id), 'id_range_price' => (int) ($rangePrice->id), 'id_range_weight' => NULL, 'id_zone' => (int) ($zone['id_zone']), 'price' => '0'), 'INSERT');
|
|
145
|
|
|
Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_ . 'delivery', array('id_carrier' => (int) ($carrier->id), 'id_range_price' => NULL, 'id_range_weight' => (int) ($rangeWeight->id), 'id_zone' => (int) ($zone['id_zone']), 'price' => '0'), 'INSERT');
|
|
146
|
|
|
}
|
|
147
|
|
|
|
|
148
|
|
|
Configuration::updateValue("PS_CORREIOS_CARRIER_{$carrier->id}", $config['cod_servico']);
|
|
|
|
|
|
|
149
|
|
|
|
|
150
|
|
|
// Copy Logo
|
|
151
|
|
|
if (!copy(dirname(__FILE__) . '/logos/' . $config['cod_servico'] . '.png', _PS_SHIP_IMG_DIR_ . '/' . (int) $carrier->id . '.jpg'))
|
|
152
|
|
|
return false;
|
|
153
|
|
|
|
|
154
|
|
|
// Return ID Carrier
|
|
155
|
|
|
return (int) ($carrier->id);
|
|
|
|
|
|
|
156
|
|
|
}
|
|
157
|
|
|
return false;
|
|
158
|
|
|
}
|
|
159
|
|
|
|
|
160
|
|
|
/**
|
|
161
|
|
|
*
|
|
162
|
|
|
* @return boolean
|
|
163
|
|
|
*/
|
|
164
|
|
|
public function uninstall() {
|
|
165
|
|
|
// Uninstall Carriers
|
|
166
|
|
|
$result = Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier', array('deleted' => 1), 'UPDATE', ' name LIKE "Correios%" ');
|
|
|
|
|
|
|
167
|
|
|
|
|
168
|
|
|
if (!Configuration::deleteByName('PS_CORREIOS_CEP_ORIG'))
|
|
|
|
|
|
|
169
|
|
|
return false;
|
|
170
|
|
|
|
|
171
|
|
|
if (!parent::uninstall() OR !$this->unregisterHook('updateCarrier'))
|
|
|
|
|
|
|
172
|
|
|
return false;
|
|
173
|
|
|
|
|
174
|
|
|
return true;
|
|
175
|
|
|
}
|
|
176
|
|
|
|
|
177
|
|
|
/**
|
|
178
|
|
|
*
|
|
179
|
|
|
* @return type
|
|
180
|
|
|
*/
|
|
181
|
|
|
public function getContent() {
|
|
|
|
|
|
|
182
|
|
|
$output = '<h2>' . $this->displayName . '</h2>';
|
|
183
|
|
|
if (Tools::isSubmit('submitcarrinho_correios')) {
|
|
184
|
|
|
Configuration::updateValue('PS_CORREIOS_CEP_ORIG', intval($_POST['cep']));
|
|
|
|
|
|
|
185
|
|
|
|
|
186
|
|
|
$output .= '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="' . $this->
|
|
187
|
|
|
l('Confirmation') . '" />' . $this->l('Settings updated') . '</div>';
|
|
|
|
|
|
|
188
|
|
|
}
|
|
189
|
|
|
if (Tools::isSubmit('factory')) {
|
|
190
|
|
|
Configuration::updateValue('PS_CORREIOS_FACTORY', $_POST['factory']);
|
|
|
|
|
|
|
191
|
|
|
|
|
192
|
|
|
$output .= '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="' . $this->
|
|
193
|
|
|
l('Confirmation') . '" />' . $this->l('Settings updated') . '</div>';
|
|
|
|
|
|
|
194
|
|
|
}
|
|
195
|
|
|
|
|
196
|
|
|
return $output . $this->displayForm();
|
|
197
|
|
|
}
|
|
198
|
|
|
|
|
199
|
|
|
/**
|
|
200
|
|
|
*
|
|
201
|
|
|
* @return type
|
|
202
|
|
|
*/
|
|
203
|
|
|
public function displayForm() {
|
|
|
|
|
|
|
204
|
|
|
$conf = Configuration::getMultiple(array('PS_CORREIOS_CEP_ORIG'));
|
|
205
|
|
|
$cep_orig = array_key_exists('cep', $_POST) ? $_POST['cep'] : (array_key_exists('PS_CORREIOS_CEP_ORIG', $conf) ? $conf['PS_CORREIOS_CEP_ORIG'] : '');
|
|
206
|
|
|
include (dirname(__file__) . "/form_config.php");
|
|
207
|
|
|
return $form_config;
|
|
|
|
|
|
|
208
|
|
|
}
|
|
209
|
|
|
|
|
210
|
|
|
/**
|
|
211
|
|
|
*
|
|
212
|
|
|
* @param type $params
|
|
213
|
|
|
* @param type $shipping_cost
|
|
214
|
|
|
* @return boolean
|
|
215
|
|
|
*/
|
|
216
|
|
|
public function getOrderShippingCost($params, $shipping_cost) {
|
|
217
|
|
|
$carrier = new Carrier();
|
|
|
|
|
|
|
218
|
|
|
$chave = Configuration::get("PS_CORREIOS_CARRIER_{$this->id_carrier}");
|
|
219
|
|
|
$address = new Address($params->id_address_delivery);
|
|
|
|
|
|
|
220
|
|
|
|
|
221
|
|
|
$sCepDestino = preg_replace("/([^0-9])/", "", $address->postcode);
|
|
222
|
|
|
|
|
223
|
|
|
$paramsCorreios = array(
|
|
224
|
|
|
"sCepDestino" => $sCepDestino,
|
|
225
|
|
|
"nVlPeso" => (string) $params->getTotalWeight(),
|
|
226
|
|
|
"nCdServico" => $chave,
|
|
227
|
|
|
);
|
|
228
|
|
|
|
|
229
|
|
|
$this->getPriceWebService($paramsCorreios);
|
|
|
|
|
|
|
230
|
|
|
$custoFrete = $this->getPriceWebService($paramsCorreios);
|
|
|
|
|
|
|
231
|
|
|
|
|
232
|
|
|
if ($custoFrete === false || $custoFrete === 0.0)
|
|
233
|
|
|
return false;
|
|
234
|
|
|
|
|
235
|
|
|
return $custoFrete + $shipping_cost;
|
|
236
|
|
|
}
|
|
237
|
|
|
|
|
238
|
|
|
/**
|
|
239
|
|
|
*
|
|
240
|
|
|
* @param type $params
|
|
241
|
|
|
* @return type
|
|
242
|
|
|
*/
|
|
243
|
|
|
public function getOrderShippingCostExternal($params) {
|
|
244
|
|
|
return $this->getOrderShippingCost($params, 0);
|
|
|
|
|
|
|
245
|
|
|
}
|
|
246
|
|
|
|
|
247
|
|
|
/**
|
|
248
|
|
|
*
|
|
249
|
|
|
* @param type $params
|
|
250
|
|
|
*/
|
|
251
|
|
|
public function hookupdateCarrier($params) {
|
|
|
|
|
|
|
252
|
|
|
|
|
253
|
|
|
}
|
|
254
|
|
|
|
|
255
|
|
|
/**
|
|
256
|
|
|
*
|
|
257
|
|
|
* @global type $smarty
|
|
258
|
|
|
* @param type $params
|
|
259
|
|
|
* @return type
|
|
260
|
|
|
*/
|
|
261
|
|
|
public function hookbeforeCarrier($params) {
|
|
262
|
|
|
global $smarty;
|
|
|
|
|
|
|
263
|
|
|
$address = new Address($params['cart']->id_address_delivery);
|
|
|
|
|
|
|
264
|
|
|
$smarty->assign(array(
|
|
265
|
|
|
"sCepDestino" => $address->postcode
|
|
266
|
|
|
));
|
|
267
|
|
|
return $this->display(__file__, 'extra_carrier.tpl');
|
|
|
|
|
|
|
268
|
|
|
}
|
|
269
|
|
|
|
|
270
|
|
|
/**
|
|
271
|
|
|
*
|
|
272
|
|
|
* @param type $params
|
|
273
|
|
|
*/
|
|
274
|
|
|
public function hookextraCarrier($params) {
|
|
|
|
|
|
|
275
|
|
|
|
|
276
|
|
|
}
|
|
277
|
|
|
|
|
278
|
|
|
/**
|
|
279
|
|
|
*
|
|
280
|
|
|
* @param type $params
|
|
281
|
|
|
* @return type
|
|
282
|
|
|
*/
|
|
283
|
|
|
private function getPriceWebService($params) {
|
|
284
|
|
|
$paramsBase = array(
|
|
285
|
|
|
"nCdEmpresa" => "",
|
|
286
|
|
|
"sDsSenha" => "",
|
|
287
|
|
|
"sCepOrigem" => str_pad(Configuration::get('PS_CORREIOS_CEP_ORIG'), 8, "0", STR_PAD_LEFT),
|
|
288
|
|
|
"nCdFormato" => "1",
|
|
289
|
|
|
"nVlComprimento" => "30",
|
|
290
|
|
|
"nVlAltura" => "8",
|
|
291
|
|
|
"nVlLargura" => "30",
|
|
292
|
|
|
"nVlDiametro" => "0",
|
|
293
|
|
|
"sCdMaoPropria" => "N",
|
|
294
|
|
|
"nVlValorDeclarado" => "0",
|
|
295
|
|
|
"sCdAvisoRecebimento" => "N"
|
|
296
|
|
|
);
|
|
297
|
|
|
$params = array_merge($paramsBase, $params);
|
|
298
|
|
|
$hash = ( implode("|", $params) );
|
|
299
|
|
|
$getInCache = $this->getCache($hash);
|
|
|
|
|
|
|
300
|
|
|
|
|
301
|
|
|
if ($getInCache) {
|
|
302
|
|
|
$return = $getInCache;
|
|
303
|
|
|
} else {
|
|
304
|
|
|
$this->_factory = Configuration::get("PS_CORREIOS_FACTORY");
|
|
305
|
|
|
$method = "getPreco" . ucfirst(strtolower($this->_factory));
|
|
306
|
|
|
|
|
307
|
|
|
$return = $this->$method($params, $hash);
|
|
308
|
|
|
$this->setCache($hash, $return);
|
|
|
|
|
|
|
309
|
|
|
}
|
|
310
|
|
|
return $return;
|
|
311
|
|
|
}
|
|
312
|
|
|
|
|
313
|
|
|
/**
|
|
314
|
|
|
*
|
|
315
|
|
|
* @global type $smarty
|
|
316
|
|
|
* @param type $idCarrier
|
|
317
|
|
|
* @param type $sCepDestino
|
|
318
|
|
|
* @return type
|
|
319
|
|
|
*/
|
|
320
|
|
|
public function getPrazoDeEntrega($idCarrier, $sCepDestino) {
|
|
321
|
|
|
global $smarty;
|
|
|
|
|
|
|
322
|
|
|
$Carrier = new Carrier($idCarrier);
|
|
|
|
|
|
|
323
|
|
|
|
|
324
|
|
|
$params = array(
|
|
325
|
|
|
"sCepOrigem" => str_pad(Configuration::get('PS_CORREIOS_CEP_ORIG'), 8, "0", STR_PAD_LEFT),
|
|
326
|
|
|
"nCdServico" => Configuration::get("PS_CORREIOS_CARRIER_{$idCarrier}"),
|
|
327
|
|
|
"sCepDestino" => $sCepDestino,
|
|
328
|
|
|
);
|
|
329
|
|
|
|
|
330
|
|
|
$this->_factory = Configuration::get("PS_CORREIOS_FACTORY");
|
|
331
|
|
|
$method = "getPrazo" . ucfirst(strtolower($this->_factory));
|
|
332
|
|
|
$dias = $this->$method($params);
|
|
333
|
|
|
|
|
334
|
|
|
$smarty->assign(array(
|
|
335
|
|
|
"nomeServico" => $Carrier->name,
|
|
|
|
|
|
|
336
|
|
|
"dias" => $dias
|
|
337
|
|
|
));
|
|
338
|
|
|
|
|
339
|
|
|
return $this->display(__file__, 'prazo_de_entrega.tpl');
|
|
|
|
|
|
|
340
|
|
|
}
|
|
341
|
|
|
|
|
342
|
|
|
private function getPrazoSoapclient($params) {
|
|
343
|
|
|
try {
|
|
344
|
|
|
$client = new SoapClient($this->_urlWebservice);
|
|
345
|
|
|
$result = $client->CalcPrazo($params);
|
|
346
|
|
|
if (intval($result->CalcPrazoResult->Servicos->cServico->Erro) !== 0)
|
|
347
|
|
|
return false;
|
|
348
|
|
|
else
|
|
349
|
|
|
return (integer) $result->CalcPrazoResult->Servicos->cServico->PrazoEntrega;
|
|
350
|
|
|
} catch (Exception $e) {
|
|
351
|
|
|
return false;
|
|
352
|
|
|
}
|
|
353
|
|
|
}
|
|
354
|
|
|
|
|
355
|
|
|
private function getPrazoNusoap($params) {
|
|
356
|
|
|
require_once('vendor/lib/nusoap.php');
|
|
357
|
|
|
$nusoap = new nusoap_client($this->_urlWebservice, 'wsdl');
|
|
358
|
|
|
$nusoap->setUseCURL(true);
|
|
359
|
|
|
$result = $nusoap->call("CalcPrazo", $params);
|
|
360
|
|
|
if (intval($result['CalcPrazoResult']['Servicos']['cServico']['Erro']) !== 0) {
|
|
361
|
|
|
return false;
|
|
362
|
|
|
} else {
|
|
363
|
|
|
return (integer) str_replace(",", ".", $result['CalcPrazoResult']['Servicos']['cServico']['PrazoEntrega']);
|
|
364
|
|
|
}
|
|
365
|
|
|
}
|
|
366
|
|
|
|
|
367
|
|
|
/**
|
|
368
|
|
|
*
|
|
369
|
|
|
* @param type $name
|
|
370
|
|
|
* @param type $value
|
|
371
|
|
|
*/
|
|
372
|
|
|
private function setCache($name, $value) {
|
|
373
|
|
|
if (_PS_CACHE_ENABLED_)
|
|
374
|
|
|
Cache::getInstance()->setQuery($name, $value);
|
|
375
|
|
|
}
|
|
376
|
|
|
|
|
377
|
|
|
/**
|
|
378
|
|
|
*
|
|
379
|
|
|
* @param type $name
|
|
380
|
|
|
* @return boolean
|
|
381
|
|
|
*/
|
|
382
|
|
|
private function getCache($name) {
|
|
383
|
|
|
if (_PS_CACHE_ENABLED_)
|
|
384
|
|
|
return Cache::getInstance()->get(md5($name));
|
|
385
|
|
|
return false;
|
|
386
|
|
|
}
|
|
387
|
|
|
|
|
388
|
|
|
/**
|
|
389
|
|
|
*
|
|
390
|
|
|
* @param type $params
|
|
391
|
|
|
* @param type $hash
|
|
392
|
|
|
* @return boolean
|
|
393
|
|
|
*/
|
|
394
|
|
|
private function getPrecoSoapclient($params, $hash) {
|
|
395
|
|
|
try {
|
|
396
|
|
|
$client = new SoapClient($this->_urlWebservice);
|
|
397
|
|
|
} catch (Exception $e) {
|
|
398
|
|
|
return false;
|
|
399
|
|
|
}
|
|
400
|
|
|
$result = $client->CalcPreco($params);
|
|
401
|
|
|
var_dump ($result);
|
|
|
|
|
|
|
402
|
|
|
if (intval($result->CalcPrecoResult->Servicos->cServico->Erro) !== 0) {
|
|
403
|
|
|
$this->setCache($hash, false);
|
|
|
|
|
|
|
404
|
|
|
return false;
|
|
405
|
|
|
} else {
|
|
406
|
|
|
return (float) str_replace(",", ".", $result->CalcPrecoResult->Servicos->cServico->Valor);
|
|
407
|
|
|
}
|
|
408
|
|
|
}
|
|
409
|
|
|
|
|
410
|
|
|
/**
|
|
411
|
|
|
*
|
|
412
|
|
|
* @param type $params
|
|
413
|
|
|
* @param type $hash
|
|
414
|
|
|
* @return boolean
|
|
415
|
|
|
*/
|
|
416
|
|
|
private function getPrecoNusoap($params, $hash) {
|
|
417
|
|
|
require_once('vendor/lib/nusoap.php');
|
|
418
|
|
|
$nusoap = new nusoap_client($this->_urlWebservice, 'wsdl');
|
|
419
|
|
|
$nusoap->setUseCURL(true);
|
|
420
|
|
|
$result = $nusoap->call("CalcPreco", $params);
|
|
421
|
|
|
if (intval($result['CalcPrecoResult']['Servicos']['cServico']['Erro']) !== 0) {
|
|
422
|
|
|
$this->setCache($hash, false);
|
|
|
|
|
|
|
423
|
|
|
return false;
|
|
424
|
|
|
} else {
|
|
425
|
|
|
return (float) str_replace(",", ".", $result['CalcPrecoResult']['Servicos']['cServico']['Valor']);
|
|
426
|
|
|
}
|
|
427
|
|
|
}
|
|
428
|
|
|
|
|
429
|
|
|
}
|
|
430
|
|
|
|
|
431
|
|
|
?>
|
|
|
|
|
|
|
432
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.