Version Notes
First release version.
Download this release
Release Info
Developer | Magento Core Team |
Extension | ENVIALIA_Shipping |
Version | 1.0.0 |
Comparing to | |
See all releases |
Version 1.0.0
- app/code/local/ENVIALIA/ENVIALIAShipping/Adminhtml/Block/Sales/Order/Shipment/View.php +61 -0
- app/code/local/ENVIALIA/ENVIALIAShipping/Model/ENVIALIA/ENVIALIAShipping.php +649 -0
- app/code/local/ENVIALIA/ENVIALIAShipping/Model/ENVIALIA/Shipment.php +303 -0
- app/code/local/ENVIALIA/ENVIALIAShipping/Model/ENVIALIA/Shipment/Track.php +131 -0
- app/code/local/ENVIALIA/ENVIALIAShipping/Model/ENVIALIA/Source/Gratuito.php +26 -0
- app/code/local/ENVIALIA/ENVIALIAShipping/Model/ENVIALIA/Source/GratuitoInternacional.php +26 -0
- app/code/local/ENVIALIA/ENVIALIAShipping/Model/ENVIALIA/Source/Manipulacion.php +26 -0
- app/code/local/ENVIALIA/ENVIALIAShipping/envialia.tarifas.csv +3133 -0
- app/code/local/ENVIALIA/ENVIALIAShipping/etc/config.xml +76 -0
- app/code/local/ENVIALIA/ENVIALIAShipping/etc/config.xml~ +76 -0
- app/code/local/ENVIALIA/ENVIALIAShipping/etc/system.xml +268 -0
- app/etc/modules/ENVIALIA_ENVIALIAShipping.xml +9 -0
- package.xml +28 -0
app/code/local/ENVIALIA/ENVIALIAShipping/Adminhtml/Block/Sales/Order/Shipment/View.php
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class ENVIALIA_ENVIALIAShipping_Adminhtml_Block_Sales_Order_Shipment_View extends Mage_Adminhtml_Block_Sales_Order_Shipment_View
|
3 |
+
{
|
4 |
+
public function __construct()
|
5 |
+
{
|
6 |
+
|
7 |
+
parent::__construct();
|
8 |
+
|
9 |
+
$url = Mage::helper('core/url')->getCurrentUrl();
|
10 |
+
$trozos = split("/",$url);
|
11 |
+
$max = count($trozos);
|
12 |
+
for($i=0;$i<$max;$i++){
|
13 |
+
if($trozos[$i] == 'etiquetaenvialia'){
|
14 |
+
$this->printLabel();
|
15 |
+
}
|
16 |
+
}
|
17 |
+
/** creo un boton Etiqueta ENVIALIA */
|
18 |
+
if ($this->getShipment()->getId()) {
|
19 |
+
$this->_addButton('labelENVIALIA', array(
|
20 |
+
'label' => Mage::helper('sales')->__('Etiqueta ENVIALIA'),
|
21 |
+
'onclick' => 'window.open(\''.$this->getLabelENVIALIAUrl().'\')'
|
22 |
+
)
|
23 |
+
);
|
24 |
+
}
|
25 |
+
}
|
26 |
+
|
27 |
+
|
28 |
+
public function getLabelENVIALIAUrl()
|
29 |
+
{
|
30 |
+
$url='';
|
31 |
+
foreach ($this->getShipment()->getAllTracks() as $track )
|
32 |
+
{
|
33 |
+
if ($track->getCarrierCode()=='ENVIALIAShipping')
|
34 |
+
{
|
35 |
+
$url = Mage::helper('core/url')->getCurrentUrl();
|
36 |
+
$url = $url."etiquetaenvialia/";
|
37 |
+
|
38 |
+
}
|
39 |
+
}
|
40 |
+
return $url;
|
41 |
+
}
|
42 |
+
public function printLabel(){
|
43 |
+
if($this->getShipment()->getShippingLabel()){
|
44 |
+
$pdf=base64_decode($this->getShipment()->getShippingLabel());
|
45 |
+
$numero_pedido=$this->getShipment()->getIncrementId();
|
46 |
+
|
47 |
+
header("Content-type: application/pdf");
|
48 |
+
header('Content-Disposition: attachment; filename="etiqueta_'.$numero_pedido.'.pdf"'); //solo para forzar descarga
|
49 |
+
|
50 |
+
echo $pdf;
|
51 |
+
}
|
52 |
+
else{
|
53 |
+
header("Content-type: text/html");
|
54 |
+
header('Content-Disposition: attachment; filename="etiqueta_'.$numero_pedido.'.html"'); //solo para forzar descarga
|
55 |
+
|
56 |
+
echo "<html><head><title>Envialia Etiqueta</title></head><body><h2>No existe la etiqueta para imprimir.</h2></body></html>";
|
57 |
+
|
58 |
+
}
|
59 |
+
}
|
60 |
+
|
61 |
+
}
|
app/code/local/ENVIALIA/ENVIALIAShipping/Model/ENVIALIA/ENVIALIAShipping.php
ADDED
@@ -0,0 +1,649 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class ENVIALIA_ENVIALIAShipping_Model_ENVIALIA_ENVIALIAShipping extends Mage_Shipping_Model_Carrier_Abstract
|
3 |
+
{
|
4 |
+
protected $_code = 'ENVIALIAShipping';
|
5 |
+
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
|
6 |
+
{
|
7 |
+
/** Si no esta activo, no sigo */
|
8 |
+
if (!$this->getConfigFlag('active')) {
|
9 |
+
return false;
|
10 |
+
}
|
11 |
+
|
12 |
+
$err = null;
|
13 |
+
|
14 |
+
/** DATOS DE LA TIENDA */
|
15 |
+
if (!$request->getOrig()) {
|
16 |
+
$request
|
17 |
+
->setCountryId(Mage::getStoreConfig('shipping/origin/country_id', $request->getStore()))
|
18 |
+
->setPostcode(Mage::getStoreConfig('shipping/origin/postcode', $request->getStore()));
|
19 |
+
}
|
20 |
+
$peso_pedido = $request->getPackageWeight();
|
21 |
+
$envio["bultos"] = 1;
|
22 |
+
$total = $request->getPackageValue(); // Precio total del pedido
|
23 |
+
|
24 |
+
$pais_cliente = $request->getDestCountryId();
|
25 |
+
$cp_cliente = $request->getDestPostcode();
|
26 |
+
|
27 |
+
$envialia_impuesto = 0;
|
28 |
+
//Verificamos si hay que agregar el impuesto
|
29 |
+
if($this->agregar_impuesto($pais_cliente)){
|
30 |
+
$envialia_impuesto = floatval($this->getConfigData('ENVIALIA_IMPUESTO'));
|
31 |
+
}
|
32 |
+
|
33 |
+
$result = Mage::getModel('shipping/rate_result');
|
34 |
+
// Verificamos si el cliente pertenece a España , Portugal o Andorra
|
35 |
+
if($pais_cliente == 'ES' || $pais_cliente == 'PT' || $pais_cliente == 'AD'){
|
36 |
+
|
37 |
+
// Primero comprobamos si hay servicio gratuito $this->getConfigData('')
|
38 |
+
if($this->getConfigData('ENVIALIA_HABILITAR_ENVIO_GRATUITO')){
|
39 |
+
// Comprobamos que superamos el importe minimo para envio gratuito
|
40 |
+
if($this->getConfigData('ENVIALIA_IMPORTE_MINIMO_ENVIO_GRATUITO') < $total){
|
41 |
+
if($this->getConfigData('ENVIALIA_SERVICIO_ENVIO_GRATUITO') == "E24"){
|
42 |
+
$tipo_servicio = "E24";
|
43 |
+
$servicio = "al día siguiente";
|
44 |
+
$importe = "GRATUITO";
|
45 |
+
|
46 |
+
}
|
47 |
+
if($this->getConfigData('ENVIALIA_SERVICIO_ENVIO_GRATUITO') == "E72"){
|
48 |
+
$tipo_servicio = "E72";
|
49 |
+
$servicio = "máximo tres días";
|
50 |
+
$importe = "GRATUITO";
|
51 |
+
}
|
52 |
+
|
53 |
+
$rate = Mage::getModel('shipping/rate_result_method');
|
54 |
+
$rate->setCarrier($this->_code);
|
55 |
+
$rate->setCarrierTitle($this->getConfigData('title'));
|
56 |
+
$rate->setMethod($tipo_servicio);
|
57 |
+
$rate->setMethodTitle('<img src="http://www.envialia-urgente.com/images/envialia_ecomm_int_mag.png">'.' servicio de entrega GRATUITO '.$servicio);
|
58 |
+
$rate->setCost('0');
|
59 |
+
$rate->setPrice('0');
|
60 |
+
$result->append($rate);
|
61 |
+
|
62 |
+
return $result;
|
63 |
+
}
|
64 |
+
}
|
65 |
+
|
66 |
+
// No hay servicio gratuito
|
67 |
+
$html='';
|
68 |
+
$impuesto = 0;
|
69 |
+
$coste_envio = 0;
|
70 |
+
$importe = 0;
|
71 |
+
$coste_fijo_envio = 0;
|
72 |
+
$coste_manipulacion = 0;
|
73 |
+
$coste_margen = 0;
|
74 |
+
$tarifas = $this->tarifas();
|
75 |
+
if(!$tarifas){
|
76 |
+
$error = Mage::getModel('shipping/rate_result_error');
|
77 |
+
$error->setCarrier($this->_code);
|
78 |
+
$error->setCarrierTitle($this->getConfigData('title'));
|
79 |
+
$error->setErrorMessage('ENVIALIA ERROR: No se pudo cargar las tarifas.');
|
80 |
+
$result->append($error);
|
81 |
+
return $result;
|
82 |
+
}
|
83 |
+
|
84 |
+
if($this->getConfigData('ENVIALIA_COSTE_FIJO_ENVIO')){
|
85 |
+
$coste_fijo_envio = floatval($this->getConfigData('ENVIALIA_COSTE_FIJO_ENVIO'));
|
86 |
+
}
|
87 |
+
if($this->getConfigData('ENVIALIA_MANIPULACION') == 'F'){
|
88 |
+
$coste_manipulacion = floatval($this->getConfigData('ENVIALIA_COSTE_MANIPULACION'));
|
89 |
+
}
|
90 |
+
if($this->getConfigData('ENVIALIA_MANIPULACION') == 'V'){
|
91 |
+
$coste_manipulacion = floatval($total*($this->getConfigData('ENVIALIA_COSTE_MANIPULACION')/100));
|
92 |
+
}
|
93 |
+
if($this->getConfigData('ENVIALIA_MARGEN_COSTE_ENVIO')){
|
94 |
+
$coste_margen = floatval($this->getConfigData('ENVIALIA_MARGEN_COSTE_ENVIO'));
|
95 |
+
}
|
96 |
+
|
97 |
+
if($this->getConfigData('ENVIALIA_ECOMM_24H')){
|
98 |
+
$tipo_servicio = "E24";
|
99 |
+
$servicio = "al día siguiente";
|
100 |
+
$importe = 0;
|
101 |
+
$subimporte=0;
|
102 |
+
if($this->getConfigData('ENVIALIA_COSTE_FIJO_ENVIO')){
|
103 |
+
$subimporte=$coste_fijo_envio;
|
104 |
+
$coste_envio = $coste_fijo_envio+($coste_fijo_envio*$envialia_impuesto);
|
105 |
+
$importe = floatval($coste_envio+$coste_manipulacion);
|
106 |
+
}
|
107 |
+
else{
|
108 |
+
//Si no hay coste_fijo buscamos en el csv el precio
|
109 |
+
//necesitamos el tipo_servicio, cp_cliente, pais y peso
|
110 |
+
$coste_envio = $this->dame_tarifa($tarifas, $tipo_servicio, $pais_cliente, $cp_cliente, $peso_pedido);
|
111 |
+
//Verificamos coste de envio
|
112 |
+
if(!$coste_envio){
|
113 |
+
$error = Mage::getModel('shipping/rate_result_error');
|
114 |
+
$error->setCarrier($this->_code);
|
115 |
+
$error->setCarrierTitle($this->getConfigData('title'));
|
116 |
+
$error->setErrorMessage('ENVIALIA ERROR: el país o el código postal son incorrectos, por favor revíselos a través de su cuenta de usuario registrado.');
|
117 |
+
$result->append($error);
|
118 |
+
return $result;
|
119 |
+
}
|
120 |
+
$subimporte=$coste_envio;
|
121 |
+
//Despues sumarle el MARGEN SOBRE COSTE DE ENVÍO
|
122 |
+
if($this->getConfigData('ENVIALIA_MARGEN_COSTE_ENVIO')){
|
123 |
+
$coste_envio=$coste_envio+(floatval($this->getConfigData('ENVIALIA_MARGEN_COSTE_ENVIO')));
|
124 |
+
}
|
125 |
+
$coste_envio = $coste_envio +($coste_envio*$envialia_impuesto);
|
126 |
+
$importe = floatval($coste_envio+$coste_manipulacion);
|
127 |
+
}
|
128 |
+
//formateamos el importe
|
129 |
+
$importe = number_format($importe,2,".","");
|
130 |
+
|
131 |
+
// Preparamos el HTML
|
132 |
+
$rate = Mage::getModel('shipping/rate_result_method');
|
133 |
+
$rate->setCarrier($this->_code);
|
134 |
+
$rate->setCarrierTitle($this->getConfigData('title'));
|
135 |
+
$rate->setMethod($tipo_servicio);
|
136 |
+
$rate->setMethodTitle('<img src="http://www.envialia-urgente.com/images/envialia_ecomm_24_mag.png">'.' servicio de entrega '.$servicio);
|
137 |
+
$rate->setCost($subimporte);
|
138 |
+
$rate->setPrice($importe);
|
139 |
+
$result->append($rate);
|
140 |
+
}
|
141 |
+
if($this->getConfigData('ENVIALIA_ECOMM_72H')){
|
142 |
+
$tipo_servicio = "E72";
|
143 |
+
$servicio = "máximo tres días";
|
144 |
+
$importe = 0;
|
145 |
+
$subimporte=0;
|
146 |
+
if($this->getConfigData('ENVIALIA_COSTE_FIJO_ENVIO')){
|
147 |
+
$subimporte=$coste_fijo_envio;
|
148 |
+
$coste_envio = $coste_fijo_envio+($coste_fijo_envio*$envialia_impuesto);
|
149 |
+
$importe = floatval($coste_envio+$coste_manipulacion);
|
150 |
+
}
|
151 |
+
else{
|
152 |
+
//Si no hay coste_fijo buscamos en el csv el precio
|
153 |
+
//necesitamos el tipo_servicio, cp_cliente, pais y peso
|
154 |
+
$coste_envio = $this->dame_tarifa($tarifas, $tipo_servicio, $pais_cliente, $cp_cliente, $peso_pedido);
|
155 |
+
//Verificamos coste de envio
|
156 |
+
if(!$coste_envio){
|
157 |
+
$error = Mage::getModel('shipping/rate_result_error');
|
158 |
+
$error->setCarrier($this->_code);
|
159 |
+
$error->setCarrierTitle($this->getConfigData('title'));
|
160 |
+
$error->setErrorMessage('ENVIALIA ERROR: el país o el código postal son incorrectos, por favor revíselos a través de su cuenta de usuario registrado.');
|
161 |
+
$result->append($error);
|
162 |
+
return $result;
|
163 |
+
}
|
164 |
+
$subimporte=$coste_envio;
|
165 |
+
//Despues sumarle el MARGEN SOBRE COSTE DE ENVÍO
|
166 |
+
if($this->getConfigData('ENVIALIA_MARGEN_COSTE_ENVIO')){
|
167 |
+
$coste_envio=$coste_envio+(floatval($this->getConfigData('ENVIALIA_MARGEN_COSTE_ENVIO')));
|
168 |
+
}
|
169 |
+
$coste_envio = $coste_envio +($coste_envio*$envialia_impuesto);
|
170 |
+
$importe = floatval($coste_envio+$coste_manipulacion);
|
171 |
+
}
|
172 |
+
//formateamos el importe
|
173 |
+
$importe = number_format($importe,2,".","");
|
174 |
+
|
175 |
+
// Preparamos el HTML
|
176 |
+
$rate = Mage::getModel('shipping/rate_result_method');
|
177 |
+
$rate->setCarrier($this->_code);
|
178 |
+
$rate->setCarrierTitle($this->getConfigData('title'));
|
179 |
+
$rate->setMethod($tipo_servicio);
|
180 |
+
$rate->setMethodTitle('<img src="http://www.envialia-urgente.com/images/envialia_ecomm_72_mag.png">'.' servicio de entrega '.$servicio);
|
181 |
+
$rate->setCost($subimporte);
|
182 |
+
$rate->setPrice($importe);
|
183 |
+
$result->append($rate);
|
184 |
+
}
|
185 |
+
return $result;
|
186 |
+
}
|
187 |
+
//Verificamos si el cliente es de EUROPA
|
188 |
+
else if($this->es_europeo($pais_cliente)){
|
189 |
+
// Primero comprobamos si hay servicio gratuito para EUROPA
|
190 |
+
// En Europa pueden usar tambien el INTERNACIONAL
|
191 |
+
if($this->getConfigData('ENVIALIA_HABILITAR_ENVIO_GRATUITO_INTERNACIONAL')){
|
192 |
+
// Comprobamos que superamos el importe minimo para envio gratuito
|
193 |
+
if($this->getConfigData('ENVIALIA_IMPORTE_MINIMO_ENVIO_GRATUITO_INTERNACIONAL') < $total){
|
194 |
+
if($this->getConfigData('ENVIALIA_SERVICIO_ENVIO_GRATUITO_INTERNACIONAL') == "EEU"){
|
195 |
+
$tipo_servicio = "EEU";
|
196 |
+
$servicio = "EUROPE EXPRESS";
|
197 |
+
$importe = "GRATUITO";
|
198 |
+
|
199 |
+
}
|
200 |
+
if($this->getConfigData('ENVIALIA_SERVICIO_ENVIO_GRATUITO_INTERNACIONAL') == "EWW"){
|
201 |
+
$tipo_servicio = "EWW";
|
202 |
+
$servicio = "WORLDWIDE";
|
203 |
+
$importe = "GRATUITO";
|
204 |
+
}
|
205 |
+
$rate = Mage::getModel('shipping/rate_result_method');
|
206 |
+
$rate->setCarrier($this->_code);
|
207 |
+
$rate->setCarrierTitle($this->getConfigData('title'));
|
208 |
+
$rate->setMethod($tipo_servicio);
|
209 |
+
$rate->setMethodTitle('<img src="http://www.envialia-urgente.com/images/envialia_ecomm_int_mag.png">'.' servicio de entrega GRATUITO '.$servicio);
|
210 |
+
$rate->setCost('0');
|
211 |
+
$rate->setPrice('0');
|
212 |
+
$result->append($rate);
|
213 |
+
|
214 |
+
return $result;
|
215 |
+
}
|
216 |
+
}
|
217 |
+
// No hay servicio gratuito Europeo o Internacional
|
218 |
+
$html='';
|
219 |
+
$impuesto = 0;
|
220 |
+
$subimporte=0;
|
221 |
+
$coste_envio = 0;
|
222 |
+
$importe = 0;
|
223 |
+
$coste_fijo_envio = 0;
|
224 |
+
$coste_manipulacion = 0;
|
225 |
+
$coste_margen = 0;
|
226 |
+
$tarifas = $this->tarifas();
|
227 |
+
|
228 |
+
//if(ENVIALIA_CLASE_IMPUESTO){$impuesto = $this->get_tax_rate();}
|
229 |
+
if($this->getConfigData('ENVIALIA_COSTE_FIJO_ENVIO')){$coste_fijo_envio = floatval($this->getConfigData('ENVIALIA_COSTE_FIJO_ENVIO'));}
|
230 |
+
if($this->getConfigData('ENVIALIA_MANIPULACION') == 'F'){$coste_manipulacion = floatval($this->getConfigData('ENVIALIA_COSTE_MANIPULACION'));}
|
231 |
+
if($this->getConfigData('ENVIALIA_MANIPULACION') == 'V'){$coste_manipulacion = floatval($total*($this->getConfigData('ENVIALIA_COSTE_MANIPULACION')/100));}
|
232 |
+
if($this->getConfigData('ENVIALIA_MARGEN_COSTE_ENVIO')){$coste_margen = floatval($this->getConfigData('ENVIALIA_MARGEN_COSTE_ENVIO'));}
|
233 |
+
|
234 |
+
if($this->getConfigData('ENVIALIA_ECOMM_EUROPE_EXPRESS')){
|
235 |
+
$tipo_servicio = "EEU";
|
236 |
+
$servicio = "EUROPE EXPRESS";
|
237 |
+
$importe = 0;
|
238 |
+
$subimporte=$coste_fijo_envio;
|
239 |
+
if($this->getConfigData('ENVIALIA_COSTE_FIJO_ENVIO')){
|
240 |
+
$coste_envio = $coste_fijo_envio+($coste_fijo_envio*$envialia_impuesto);
|
241 |
+
$importe = floatval($coste_envio+$coste_manipulacion);
|
242 |
+
}
|
243 |
+
else{
|
244 |
+
//Si no hay coste_fijo buscamos en el csv el precio
|
245 |
+
//necesitamos el tipo_servicio, cp_cliente, pais y peso
|
246 |
+
$coste_envio = $this->dame_tarifa($tarifas, $tipo_servicio, $pais_cliente, $cp_cliente, $peso_pedido);
|
247 |
+
//Verificamos coste de envio
|
248 |
+
if(!$coste_envio){
|
249 |
+
$error = Mage::getModel('shipping/rate_result_error');
|
250 |
+
$error->setCarrier($this->_code);
|
251 |
+
$error->setCarrierTitle($this->getConfigData('title'));
|
252 |
+
$error->setErrorMessage('ENVIALIA ERROR: el país o el código postal son incorrectos, por favor revíselos a través de su cuenta de usuario registrado.');
|
253 |
+
$result->append($error);
|
254 |
+
return $result;
|
255 |
+
}
|
256 |
+
//Despues sumarle el MARGEN SOBRE COSTE DE ENVÍO
|
257 |
+
if($this->getConfigData('ENVIALIA_MARGEN_COSTE_ENVIO')){
|
258 |
+
$coste_envio=$coste_envio+(floatval($this->getConfigData('ENVIALIA_MARGEN_COSTE_ENVIO')));
|
259 |
+
}
|
260 |
+
$subimporte=$coste_envio;
|
261 |
+
$coste_envio = $coste_envio +($coste_envio*$envialia_impuesto);
|
262 |
+
$importe = floatval($coste_envio+$coste_manipulacion);
|
263 |
+
}
|
264 |
+
//formateamos el importe
|
265 |
+
$importe = number_format($importe,2,".","");
|
266 |
+
|
267 |
+
// Preparamos el HTML
|
268 |
+
$rate = Mage::getModel('shipping/rate_result_method');
|
269 |
+
$rate->setCarrier($this->_code);
|
270 |
+
$rate->setCarrierTitle($this->getConfigData('title'));
|
271 |
+
$rate->setMethod($tipo_servicio);
|
272 |
+
$rate->setMethodTitle('<img src="http://www.envialia-urgente.com/images/envialia_ecomm_int_mag.png">'.' servicio de entrega terrestre '.$servicio);
|
273 |
+
$rate->setCost($subimporte);
|
274 |
+
$rate->setPrice($importe);
|
275 |
+
$result->append($rate);
|
276 |
+
|
277 |
+
}
|
278 |
+
if($this->getConfigData('ENVIALIA_ECOMM_WORLDWIDE')){
|
279 |
+
$tipo_servicio = "EWW";
|
280 |
+
$servicio = "WORLDWIDE";
|
281 |
+
$importe = 0;
|
282 |
+
$subimporte=0;
|
283 |
+
$subimporte=$coste_fijo_envio;
|
284 |
+
|
285 |
+
if($this->getConfigData('ENVIALIA_COSTE_FIJO_ENVIO')){
|
286 |
+
$importe = floatval($coste_fijo_envio+$coste_manipulacion);
|
287 |
+
}
|
288 |
+
else{
|
289 |
+
//Si no hay coste_fijo buscamos en el csv el precio
|
290 |
+
//necesitamos el tipo_servicio, cp_cliente, pais y peso
|
291 |
+
$coste_envio = $this->dame_tarifa($tarifas, $tipo_servicio, $pais_cliente, $cp_cliente, $peso_pedido);
|
292 |
+
//Verificamos coste de envio
|
293 |
+
if(!$coste_envio){
|
294 |
+
$error = Mage::getModel('shipping/rate_result_error');
|
295 |
+
$error->setCarrier($this->_code);
|
296 |
+
$error->setCarrierTitle($this->getConfigData('title'));
|
297 |
+
$error->setErrorMessage('ENVIALIA ERROR: el país o el código postal son incorrectos, por favor revíselos a través de su cuenta de usuario registrado.');
|
298 |
+
$result->append($error);
|
299 |
+
return $result;
|
300 |
+
}
|
301 |
+
$subimporte=$coste_envio;
|
302 |
+
//Despues sumarle el MARGEN SOBRE COSTE DE ENVÍO
|
303 |
+
if($this->getConfigData('ENVIALIA_MARGEN_COSTE_ENVIO')){
|
304 |
+
$coste_envio=$coste_envio+(floatval($this->getConfigData('ENVIALIA_MARGEN_COSTE_ENVIO')));
|
305 |
+
}
|
306 |
+
$importe = floatval($coste_envio+$coste_manipulacion);
|
307 |
+
}
|
308 |
+
//formateamos el importe
|
309 |
+
$importe = number_format($importe,2,".","");
|
310 |
+
|
311 |
+
// Preparamos el HTML
|
312 |
+
$rate = Mage::getModel('shipping/rate_result_method');
|
313 |
+
$rate->setCarrier($this->_code);
|
314 |
+
$rate->setCarrierTitle($this->getConfigData('title'));
|
315 |
+
$rate->setMethod($tipo_servicio);
|
316 |
+
$rate->setMethodTitle('<img src="http://www.envialia-urgente.com/images/envialia_ecomm_int_mag.png">'.' servicio de entrega aéreo '.$servicio);
|
317 |
+
$rate->setCost($subimporte);
|
318 |
+
$rate->setPrice($importe);
|
319 |
+
$result->append($rate);
|
320 |
+
}
|
321 |
+
return $result;
|
322 |
+
}
|
323 |
+
//Es INTERNACIONAL
|
324 |
+
else {
|
325 |
+
// Primero comprobamos si hay servicio gratuito INTERNACIONAL
|
326 |
+
if($this->getConfigData('ENVIALIA_HABILITAR_ENVIO_GRATUITO_INTERNACIONAL')){
|
327 |
+
// Comprobamos que superamos el importe minimo para envio gratuito
|
328 |
+
if($this->getConfigData('ENVIALIA_IMPORTE_MINIMO_ENVIO_GRATUITO_INTERNACIONAL') < $total){
|
329 |
+
if($this->getConfigData('ENVIALIA_SERVICIO_ENVIO_GRATUITO_INTERNACIONAL') == "EWW"){
|
330 |
+
$tipo_servicio = "EWW";
|
331 |
+
$servicio = "WORLDWIDE";
|
332 |
+
$importe = "GRATUITO";
|
333 |
+
|
334 |
+
$rate = Mage::getModel('shipping/rate_result_method');
|
335 |
+
$rate->setCarrier($this->_code);
|
336 |
+
$rate->setCarrierTitle($this->getConfigData('title'));
|
337 |
+
$rate->setMethod($tipo_servicio);
|
338 |
+
$rate->setMethodTitle('Envialia servicio de envio GRATUITO '.$servicio);
|
339 |
+
$rate->setCost('0');
|
340 |
+
$rate->setPrice('0');
|
341 |
+
$result->append($rate);
|
342 |
+
|
343 |
+
return $result;
|
344 |
+
}
|
345 |
+
}
|
346 |
+
}
|
347 |
+
// No hay servicio gratuito Internacional
|
348 |
+
$html='';
|
349 |
+
$impuesto = 0;
|
350 |
+
$coste_envio = 0;
|
351 |
+
$importe = 0;
|
352 |
+
$subimporte=0;
|
353 |
+
$coste_fijo_envio = 0;
|
354 |
+
$coste_manipulacion = 0;
|
355 |
+
$coste_margen = 0;
|
356 |
+
$tarifas = $this->tarifas();
|
357 |
+
|
358 |
+
if($this->getConfigData('ENVIALIA_COSTE_FIJO_ENVIO')){$coste_fijo_envio = floatval($this->getConfigData('ENVIALIA_COSTE_FIJO_ENVIO'));}
|
359 |
+
if($this->getConfigData('ENVIALIA_MANIPULACION') == 'F'){$coste_manipulacion = floatval($this->getConfigData('ENVIALIA_COSTE_MANIPULACION'));}
|
360 |
+
if($this->getConfigData('ENVIALIA_MANIPULACION') == 'V'){$coste_manipulacion = floatval($total*($this->getConfigData('ENVIALIA_COSTE_MANIPULACION')/100));}
|
361 |
+
if($this->getConfigData('ENVIALIA_MARGEN_COSTE_ENVIO')){$coste_margen = floatval($this->getConfigData('ENVIALIA_MARGEN_COSTE_ENVIO'));}
|
362 |
+
|
363 |
+
if($this->getConfigData('ENVIALIA_ECOMM_WORLDWIDE')){
|
364 |
+
$tipo_servicio = "EWW";
|
365 |
+
$servicio = "WORLDWIDE";
|
366 |
+
$importe = 0;
|
367 |
+
$subimporte=$coste_fijo_envio;
|
368 |
+
|
369 |
+
if($this->getConfigData('ENVIALIA_COSTE_FIJO_ENVIO')){
|
370 |
+
$importe = floatval($coste_fijo_envio+$coste_manipulacion);
|
371 |
+
}
|
372 |
+
else{
|
373 |
+
//Si no hay coste_fijo buscamos en el csv el precio
|
374 |
+
//necesitamos el tipo_servicio, cp_cliente, pais y peso
|
375 |
+
$coste_envio = $this->dame_tarifa($tarifas, $tipo_servicio, $pais_cliente, $cp_cliente, $peso_pedido);
|
376 |
+
//Verificamos coste de envio
|
377 |
+
if(!$coste_envio){
|
378 |
+
$error = Mage::getModel('shipping/rate_result_error');
|
379 |
+
$error->setCarrier($this->_code);
|
380 |
+
$error->setCarrierTitle($this->getConfigData('title'));
|
381 |
+
$error->setErrorMessage('ENVIALIA ERROR: el país o el código postal son incorrectos, por favor revíselos a través de su cuenta de usuario registrado.');
|
382 |
+
$result->append($error);
|
383 |
+
return $result;
|
384 |
+
}
|
385 |
+
$subimporte=$coste_envio;
|
386 |
+
//Despues sumarle el MARGEN SOBRE COSTE DE ENVÍO
|
387 |
+
if($this->getConfigData('ENVIALIA_MARGEN_COSTE_ENVIO')){
|
388 |
+
$coste_envio=$coste_envio+(floatval($this->getConfigData('ENVIALIA_MARGEN_COSTE_ENVIO')));
|
389 |
+
}
|
390 |
+
$importe = floatval($coste_envio+$coste_manipulacion);
|
391 |
+
}
|
392 |
+
//formateamos el importe
|
393 |
+
$importe = number_format($importe,2,".","");
|
394 |
+
// Preparamos el HTML
|
395 |
+
$rate = Mage::getModel('shipping/rate_result_method');
|
396 |
+
$rate->setCarrier($this->_code);
|
397 |
+
$rate->setCarrierTitle($this->getConfigData('title'));
|
398 |
+
$rate->setMethod($tipo_servicio);
|
399 |
+
$rate->setMethodTitle('<img src="http://www.envialia-urgente.com/images/envialia_ecomm_int_mag.png">'.' servicio de entrega aéreo '.$servicio);
|
400 |
+
$rate->setCost($subimporte);
|
401 |
+
$rate->setPrice($importe);
|
402 |
+
$result->append($rate);
|
403 |
+
return $result;
|
404 |
+
}
|
405 |
+
}
|
406 |
+
}
|
407 |
+
|
408 |
+
public function isTrackingAvailable()
|
409 |
+
{
|
410 |
+
return true;
|
411 |
+
}
|
412 |
+
|
413 |
+
public function getTrackingInfo($tracking_number)
|
414 |
+
{
|
415 |
+
$tracking_result = $this->getTracking($tracking_number);
|
416 |
+
if ($tracking_result instanceof Mage_Shipping_Model_Tracking_Result) {
|
417 |
+
$trackings = $tracking_result->getAllTrackings();
|
418 |
+
if ($trackings){ return $trackings[0]; }
|
419 |
+
}
|
420 |
+
elseif (is_string($tracking_result) && !empty($tracking_result)){
|
421 |
+
return $tracking_result;
|
422 |
+
}
|
423 |
+
else return false;
|
424 |
+
}
|
425 |
+
|
426 |
+
//Devuelve el tracking de un envio llamando al servicio web de ENVIALIA
|
427 |
+
protected function getTracking($tracking_number)
|
428 |
+
{
|
429 |
+
$envialia_num_tracking=$tracking_number;
|
430 |
+
$baseDatos = Mage::getSingleton('core/resource')->getConnection('core_write');
|
431 |
+
$resultado=$baseDatos->query("select updated_at from sales_flat_shipment_track where track_number='".$tracking_number."'");
|
432 |
+
$row = $resultado->fetch();
|
433 |
+
$envialia_fecha = $row['updated_at'];
|
434 |
+
//preparamos la fecha la obtenemos de updated_at
|
435 |
+
$envialia_fecha = substr($envialia_fecha,2,8); // AA/MM/DD
|
436 |
+
list($anyo,$mes,$dia) = explode("-",$envialia_fecha);
|
437 |
+
$envialia_fecha = $dia.'/'.$mes.'/'.$anyo;
|
438 |
+
|
439 |
+
// Primero de todo nos logueamos si esto falla todo lo demas no tiene sentido
|
440 |
+
$urlEnvialia = $this->getConfigData('ENVIALIA_URL');
|
441 |
+
$URL = $urlEnvialia."/soap";
|
442 |
+
|
443 |
+
$envialiaCodigoAgencia = $this->getConfigData('ENVIALIA_CODIGO_AGENCIA');
|
444 |
+
$envialiaCodigoCliente = $this->getConfigData('ENVIALIA_CODIGO_CLIENTE');
|
445 |
+
$envialiaPasswordCliente = $this->getConfigData('ENVIALIA_PASSWORD_CLIENTE');
|
446 |
+
|
447 |
+
$XML='<?xml version="1.0" encoding="utf-8"?>
|
448 |
+
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
449 |
+
<soap:Body>
|
450 |
+
<LoginWSService___LoginCli>
|
451 |
+
<strCodAge>'.$envialiaCodigoAgencia.'</strCodAge>
|
452 |
+
<strCod>'.$envialiaCodigoCliente.'</strCod>
|
453 |
+
<strPass>'.$envialiaPasswordCliente.'</strPass>
|
454 |
+
</LoginWSService___LoginCli>
|
455 |
+
</soap:Body>
|
456 |
+
</soap:Envelope>';
|
457 |
+
|
458 |
+
|
459 |
+
$ch = curl_init();
|
460 |
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
461 |
+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
462 |
+
curl_setopt($ch, CURLOPT_HEADER, FALSE);
|
463 |
+
curl_setopt($ch, CURLOPT_FORBID_REUSE, TRUE);
|
464 |
+
curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);
|
465 |
+
curl_setopt($ch, CURLOPT_URL, $URL );
|
466 |
+
curl_setopt($ch, CURLOPT_POSTFIELDS, $XML );
|
467 |
+
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
|
468 |
+
|
469 |
+
$postResult = curl_exec($ch);
|
470 |
+
|
471 |
+
if (curl_errno($ch)) {
|
472 |
+
Mage::throwException(
|
473 |
+
Mage::helper('sales')->__('No se pudo llamar al ws de ENVIALIA.')
|
474 |
+
);
|
475 |
+
}
|
476 |
+
|
477 |
+
|
478 |
+
$xml = simplexml_load_string($postResult, NULL, NULL, "http://http://www.w3.org/2003/05/soap-envelope");
|
479 |
+
$xml->registerXPathNamespace("abc","http://tempuri.org/");
|
480 |
+
// hay excepciones desde el WS
|
481 |
+
if($xml->xpath('//faultstring')){
|
482 |
+
foreach($xml->xpath('//faultstring') as $error){
|
483 |
+
Mage::log('ENVIALIA ERROR : '.$error);
|
484 |
+
Mage::throwException(Mage::helper('sales')->__('ENVIALIA ERROR : '.$error));
|
485 |
+
}
|
486 |
+
}
|
487 |
+
else{
|
488 |
+
foreach ($xml->xpath('//abc:strURLDetSegEnv') as $item)
|
489 |
+
{
|
490 |
+
$envialia_url_seguimiento=$item;
|
491 |
+
}
|
492 |
+
}
|
493 |
+
//ya tenemos los datos para la url de seguimiento la montamos
|
494 |
+
|
495 |
+
$cortar=split("\?",$envialia_url_seguimiento);
|
496 |
+
$envialia_url_seguimiento=$cortar[0];
|
497 |
+
|
498 |
+
$enlace=$envialia_url_seguimiento."?servicio=".$envialia_num_tracking."&fecha=".$envialia_fecha;
|
499 |
+
|
500 |
+
$tracking_result = Mage::getModel('shipping/tracking_result');
|
501 |
+
|
502 |
+
$msg = '<p><a href="'.$enlace.'">Click para ver el seguimiento del envio</a></p>';
|
503 |
+
|
504 |
+
|
505 |
+
$tracking_status = Mage::getModel('shipping/tracking_result_status');
|
506 |
+
$tracking_status->setCarrier($this->_code);
|
507 |
+
$tracking_status->setCarrierTitle('<a target="_blank" href="http://www.envialia-urgente.com">' .$this->getConfigData('title'). '<a>');
|
508 |
+
$tracking_status->setTracking($tracking_number);
|
509 |
+
$tracking_status->addData(
|
510 |
+
array( 'status'=>$msg )
|
511 |
+
);
|
512 |
+
|
513 |
+
$tracking_result->append($tracking_status);
|
514 |
+
return $tracking_result;
|
515 |
+
}
|
516 |
+
|
517 |
+
|
518 |
+
function agregar_impuesto($pais){
|
519 |
+
|
520 |
+
$paises = Array("AT","BE","BG","CC","CY","CZ","DK","EE","FI",
|
521 |
+
"FR","DE","GR","HU","IE","IT","LV","LT","LU",
|
522 |
+
"MT","NL","PL","PT","RO","SK","SI","ES","SE","GB");
|
523 |
+
$max=count($paises);
|
524 |
+
for($i=0;$i<$max;$i++){
|
525 |
+
if($pais == $paises[$i]){
|
526 |
+
return true;
|
527 |
+
}
|
528 |
+
}
|
529 |
+
return false;
|
530 |
+
}
|
531 |
+
protected function tarifas(){
|
532 |
+
$archivo = getcwd().'/app/code/local/ENVIALIA/ENVIALIAShipping/'.'envialia.tarifas.csv';
|
533 |
+
$tarifas = Array();
|
534 |
+
|
535 |
+
if($fp = fopen ( $archivo , "r" )){
|
536 |
+
while (( $data = fgetcsv ( $fp , 1000 , ";" )) !== FALSE ) { // Mientras hay líneas que leer...
|
537 |
+
$tarifas[] = Array( "servicio" => $data[0],
|
538 |
+
"pais" => $data[1],
|
539 |
+
"cp_origen" => $data[2],
|
540 |
+
"cp_destino" => $data[3],
|
541 |
+
"peso" => $data[4],
|
542 |
+
"importe" => $data[5]);
|
543 |
+
}
|
544 |
+
fclose ( $fp );
|
545 |
+
return $tarifas;
|
546 |
+
}
|
547 |
+
else{
|
548 |
+
return false;
|
549 |
+
}
|
550 |
+
}
|
551 |
+
|
552 |
+
function dame_tarifa($tarifas,$servicio,$pais,$cp,$peso){
|
553 |
+
$max=count($tarifas);
|
554 |
+
$cp=intval($cp);
|
555 |
+
$peso=ceil($peso); //redondeo para arriba
|
556 |
+
$segmento = Array();
|
557 |
+
|
558 |
+
for($i=1;$i<$max;$i++){
|
559 |
+
// Si es un envio para ES-PT-AD
|
560 |
+
if($servicio == 'E24' || $servicio == 'E72'){
|
561 |
+
if($tarifas[$i]['servicio'] == $servicio){
|
562 |
+
if($tarifas[$i]['pais'] == $pais){
|
563 |
+
$cp_origen=intval($tarifas[$i]['cp_origen']);
|
564 |
+
$cp_destino=intval($tarifas[$i]['cp_destino']);
|
565 |
+
if($cp >= $cp_origen){
|
566 |
+
if($cp <= $cp_destino){
|
567 |
+
$segmento[]=Array("peso" => floatval($tarifas[$i]['peso']),"precio" => floatval($tarifas[$i]['importe']));
|
568 |
+
}
|
569 |
+
}
|
570 |
+
}
|
571 |
+
}
|
572 |
+
}
|
573 |
+
//Servico Europeo o Internacional
|
574 |
+
else{
|
575 |
+
if($tarifas[$i]['servicio'] == $servicio){
|
576 |
+
if($tarifas[$i]['pais'] == $pais){
|
577 |
+
$segmento[]=Array("peso" => floatval($tarifas[$i]['peso']),"precio" => floatval($tarifas[$i]['importe']));
|
578 |
+
}
|
579 |
+
}
|
580 |
+
}
|
581 |
+
}
|
582 |
+
// ya tenemos el segmento
|
583 |
+
|
584 |
+
// Metodo para ordenar arrays con arrays asociativos dentro
|
585 |
+
if(!function_exists('ordenar')){
|
586 |
+
function ordenar($x, $y){
|
587 |
+
if ( $x['peso'] == $y['peso'] ){
|
588 |
+
return 0;
|
589 |
+
}
|
590 |
+
//ordenar de menor a mayor
|
591 |
+
else if ( $x['peso'] < $y['peso'] ){
|
592 |
+
return -1;
|
593 |
+
}
|
594 |
+
else{
|
595 |
+
return 1;
|
596 |
+
}
|
597 |
+
}
|
598 |
+
}
|
599 |
+
|
600 |
+
// Ordenamos el segmento
|
601 |
+
usort($segmento,'ordenar');
|
602 |
+
// Preparamos los datos para el peso minimo y maximo
|
603 |
+
$precio_envio = 0;
|
604 |
+
$max=count($segmento);
|
605 |
+
$peso_min = floatval($segmento[0]['peso']);
|
606 |
+
$precio_min = floatval($segmento[0]['precio']);
|
607 |
+
$peso_max = floatval($segmento[$max-2]['peso']);
|
608 |
+
$precio_max = floatval($segmento[$max-2]['precio']);
|
609 |
+
$precio_despues_max = floatval($segmento[$max-1]['precio']);
|
610 |
+
|
611 |
+
if($peso <= $peso_min){
|
612 |
+
$precio_envio = $precio_min;
|
613 |
+
}
|
614 |
+
else if($peso >= $peso_max){
|
615 |
+
$peso_restante = $peso-$peso_max;
|
616 |
+
$precio_restante = $peso_restante*$precio_despues_max;
|
617 |
+
$precio_envio = $precio_max+$precio_restante;
|
618 |
+
}
|
619 |
+
else{
|
620 |
+
for($i=0;$i<$max;$i++){
|
621 |
+
if($peso != $segmento[$i]['peso']){
|
622 |
+
if($peso < $segmento[$i]['peso']){
|
623 |
+
$precio_envio = $segmento[$i]['precio'];
|
624 |
+
$i=$max;
|
625 |
+
}
|
626 |
+
}
|
627 |
+
else{ //es igual
|
628 |
+
$precio_envio = $segmento[$i]['precio'];
|
629 |
+
$i=$max;
|
630 |
+
}
|
631 |
+
}
|
632 |
+
}
|
633 |
+
return $precio_envio;
|
634 |
+
}
|
635 |
+
|
636 |
+
function es_europeo($pais){
|
637 |
+
$paises = Array("DE","AT","BE","BG","CC","DK","SK","SI","EE","FI","FR","GR","GG",
|
638 |
+
"NL","HU","IE","IT","LV","LI","LT","LU","MC","NO","PL","GB","CZ",
|
639 |
+
"RO","SM","SE","CH","VA");
|
640 |
+
$max=count($paises);
|
641 |
+
for($i=0;$i<$max;$i++){
|
642 |
+
if($pais == $paises[$i]){
|
643 |
+
return true;
|
644 |
+
}
|
645 |
+
}
|
646 |
+
return false;
|
647 |
+
}
|
648 |
+
|
649 |
+
}
|
app/code/local/ENVIALIA/ENVIALIAShipping/Model/ENVIALIA/Shipment.php
ADDED
@@ -0,0 +1,303 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class ENVIALIA_ENVIALIAShipping_Model_ENVIALIA_Shipment extends Mage_Sales_Model_Order_Shipment
|
3 |
+
{
|
4 |
+
protected function _beforeSave()
|
5 |
+
{
|
6 |
+
$canSave = parent::_beforeSave();
|
7 |
+
// Antes de guardar verificamos que no este guardado este envio
|
8 |
+
$order_id=$this->getOrder()->getId();
|
9 |
+
|
10 |
+
$baseDatos = Mage::getSingleton('core/resource')->getConnection('core_write');
|
11 |
+
$resultado=$baseDatos->query("select track_number from sales_flat_shipment_track where parent_id = (select entity_id from sales_flat_order where order_id = '".$order_id."')");
|
12 |
+
$row = $resultado->fetch();
|
13 |
+
$hay_track = $row['track_number'];
|
14 |
+
|
15 |
+
if(!$hay_track){
|
16 |
+
// Primero de todo nos logueamos si esto falla todo lo demas no tiene sentido
|
17 |
+
$urlEnvialia = Mage::getStoreConfig('carriers/ENVIALIAShipping/ENVIALIA_URL', $this->getStoreId());
|
18 |
+
$URL = $urlEnvialia."/soap";
|
19 |
+
|
20 |
+
$envialiaCodigoAgencia = Mage::getStoreConfig('carriers/ENVIALIAShipping/ENVIALIA_CODIGO_AGENCIA', $this->getStoreId());
|
21 |
+
$envialiaCodigoCliente = Mage::getStoreConfig('carriers/ENVIALIAShipping/ENVIALIA_CODIGO_CLIENTE', $this->getStoreId());
|
22 |
+
$envialiaPasswordCliente = Mage::getStoreConfig('carriers/ENVIALIAShipping/ENVIALIA_PASSWORD_CLIENTE', $this->getStoreId());
|
23 |
+
|
24 |
+
|
25 |
+
|
26 |
+
$XML='<?xml version="1.0" encoding="utf-8"?>
|
27 |
+
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
28 |
+
<soap:Body>
|
29 |
+
<LoginWSService___LoginCli>
|
30 |
+
<strCodAge>'.$envialiaCodigoAgencia.'</strCodAge>
|
31 |
+
<strCod>'.$envialiaCodigoCliente.'</strCod>
|
32 |
+
<strPass>'.$envialiaPasswordCliente.'</strPass>
|
33 |
+
</LoginWSService___LoginCli>
|
34 |
+
</soap:Body>
|
35 |
+
</soap:Envelope>';
|
36 |
+
|
37 |
+
|
38 |
+
$ch = curl_init();
|
39 |
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
40 |
+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
41 |
+
curl_setopt($ch, CURLOPT_HEADER, FALSE);
|
42 |
+
curl_setopt($ch, CURLOPT_FORBID_REUSE, TRUE);
|
43 |
+
curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);
|
44 |
+
curl_setopt($ch, CURLOPT_URL, $URL );
|
45 |
+
curl_setopt($ch, CURLOPT_POSTFIELDS, $XML );
|
46 |
+
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
|
47 |
+
|
48 |
+
$postResult = curl_exec($ch);
|
49 |
+
|
50 |
+
if (curl_errno($ch)) {
|
51 |
+
Mage::throwException(
|
52 |
+
Mage::helper('sales')->__('No se pudo llamar al ws de ENVIALIA.')
|
53 |
+
);
|
54 |
+
}
|
55 |
+
|
56 |
+
|
57 |
+
$xml = simplexml_load_string($postResult, NULL, NULL, "http://http://www.w3.org/2003/05/soap-envelope");
|
58 |
+
$xml->registerXPathNamespace("abc","http://tempuri.org/");
|
59 |
+
// hay excepciones desde el WS
|
60 |
+
if($xml->xpath('//faultstring')){
|
61 |
+
foreach($xml->xpath('//faultstring') as $error){
|
62 |
+
Mage::log('ENVIALIA ERROR : '.$error);
|
63 |
+
Mage::throwException(Mage::helper('sales')->__('ENVIALIA ERROR : '.$error));
|
64 |
+
}
|
65 |
+
}
|
66 |
+
else{
|
67 |
+
foreach ($xml->xpath('//abc:strSesion') as $item)
|
68 |
+
{
|
69 |
+
$id_sesion_cliente=$item;
|
70 |
+
}
|
71 |
+
}
|
72 |
+
// Ya tenemos el id_sesion
|
73 |
+
// Vamos a por todos los datos necesarios para realizar el pedido
|
74 |
+
|
75 |
+
$tipoServicio = $this->getOrder()->getShippingMethod();
|
76 |
+
$tipoServicio = split("_",$tipoServicio);
|
77 |
+
$envialia_tipo_servicio = $tipoServicio[1];
|
78 |
+
|
79 |
+
|
80 |
+
$peso = 0;
|
81 |
+
foreach ($this->getAllItems() as $item) {
|
82 |
+
$peso+= $item->getOrderItem()->getWeight() * $item->getOrderItem()->getQtyShipped();
|
83 |
+
}
|
84 |
+
if($peso < 1){
|
85 |
+
$peso=1;
|
86 |
+
}
|
87 |
+
$envialia_peso_origen = $peso;
|
88 |
+
$envialia_referencia = $this->getOrder()->getIncrementId();
|
89 |
+
$envialia_numero_paquetes = 1;
|
90 |
+
$envialia_importe_servicio = $this->getOrder()->getTotalDue();
|
91 |
+
|
92 |
+
// Datos del comprador
|
93 |
+
$dir_pedido = $this->getShippingAddress();
|
94 |
+
$envialia_nombre_destinatario = $dir_pedido->getName();
|
95 |
+
$envialia_nombre_via_destinatario = $dir_pedido->getStreetFull();
|
96 |
+
$envialia_poblacion_destinatario = $dir_pedido->getCity();
|
97 |
+
$envialia_CP_destinatario = $dir_pedido->getPostcode();
|
98 |
+
//$envialia_cod_provincia_destinatario= $dir_pedido->getRegion();
|
99 |
+
$envialia_telefono_destinatario = $dir_pedido->getTelephone();
|
100 |
+
$envialia_email_destinatario = $dir_pedido->getEmail();
|
101 |
+
$envialia_pais = $dir_pedido->getCountry();
|
102 |
+
|
103 |
+
//HAY QUE CONTROLAR SI EL COMPRADOR A ELEGIDO CONTRAREEMBOLSO Y PONERLO EN EL PARAMETRO
|
104 |
+
$metodo_pago = $this->getOrder()->getPayment()->getMethod();
|
105 |
+
if($metodo_pago == 'ig_cashondelivery'){
|
106 |
+
$envialia_reembolso=floatval($envialia_importe_servicio);
|
107 |
+
}
|
108 |
+
else{
|
109 |
+
$envialia_reembolso = 0;
|
110 |
+
}
|
111 |
+
|
112 |
+
//controlar de que pais es el comprador
|
113 |
+
if($envialia_pais == 'ES' || $envialia_pais == 'PT' || $envialia_pais == 'AD'){
|
114 |
+
$envialia_pais = '';
|
115 |
+
}
|
116 |
+
else{
|
117 |
+
$envialia_pais='<strCodPais>'.$envialia_pais.'</strCodPais>';
|
118 |
+
}
|
119 |
+
|
120 |
+
// Datos del vendedor
|
121 |
+
$envialia_nombre_remitente = Mage::getStoreConfig('general/store_information/name');
|
122 |
+
$envialia_nombre_via_remitente = Mage::getStoreConfig('general/store_information/address');
|
123 |
+
$envialia_poblacion_remitente = Mage::getStoreConfig('shipping/origin/city');
|
124 |
+
//$envialia_cod_provincia_remitente = Mage::getStoreConfig('shipping/origin/region');
|
125 |
+
$envialia_telefono_remitente = Mage::getStoreConfig('general/store_information/phone');
|
126 |
+
// comprobar si tenemos que sobreescribir el CP
|
127 |
+
if(Mage::getStoreConfig('carriers/ENVIALIAShipping/ENVIALIA_SOBREESCRIBIR_CODIGO_POSTAL', $this->getStoreId())){
|
128 |
+
$envialia_CP_remitente = Mage::getStoreConfig('carriers/ENVIALIAShipping/ENVIALIA_SOBREESCRIBIR_CODIGO_POSTAL', $this->getStoreId());
|
129 |
+
}
|
130 |
+
else{
|
131 |
+
$envialia_CP_remitente = Mage::getStoreConfig('shipping/origin/postcode');
|
132 |
+
}
|
133 |
+
|
134 |
+
|
135 |
+
//Realizamos el pedido
|
136 |
+
// <strCodProOri>'.$envialia_cod_provincia_remitente.'</strCodProOri>
|
137 |
+
// <strCodProDes>'.$envialia_cod_provincia_destinatario.'</strCodProDes>
|
138 |
+
// RECUERDA ELIMINAR LA SIGUIENTE VAR
|
139 |
+
//$envialia_tipo_servicio='24';
|
140 |
+
|
141 |
+
|
142 |
+
$XML='<?xml version="1.0" encoding="utf-8"?>
|
143 |
+
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
144 |
+
<soap:Header>
|
145 |
+
<ROClientIDHeader xmlns="http://tempuri.org/">
|
146 |
+
<ID>'.$id_sesion_cliente.'</ID>
|
147 |
+
</ROClientIDHeader>
|
148 |
+
</soap:Header>
|
149 |
+
<soap:Body>
|
150 |
+
<WebServService___GrabaEnvio4 xmlns="http://tempuri.org/">
|
151 |
+
<strCodAgeCargo>'.$envialiaCodigoAgencia.'</strCodAgeCargo>
|
152 |
+
<strCodAgeOri>'.$envialiaCodigoAgencia.'</strCodAgeOri>
|
153 |
+
<dtFecha>'.date("Y/m/d").'</dtFecha>
|
154 |
+
<strCodTipoServ>'.$envialia_tipo_servicio.'</strCodTipoServ>
|
155 |
+
<strCodCli>'.$envialiaCodigoCliente.'</strCodCli>
|
156 |
+
|
157 |
+
<strNomOri>'.$envialia_nombre_remitente.'</strNomOri>
|
158 |
+
<strDirOri>'.$envialia_nombre_via_remitente.'</strDirOri>
|
159 |
+
<strPobOri>'.$envialia_poblacion_remitente.'</strPobOri>
|
160 |
+
<strCPOri>'.$envialia_CP_remitente.'</strCPOri>
|
161 |
+
|
162 |
+
<strTlfOri>'.$envialia_telefono_remitente.'</strTlfOri>
|
163 |
+
|
164 |
+
<strNomDes>'.$envialia_nombre_destinatario.'</strNomDes>
|
165 |
+
<strDirDes>'.$envialia_nombre_via_destinatario.'</strDirDes>
|
166 |
+
<strPobDes>'.$envialia_poblacion_destinatario.'</strPobDes>
|
167 |
+
<strCPDes>'.$envialia_CP_destinatario.'</strCPDes>
|
168 |
+
|
169 |
+
<strTlfDes>'.$envialia_telefono_destinatario.'</strTlfDes>
|
170 |
+
|
171 |
+
<intPaq>'.$envialia_numero_paquetes.'</intPaq>
|
172 |
+
<dPesoOri>'.floatval($envialia_peso_origen).'</dPesoOri>
|
173 |
+
<dReembolso>'.$envialia_reembolso.'</dReembolso>
|
174 |
+
<strRef>'.$envialia_referencia.'</strRef>
|
175 |
+
'.$envialia_pais.'
|
176 |
+
<strDesDirEmails>'.$envialia_email_destinatario.'</strDesDirEmails>
|
177 |
+
<boInsert>'.TRUE.'</boInsert>
|
178 |
+
</WebServService___GrabaEnvio4>
|
179 |
+
</soap:Body>
|
180 |
+
</soap:Envelope>';
|
181 |
+
|
182 |
+
$ch = curl_init();
|
183 |
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
184 |
+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
185 |
+
curl_setopt($ch, CURLOPT_HEADER, FALSE);
|
186 |
+
curl_setopt($ch, CURLOPT_FORBID_REUSE, TRUE);
|
187 |
+
curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);
|
188 |
+
curl_setopt($ch, CURLOPT_URL, $URL );
|
189 |
+
curl_setopt($ch, CURLOPT_POSTFIELDS, $XML );
|
190 |
+
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
|
191 |
+
|
192 |
+
$postResult = curl_exec($ch);
|
193 |
+
|
194 |
+
if (curl_errno($ch)) {
|
195 |
+
Mage::throwException(
|
196 |
+
Mage::helper('sales')->__('No se pudo llamar al ws de ENVIALIA.')
|
197 |
+
);
|
198 |
+
}
|
199 |
+
|
200 |
+
|
201 |
+
$xml = simplexml_load_string($postResult, NULL, NULL, "http://http://www.w3.org/2003/05/soap-envelope");
|
202 |
+
$xml->registerXPathNamespace("abc","http://tempuri.org/");
|
203 |
+
// hay excepciones desde el WS
|
204 |
+
if($xml->xpath('//faultstring')){
|
205 |
+
foreach($xml->xpath('//faultstring') as $error){
|
206 |
+
Mage::log('ENVIALIA ERROR : '.$error);
|
207 |
+
Mage::throwException(Mage::helper('sales')->__('ENVIALIA ERROR : '.$error));
|
208 |
+
}
|
209 |
+
}
|
210 |
+
else{
|
211 |
+
foreach ($xml->xpath('//abc:strAlbaranOut') as $item)
|
212 |
+
{
|
213 |
+
$envialia_num_albaran=$item;
|
214 |
+
}
|
215 |
+
foreach ($xml->xpath('//abc:strGuidOut') as $item)
|
216 |
+
{
|
217 |
+
$envialia_num_seguimiento=$item;
|
218 |
+
}
|
219 |
+
// primero tenemos que transformar el codigo de seguimiento
|
220 |
+
|
221 |
+
$cod_tracking = $this->limpiarNumTrack($envialia_num_seguimiento);
|
222 |
+
if(!$cod_tracking){
|
223 |
+
Mage::throwException(Mage::helper('sales')->__('ENVIALIA ERROR : limpiarNumTrack'));
|
224 |
+
}
|
225 |
+
// guardamos el num de seguimiento o track
|
226 |
+
$track = Mage::getModel('sales/order_shipment_track')
|
227 |
+
->setNumber($cod_tracking)
|
228 |
+
->setCarrierCode('ENVIALIAShipping')
|
229 |
+
->setTitle('Tracking ENVIALIA')
|
230 |
+
->setDescription($envialia_num_albaran);
|
231 |
+
$this->addTrack($track);
|
232 |
+
|
233 |
+
}
|
234 |
+
|
235 |
+
//Ahora podemos obtener el codigo de barras en PDF codificado en base64
|
236 |
+
$XML='<?xml version="1.0" encoding="utf-8"?>
|
237 |
+
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
238 |
+
<soap:Header>
|
239 |
+
<ROClientIDHeader xmlns="http://tempuri.org/">
|
240 |
+
<ID>'.$id_sesion_cliente.'</ID>
|
241 |
+
</ROClientIDHeader>
|
242 |
+
</soap:Header>
|
243 |
+
<soap:Body>
|
244 |
+
<WebServService___ConsEtiquetaEnvio>
|
245 |
+
<strAlbaran>'.$envialia_num_albaran.'</strAlbaran>
|
246 |
+
</WebServService___ConsEtiquetaEnvio>
|
247 |
+
</soap:Body>
|
248 |
+
</soap:Envelope>';
|
249 |
+
|
250 |
+
|
251 |
+
|
252 |
+
$ch = curl_init();
|
253 |
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
254 |
+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
255 |
+
curl_setopt($ch, CURLOPT_HEADER, FALSE);
|
256 |
+
curl_setopt($ch, CURLOPT_FORBID_REUSE, TRUE);
|
257 |
+
curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);
|
258 |
+
curl_setopt($ch, CURLOPT_URL, $URL );
|
259 |
+
curl_setopt($ch, CURLOPT_POSTFIELDS, $XML );
|
260 |
+
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
|
261 |
+
|
262 |
+
$postResult = curl_exec($ch);
|
263 |
+
|
264 |
+
|
265 |
+
|
266 |
+
if (curl_errno($ch)) {
|
267 |
+
Mage::throwException(
|
268 |
+
Mage::helper('sales')->__('No se pudo llamar al ws de ENVIALIA.')
|
269 |
+
);
|
270 |
+
}
|
271 |
+
|
272 |
+
|
273 |
+
$xml = simplexml_load_string($postResult, NULL, NULL, "http://http://www.w3.org/2003/05/soap-envelope");
|
274 |
+
$xml->registerXPathNamespace("abc","http://tempuri.org/");
|
275 |
+
// hay excepciones desde el WS
|
276 |
+
if($xml->xpath('//faultstring')){
|
277 |
+
foreach($xml->xpath('//faultstring') as $error){
|
278 |
+
Mage::log('ENVIALIA ERROR : '.$error);
|
279 |
+
Mage::throwException(Mage::helper('sales')->__('ENVIALIA ERROR : '.$error));
|
280 |
+
}
|
281 |
+
}
|
282 |
+
else{
|
283 |
+
foreach ($xml->xpath('//abc:strEtiqueta') as $item)
|
284 |
+
{
|
285 |
+
$envialia_etiqueta=$item;
|
286 |
+
}
|
287 |
+
}
|
288 |
+
|
289 |
+
$this->setShippingLabel($envialia_etiqueta);
|
290 |
+
}
|
291 |
+
return $canSave;
|
292 |
+
}
|
293 |
+
|
294 |
+
function limpiarNumTrack($codigo){
|
295 |
+
if(!$codigo){
|
296 |
+
return false;
|
297 |
+
}
|
298 |
+
$codigo = substr($codigo,1,36);
|
299 |
+
return $codigo;
|
300 |
+
}
|
301 |
+
|
302 |
+
|
303 |
+
}
|
app/code/local/ENVIALIA/ENVIALIAShipping/Model/ENVIALIA/Shipment/Track.php
ADDED
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class ENVIALIA_ENVIALIAShipping_Model_ENVIALIA_Shipment_Track extends Mage_Sales_Model_Order_Shipment_Track
|
3 |
+
{
|
4 |
+
protected function _beforeDelete()
|
5 |
+
{
|
6 |
+
$canDelete = parent::_beforeDelete();
|
7 |
+
|
8 |
+
foreach ($this->getShipment()->getAllTracks() as $track )
|
9 |
+
{
|
10 |
+
if ($track->getCarrierCode()=='ENVIALIAShipping')
|
11 |
+
{
|
12 |
+
$ordenId=$track->getOrderId();
|
13 |
+
$baseDatos = Mage::getSingleton('core/resource')->getConnection('core_write');
|
14 |
+
// obtenemos el num albaran
|
15 |
+
$resultado=$baseDatos->query("select * from sales_flat_shipment_track where order_id='".$ordenId."'");
|
16 |
+
$row = $resultado->fetch();
|
17 |
+
$envialia_num_albaran = $row['description'];
|
18 |
+
|
19 |
+
|
20 |
+
// Primero de todo nos logueamos si esto falla todo lo demas no tiene sentido
|
21 |
+
$urlEnvialia = Mage::getStoreConfig('carriers/ENVIALIAShipping/ENVIALIA_URL', $this->getStoreId());
|
22 |
+
$URL = $urlEnvialia."/soap";
|
23 |
+
|
24 |
+
$envialiaCodigoAgencia = Mage::getStoreConfig('carriers/ENVIALIAShipping/ENVIALIA_CODIGO_AGENCIA', $this->getStoreId());
|
25 |
+
$envialiaCodigoCliente = Mage::getStoreConfig('carriers/ENVIALIAShipping/ENVIALIA_CODIGO_CLIENTE', $this->getStoreId());
|
26 |
+
$envialiaPasswordCliente = Mage::getStoreConfig('carriers/ENVIALIAShipping/ENVIALIA_PASSWORD_CLIENTE', $this->getStoreId());
|
27 |
+
|
28 |
+
|
29 |
+
|
30 |
+
$XML='<?xml version="1.0" encoding="utf-8"?>
|
31 |
+
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
32 |
+
<soap:Body>
|
33 |
+
<LoginWSService___LoginCli>
|
34 |
+
<strCodAge>'.$envialiaCodigoAgencia.'</strCodAge>
|
35 |
+
<strCod>'.$envialiaCodigoCliente.'</strCod>
|
36 |
+
<strPass>'.$envialiaPasswordCliente.'</strPass>
|
37 |
+
</LoginWSService___LoginCli>
|
38 |
+
</soap:Body>
|
39 |
+
</soap:Envelope>';
|
40 |
+
|
41 |
+
$ch = curl_init();
|
42 |
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
43 |
+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
44 |
+
curl_setopt($ch, CURLOPT_HEADER, FALSE);
|
45 |
+
curl_setopt($ch, CURLOPT_FORBID_REUSE, TRUE);
|
46 |
+
curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);
|
47 |
+
curl_setopt($ch, CURLOPT_URL, $URL );
|
48 |
+
curl_setopt($ch, CURLOPT_POSTFIELDS, $XML );
|
49 |
+
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
|
50 |
+
|
51 |
+
$postResult = curl_exec($ch);
|
52 |
+
|
53 |
+
if (curl_errno($ch)) {
|
54 |
+
Mage::throwException(
|
55 |
+
Mage::helper('sales')->__('No se pudo llamar al ws de ENVIALIA.')
|
56 |
+
);
|
57 |
+
}
|
58 |
+
|
59 |
+
|
60 |
+
$xml = simplexml_load_string($postResult, NULL, NULL, "http://http://www.w3.org/2003/05/soap-envelope");
|
61 |
+
$xml->registerXPathNamespace("abc","http://tempuri.org/");
|
62 |
+
// hay excepciones desde el WS
|
63 |
+
if($xml->xpath('//faultstring')){
|
64 |
+
foreach($xml->xpath('//faultstring') as $error){
|
65 |
+
Mage::log('ENVIALIA ERROR : '.$error);
|
66 |
+
Mage::throwException(Mage::helper('sales')->__('ENVIALIA ERROR : '.$error));
|
67 |
+
}
|
68 |
+
}
|
69 |
+
else{
|
70 |
+
foreach ($xml->xpath('//abc:strSesion') as $item)
|
71 |
+
{
|
72 |
+
$id_sesion_cliente=$item;
|
73 |
+
}
|
74 |
+
}
|
75 |
+
// Ya tenemos el id_sesion
|
76 |
+
// Ahora cancelamos el envio
|
77 |
+
|
78 |
+
$XML=' <?xml version="1.0" encoding="utf-8"?>
|
79 |
+
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-
|
80 |
+
instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
81 |
+
<soap:Header>
|
82 |
+
<ROClientIDHeader xmlns="http://tempuri.org/">
|
83 |
+
<ID>'.$id_sesion_cliente.'</ID>
|
84 |
+
</ROClientIDHeader>
|
85 |
+
</soap:Header>
|
86 |
+
<soap:Body>
|
87 |
+
<WebServService___BorraEnvio xmlns="http://tempuri.org/">
|
88 |
+
<strCodAgeCargo>'.$envialiaCodigoAgencia.'</strCodAgeCargo>
|
89 |
+
<strCodAgeOri>'.$envialiaCodigoAgencia.'</strCodAgeOri>
|
90 |
+
<strAlbaran>'.$envialia_num_albaran.'</strAlbaran>
|
91 |
+
</WebServService___BorraEnvio>
|
92 |
+
</soap:Body>
|
93 |
+
</soap:Envelope>';
|
94 |
+
|
95 |
+
$ch = curl_init();
|
96 |
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
97 |
+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
98 |
+
curl_setopt($ch, CURLOPT_HEADER, FALSE);
|
99 |
+
curl_setopt($ch, CURLOPT_FORBID_REUSE, TRUE);
|
100 |
+
curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);
|
101 |
+
curl_setopt($ch, CURLOPT_URL, $URL );
|
102 |
+
curl_setopt($ch, CURLOPT_POSTFIELDS, $XML );
|
103 |
+
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
|
104 |
+
|
105 |
+
$postResult = curl_exec($ch);
|
106 |
+
|
107 |
+
if (curl_errno($ch)) {
|
108 |
+
Mage::throwException(
|
109 |
+
Mage::helper('sales')->__('No se pudo llamar al ws de ENVIALIA.')
|
110 |
+
);
|
111 |
+
}
|
112 |
+
|
113 |
+
|
114 |
+
$xml = simplexml_load_string($postResult, NULL, NULL, "http://http://www.w3.org/2003/05/soap-envelope");
|
115 |
+
$xml->registerXPathNamespace("abc","http://tempuri.org/");
|
116 |
+
// hay excepciones desde el WS
|
117 |
+
if($xml->xpath('//intCodError')){
|
118 |
+
foreach($xml->xpath('//intCodError') as $error){
|
119 |
+
Mage::log('ENVIALIA ERROR : '.$error);
|
120 |
+
Mage::throwException(Mage::helper('sales')->__('ENVIALIA ERROR : '.$error));
|
121 |
+
}
|
122 |
+
}
|
123 |
+
// Ya cancelamos el pedido y podemos borrar su codigo de barras
|
124 |
+
$resultado=$baseDatos->query("update sales_flat_shipment set shipping_label='' where order_id='".$ordenId."'");
|
125 |
+
|
126 |
+
}
|
127 |
+
}
|
128 |
+
return $canDelete;
|
129 |
+
}
|
130 |
+
|
131 |
+
}
|
app/code/local/ENVIALIA/ENVIALIAShipping/Model/ENVIALIA/Source/Gratuito.php
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class ENVIALIA_ENVIALIAShipping_Model_ENVIALIA_Source_Gratuito
|
3 |
+
{
|
4 |
+
public function toOptionArray()
|
5 |
+
{
|
6 |
+
$arr = array();
|
7 |
+
$arr[] = array('value'=>'E24', 'label'=>'E-COMM 24H');
|
8 |
+
$arr[] = array('value'=>'E72', 'label'=>'E-COMM 72H');
|
9 |
+
return $arr;
|
10 |
+
}
|
11 |
+
|
12 |
+
public function getMethod($shippingMethod)
|
13 |
+
{
|
14 |
+
$mte= explode("_",$shippingMethod);
|
15 |
+
if ($mte[0]=="ENVIALIAShipping")
|
16 |
+
{
|
17 |
+
$label=$mte[1];
|
18 |
+
foreach($this->toOptionArray() as $mta)
|
19 |
+
{
|
20 |
+
if ($mta["label"]==$label) $metodo=$mta;
|
21 |
+
}
|
22 |
+
}
|
23 |
+
return $metodo;
|
24 |
+
}
|
25 |
+
}
|
26 |
+
?>
|
app/code/local/ENVIALIA/ENVIALIAShipping/Model/ENVIALIA/Source/GratuitoInternacional.php
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class ENVIALIA_ENVIALIAShipping_Model_ENVIALIA_Source_GratuitoInternacional
|
3 |
+
{
|
4 |
+
public function toOptionArray()
|
5 |
+
{
|
6 |
+
$arr = array();
|
7 |
+
$arr[] = array('value'=>'EWW', 'label'=>'E-COMM WORLDWIDE');
|
8 |
+
$arr[] = array('value'=>'EEU', 'label'=>'E-COMM EUROPE EXPRESS');
|
9 |
+
return $arr;
|
10 |
+
}
|
11 |
+
|
12 |
+
public function getMethod($shippingMethod)
|
13 |
+
{
|
14 |
+
$mte= explode("_",$shippingMethod);
|
15 |
+
if ($mte[0]=="ENVIALIAShipping")
|
16 |
+
{
|
17 |
+
$label=$mte[1];
|
18 |
+
foreach($this->toOptionArray() as $mta)
|
19 |
+
{
|
20 |
+
if ($mta["label"]==$label) $metodo=$mta;
|
21 |
+
}
|
22 |
+
}
|
23 |
+
return $metodo;
|
24 |
+
}
|
25 |
+
}
|
26 |
+
?>
|
app/code/local/ENVIALIA/ENVIALIAShipping/Model/ENVIALIA/Source/Manipulacion.php
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class ENVIALIA_ENVIALIAShipping_Model_ENVIALIA_Source_Manipulacion
|
3 |
+
{
|
4 |
+
public function toOptionArray()
|
5 |
+
{
|
6 |
+
$arr = array();
|
7 |
+
$arr[] = array('value'=>'F', 'label'=>'Fijo');
|
8 |
+
$arr[] = array('value'=>'V', 'label'=>'Variable');
|
9 |
+
return $arr;
|
10 |
+
}
|
11 |
+
|
12 |
+
public function getMethod($shippingMethod)
|
13 |
+
{
|
14 |
+
$mte= explode("_",$shippingMethod);
|
15 |
+
if ($mte[0]=="ENVIALIAShipping")
|
16 |
+
{
|
17 |
+
$label=$mte[1];
|
18 |
+
foreach($this->toOptionArray() as $mta)
|
19 |
+
{
|
20 |
+
if ($mta["label"]==$label) $metodo=$mta;
|
21 |
+
}
|
22 |
+
}
|
23 |
+
return $metodo;
|
24 |
+
}
|
25 |
+
}
|
26 |
+
?>
|
app/code/local/ENVIALIA/ENVIALIAShipping/envialia.tarifas.csv
ADDED
@@ -0,0 +1,3133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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