-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvmetiquetas.php
223 lines (194 loc) · 10.6 KB
/
vmetiquetas.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<?php
/**
* $Id: vmetiquetas.php 1.0.0 2013-06-24 05:39:14 Luiz Weber $
* @package Joomla!
* @subpackage vmetiquetas
* @version 1.0.0
* @description VM Template Override
* @copyright Copyright © 2013 - Weber TI All rights reserved.
* @license GNU General Public License v2.0
* @author Luiz Felipe Weber
* @author mail virtuemartpro@gmail.com
* @website http://virtuemartpro.com.br
*
*
* The events triggered in Joomla!
* -------------------------------
* onAfterInitialise()
* onAfterRoute()
* onAfterDispatch()
* onAfterRender()
*
*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.plugin.plugin' );
/**
* Example System Plugin
*
* @package Joomla!
* @subpackage Webservice VM Teste
* @class plgSystemWebservicevmteste
* @since 1.5
*/
class plgSystemVmetiquetas extends JPlugin {
/**
* Constructor
*
* For php4 compatability we must not use the __constructor as a constructor for plugins
* because func_get_args ( void ) returns a copy of all passed arguments NOT references.
* This causes problems with cross-referencing necessary for the observer design pattern.
*
* @access protected
* @param object $subject The object to observe
*/
function plgSystemVmetiquetas( &$subject, $config ) {
parent::__construct( $subject, $config );
}
function onAfterRoute() {
jimport( 'joomla.application.component.view' );
$app = JFactory::getApplication();
$doc = JFactory::getDocument();
$option = JRequest::getVar('option');
$view = JRequest::getVar('view');
$layout = JRequest::getVar('layout');
$task = JRequest::getVar('task');
if(!$app->isAdmin()) {
if (!class_exists( 'ShopFunctions' )) require(JPATH_ADMINISTRATOR.DIRECTORY_SEPARATOR.'components'.DIRECTORY_SEPARATOR.'com_virtuemart'.DIRECTORY_SEPARATOR.'helpers'.DIRECTORY_SEPARATOR.'shopfunctions.php');
if (!class_exists( 'VmConfig' )) require(JPATH_ADMINISTRATOR.DIRECTORY_SEPARATOR.'components'.DIRECTORY_SEPARATOR.'com_virtuemart'.DIRECTORY_SEPARATOR.'helpers'.DIRECTORY_SEPARATOR.'config.php');
if (!class_exists( 'VmModel' )) require(JPATH_ADMINISTRATOR.DIRECTORY_SEPARATOR.'components'.DIRECTORY_SEPARATOR.'com_virtuemart'.DIRECTORY_SEPARATOR.'helpers'.DIRECTORY_SEPARATOR.'vmmodel.php');
if (!class_exists('VmPdf')) require(JPATH_VM_SITE.DIRECTORY_SEPARATOR.'helpers'.DIRECTORY_SEPARATOR.'vmpdf.php');
// index.php?option=com_virtuemart&view=invoice&layout=deliverynote&format=pdf&tmpl=component
// &virtuemart_order_id=7&order_number=7&order_pass=p_7031e&create_invoice=1
// ini_set('display_errors',true);
// error_reporting(E_ALL);
//if ($option == 'com_virtuemart' and $view == 'invoice' and $layout == 'deliverynote' and $create_invoice == '1') {
if ($option == 'com_virtuemart' and $view == 'invoice' and $layout == 'deliverynote' ) {
$virtuemart_order_id = JRequest::getVar('virtuemart_order_id');
$order_number = JRequest::getVar('order_number');
$order_pass = JRequest::getVar('order_pass');
// recupera a configuração do vm do template
$config = VmConfig::loadConfig();
$doc->setBuffer('','component');
$url = 'http://www2.correios.com.br/enderecador/encomendas/act/gerarEtiqueta.cfm?etq=1';
$orders = VmModel::getModel('orders');
$order = $orders->getOrder($virtuemart_order_id);
$orderDetails = $order['details'];
$vendor = VmModel::getModel('vendor');
$userId = $vendor->getUserIdByVendorId($orderDetails['BT']->virtuemart_vendor_id);
$usermodel = VmModel::getModel('user');
$virtuemart_userinfo_id = $usermodel->getBTuserinfo_id($userId);
$vendorAddress = $usermodel->getUserAddressList($userId, 'BT', $virtuemart_userinfo_id);
$cep_vendedor = str_replace(array('-',' ','.'),array('','',''),$vendorAddress[0]->zip);
$cep_cliente = str_replace(array('-',' ','.'),array('','',''),$orderDetails['BT']->zip);
$estado_vendedor = ShopFunctions::getStateByID($vendorAddress[0]->virtuemart_state_id, "state_2_code");
$estado_cliente = ShopFunctions::getStateByID($vendorAddress[0]->virtuemart_state_id, "state_2_code");
$campo_numero = $this->params->get('campo_numero','');
$campo_bairro = $this->params->get('campo_bairro','');
$campo_complemento = $this->params->get('campo_complemento','');
$data = array(
'controle' => '',
'to' => '2',
'tipoImpressao' => '1',
'tipo_cep_1' => '2',
'cep_1' => utf8_decode($cep_vendedor),
'cep_teste_1' => utf8_decode($cep_vendedor),
'nome_1' => utf8_decode($vendorAddress[0]->first_name.' '.$vendorAddress[0]->last_name),
'empresa_1' => utf8_decode($vendorAddress[0]->company),
'endereco_1' => utf8_decode($vendorAddress[0]->address_1),
'numero_1' => (isset($vendorAddress[0]->$campo_numero)?utf8_decode($vendorAddress[0]->$campo_numero):''),
'complemento_1' => (isset($vendorAddress[0]->$campo_complemento)?utf8_decode($vendorAddress[0]->$campo_complemento):''),
'bairro_1' => (isset($vendorAddress[0]->$campo_bairro)?utf8_decode($vendorAddress[0]->$campo_bairro):''),
'cidade_1' => utf8_decode($vendorAddress[0]->city),
'uf_1' => utf8_decode($estado_vendedor),
'selUf_1' => utf8_decode($estado_vendedor),
'telefone_1' => utf8_decode($vendorAddress[0]->phone_1),
'desTipo_cep_1' => '2',
'desCep_teste_1' => utf8_decode($cep_cliente),
'desCep_1' => utf8_decode($cep_cliente),
'desNome_1' => utf8_decode($orderDetails['BT']->first_name.' '.$orderDetails['BT']->last_name),
'desEmpresa_1' => utf8_decode($orderDetails['BT']->company),
'desEndereco_1' => utf8_decode($orderDetails['BT']->address_1),
'desNumero_1' => (isset($orderDetails['BT']->$campo_numero)?utf8_decode($orderDetails['BT']->$campo_numero):''),
'desComplemento_1' => (isset($orderDetails['BT']->$campo_complemento)?utf8_decode($orderDetails['BT']->$campo_complemento):''),
'desBairro_1' => (isset($orderDetails['BT']->$campo_bairro)?utf8_decode($orderDetails['BT']->$campo_bairro):''),
'desCidade_1' => utf8_decode($orderDetails['BT']->city),
'desUf_1' => utf8_decode($estado_cliente),
'selDesUf_1' => utf8_decode($estado_cliente),
'desTelefone_1' => utf8_decode($orderDetails['BT']->phone_1),
'desDC_1' => 'Pedido N. '.$orderDetails['BT']->order_number,
'desCep_2' => '',
'tipo_cep_2' => '',
'cep_teste_2' => '',
'nome_2' => '',
'empresa_2' => '',
'endereco_2' => '',
'numero_2' => '',
'complemento_2' => '',
'bairro_2' => '',
'cidade_2' => '',
'uf_2' => '',
'selUf_2' => '',
'telefone_2' => '',
'desTipo_cep_2' => '',
'desCep_teste_2' => '',
'cep_2' => '',
'desNome_2' => '',
'desEmpresa_2' => '',
'desEndereco_2' => '',
'desNumero_2' => '',
'desComplemento_2' => '',
'desBairro_2' => '',
'desCidade_2' => '',
'desUf_2' => '',
'selDesUf_2' => '',
'desTelefone_2' => '',
'desDC_2' => '',
);
echo "<form action='".$url."' method='post' name='form_etiqueta'>";
foreach ($data as $key => $value) {
echo '<input type="hidden" name="'.$key.'" value="'.$value.'" />';
}
echo "</form>
<script language='javascript'>document.form_etiqueta.submit();</script>";
// if (function_exists('curl_exec')) {
// $ch = curl_init();
// $timeout = 0; // set to zero for no timeout
// curl_setopt($ch, CURLOPT_URL, $url);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
// curl_setopt($ch, CURLOPT_POST, true);
// curl_setopt($ch, CURLOPT_POSTFIELDIRECTORY_SEPARATOR, $data);
// $conteudo_etiqueta = curl_exec($ch);
// } else {
// $conteudo_etiqueta = file_get_contents($url);
// }
// $conteudo_etiqueta = str_replace(
// array(
// 'src="',
// ' onLoad="window.focus(); abrirAjuda();"',
// ),
// array(
// 'src="http://www2.correios.com.br/enderecador/encomendas/act/',
// ''
// ),
// $conteudo_etiqueta
// );
// $conteudo_etiqueta = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $conteudo_etiqueta);
// $conteudo_etiqueta = preg_replace('#<style(.*?)>(.*?)</style>#is', '', $conteudo_etiqueta);
// ob_start();
// ob_end_clean();
// // gera o pdf da etiqueta
/*
$pdf = new VmVendorPDF();
$pdf->AddPage();
$pdf->PrintContents($conteudo_etiqueta);
$pdf->Output("etiqueta_correios_".$orderDetails['BT']->order_number.".pdf", 'I');
echo ($conteudo_etiqueta);
*/
JFactory::getApplication()->close();
}
}
}
}
?>