forked from PrestaShopCorp/chronopost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
importExport.php
executable file
·189 lines (157 loc) · 5.57 KB
/
importExport.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
<?php
/**
* MODULE PRESTASHOP OFFICIEL CHRONOPOST
*
* LICENSE : All rights reserved - COPY AND REDISTRIBUTION FORBIDDEN WITHOUT PRIOR CONSENT FROM OXILEO
* LICENCE : Tous droits réservés, le droit d'auteur s'applique - COPIE ET REDISTRIBUTION INTERDITES SANS ACCORD EXPRES D'OXILEO
*
* @author Oxileo SAS <contact@oxileo.eu>
* @copyright 2001-2015 Oxileo SAS
* @license Proprietary - no redistribution without authorization
*/
include('../../config/config.inc.php');
require_once('chronopost.php');
if (!defined('_MYDIR_')) define('_MYDIR_', dirname(__FILE__));
if (!Tools::getIsset('shared_secret') || Tools::getValue('shared_secret') != Configuration::get('CHRONOPOST_SECRET'))
die('Secret does not match.');
$cible = Tools::getValue('cible');
if ($cible)
{
/* export */
header('Content-Disposition: attachment; filename="export'.$cible.date('Ymd').'.csv"');
if ($cible == 'CSS')
{
header('Content-Type: text/plain; charset=ISO-8859-1');
include_once _MYDIR_.'/libraries/PointRelaisServiceWSService.php';
foreach (_getChronoOrders() as $o)
{
/* Ingredients */
$address = new Address($o->id_address_delivery);
$country = new Country($address->id_country);
$customer = new Customer($o->id_customer); /* for email address */
$bt = '';
/*
if ($o->id_carrier == Configuration::get('CHRONORELAIS_CARRIER_ID'))
{
$row = Db::getInstance()->getRow('SELECT id_pr FROM '._DB_PREFIX_.'chrono_cart_relais WHERE id_cart='.$o->id_cart);
$bt = $row['id_pr'];
$ws = new PointRelaisServiceWSService();
$p = new rechercheBtAvecPFParIdChronopostA2Pas();
$p->id = $row['id_pr'];
// TODO USE PUDO
$prdata = $ws->rechercheBtAvecPFParIdChronopostA2Pas($p)->return;
$address->company = $prdata->nomEnseigne;
$address->address1 = $prdata->adresse1;
$address->address2 = @$prdata->adresse2;
$address->city = $prdata->localite;
$address->postcode = $prdata->codePostal;
}
OBSOLETE : hoookNewOrder completes the address already
*/
/* Stir everything together */
echo $o->id.';';
if ($address->company != '') echo _c($address->company).';';
echo _c($address->firstname.' '.$address->lastname).';';
if ($address->company == '') echo ';';
echo _c($address->address1).';'._c($address->address2).';';
echo _c($address->postcode).';';
echo _c($address->city).';';
echo $country->iso_code.';';
if ($address->phone != '') echo $address->phone.';';
else echo $address->phone_mobile.';';
echo $customer->email.';';
echo $bt.';';
echo ';'; /* ref expé 2 */
echo '1;'; /* Weight */
if ($o->id_carrier == Configuration::get('CHRONOPOST_CARRIER_ID')) echo '13H;';
if ($o->id_carrier == Configuration::get('CHRONOEXPRESS_CARRIER_ID')) echo 'EI;';
if ($o->id_carrier == Configuration::get('CHRONORELAIS_CARRIER_ID')) echo 'PR;';
if (Chronopost::isSaturdayOptionApplicable()) echo 'S;';
else echo 'L;';
echo Configuration::get('CHRONOPOST_GENERAL_SUBACCOUNT').';';
echo ';'."\r\n";
}
}
if ($cible == 'CSO')
{
header('Content-Type: text/plain; charset=US-ASCII');
foreach (_getChronoOrders(false) as $o)
{
/* Ingredients */
$address = new Address($o->id_address_delivery);
$country = new Country($address->id_country);
$customer = new Customer($o->id_customer); /* for email address */
if (strpos($address->alias, 'Depot Chrono Relais ') === false) $bt = '';
else $bt = Tools::substr($address->alias, 20); /* strlen(Depot [...])=20 */
/* Stir everything together */
echo ';'; /* "code destinataire" left empty */
if ($address->company != '') echo _c($address->company).';';
else echo ';';
echo ';'; /* "suite raison sociale" (?) */
echo _c($address->address1).';'._c($address->address2).';';
echo ';'; /* "code porte" */
echo $country->iso_code.';';
echo _c($address->postcode).';';
echo _c($address->city).';';
echo _c($address->lastname).';';
echo _c($address->firstname).';';
if ($address->phone != '') echo $address->phone.';';
else echo $address->phone_mobile.';';
echo $customer->email.';';
echo ';'; /* "numero tva" */
if ($o->id_carrier == Configuration::get('CHRONOPOST_CARRIER_ID')) echo '1;';
if ($o->id_carrier == Configuration::get('CHRONOEXPRESS_CARRIER_ID')) echo '4;';
echo $o->id.';';
echo ($o->getTotalWeight() == 0 ? 1 : ($o->getTotalWeight() * 1000)).';';
echo ';;;';
echo Configuration::get('CHRONOPOST_GENERAL_SUBACCOUNT').';';
echo '1;Commande '.$o->id.';';
echo ';';
echo $o->total_paid.';';
if (Chronopost::isSaturdayOptionApplicable()) echo '1;';
else echo '2;';
echo "\r\n";
}
}
}
function _c($value)
{
return utf8_decode(str_replace('"', ' ', str_replace(';', ' ', strip_tags($value))));
}
function _getChronoOrders($withRelais = true)
{
if (Tools::getIsset('multi'))
$multi = Tools::jsonDecode(Tools::getValue('multi'), true);
else $multi = array();
$r = array();
if (Tools::getIsset('orders'))
$o = explode(';', Tools::getValue('orders'));
else
$o = Order::getOrdersIdByDate(date('Y-m-d H:i:s', 0), date('Y-m-d H:i:s'));
foreach ($o as $i)
{
$or = new Order($i);
if ($withRelais)
{
if (Chronopost::isChrono($or->id_carrier))
{
if (array_key_exists($i, $multi)) $cpt = $multi[$i];
else $cpt = 1;
for (; $cpt > 0; $cpt--)
$r[] = $or;
}
}
else
{ // no relais export for CSO
if (Chronopost::isChrono($or->id_carrier) && $or->id_carrier != Configuration::get('CHRONORELAIS_CARRIER_ID'))
{
if (array_key_exists($i, $multi)) $cpt = $multi[$i];
else $cpt = 1;
for (; $cpt > 0; $cpt--)
$r[] = $or;
}
}
}
return $r;
}
?>