1
|
<?php
|
2
|
/* --------------------------------------------------------------
|
3
|
RecreateOrder.php 2014-06-04 gm
|
4
|
Gambio GmbH
|
5
|
http://www.gambio.de
|
6
|
Copyright (c) 2014 Gambio GmbH
|
7
|
Released under the GNU General Public License (Version 2)
|
8
|
[http://www.gnu.org/licenses/gpl-2.0.html]
|
9
|
--------------------------------------------------------------
|
10
|
*/
|
11
|
|
12
|
require_once(DIR_FS_INC.'xtc_format_price_order.inc.php');
|
13
|
require_once(DIR_FS_CATALOG.'gm/inc/gm_prepare_number.inc.php');
|
14
|
require_once(DIR_FS_CATALOG.'gm/inc/gm_save_order.inc.php');
|
15
|
require_once(DIR_FS_INC.'xtc_get_attributes_model.inc.php');
|
16
|
|
17
|
class RecreateOrder
|
18
|
{
|
19
|
/**
|
20
|
* @var int order id
|
21
|
*/
|
22
|
var $v_order_id = 0;
|
23
|
|
24
|
/**
|
25
|
* @var string html of the order
|
26
|
*/
|
27
|
var $v_html = '';
|
28
|
|
29
|
/**
|
30
|
* constructor
|
31
|
*
|
32
|
* check order exists
|
33
|
*
|
34
|
* @access public
|
35
|
* @param int $p_orders_id order id
|
36
|
* @return bool OK:true | ERROR:false
|
37
|
*/
|
38
|
function RecreateOrder($p_orders_id)
|
39
|
{
|
40
|
// manage params
|
41
|
$this->v_order_id = (int)$p_orders_id;
|
42
|
|
43
|
// get send order status and orders id
|
44
|
$t_query = xtc_db_query("
|
45
|
SELECT
|
46
|
orders_id,
|
47
|
gm_send_order_status,
|
48
|
abandonment_download,
|
49
|
abandonment_service
|
50
|
FROM " .
|
51
|
TABLE_ORDERS . "
|
52
|
WHERE
|
53
|
orders_id= '" . $this->v_order_id . "'
|
54
|
LIMIT 1
|
55
|
");
|
56
|
|
57
|
// if order status exists
|
58
|
if(xtc_db_num_rows($t_query) <= 0) {
|
59
|
return false;
|
60
|
}
|
61
|
|
62
|
$t_order_status = xtc_db_fetch_array($t_query);
|
63
|
$this->createOrder($t_order_status);
|
64
|
|
65
|
return true;
|
66
|
}
|
67
|
|
68
|
/**
|
69
|
* create the order
|
70
|
*
|
71
|
* @access private
|
72
|
* @return bool OK:true | Error:false
|
73
|
*/
|
74
|
function createOrder($t_row)
|
75
|
{
|
76
|
// recreate order
|
77
|
$smarty = new Smarty;
|
78
|
|
79
|
$t_order = new order($t_row['orders_id']);
|
80
|
|
81
|
$t_order_query = xtc_db_query("
|
82
|
SELECT
|
83
|
products_id,
|
84
|
orders_products_id,
|
85
|
products_model,
|
86
|
products_name,
|
87
|
products_shipping_time,
|
88
|
final_price,
|
89
|
products_quantity
|
90
|
FROM " .
|
91
|
TABLE_ORDERS_PRODUCTS . "
|
92
|
WHERE
|
93
|
orders_id= '" . (int)$t_row['orders_id'] . "'
|
94
|
");
|
95
|
|
96
|
$t_order_data = array();
|
97
|
|
98
|
while ($t_order_data_values = xtc_db_fetch_array($t_order_query)) {
|
99
|
$t_attributes_query = xtc_db_query("
|
100
|
SELECT
|
101
|
products_options,
|
102
|
products_options_values,
|
103
|
price_prefix,
|
104
|
options_values_price
|
105
|
FROM " .
|
106
|
TABLE_ORDERS_PRODUCTS_ATTRIBUTES . "
|
107
|
WHERE
|
108
|
orders_products_id = '" . $t_order_data_values['orders_products_id'] . "'
|
109
|
AND
|
110
|
orders_id = '" . (int)$t_row['orders_id'] . "'
|
111
|
");
|
112
|
|
113
|
$t_attributes_data = '';
|
114
|
$t_attributes_model = '';
|
115
|
|
116
|
while($t_attributes_data_values = xtc_db_fetch_array($t_attributes_query)) {
|
117
|
$t_attributes_data .= '<br />' . $t_attributes_data_values['products_options'] . ':' . $t_attributes_data_values['products_options_values'];
|
118
|
$t_attributes_model .= '<br />' . xtc_get_attributes_model(
|
119
|
$t_order_data_values['products_id'],
|
120
|
$t_attributes_data_values['products_options_values'],
|
121
|
$t_attributes_data_values['products_options']
|
122
|
);
|
123
|
}
|
124
|
|
125
|
// PROPERTIES
|
126
|
$coo_properties_control = MainFactory::create_object('PropertiesControl');
|
127
|
$t_properties_array = $coo_properties_control->get_orders_products_properties($t_order_data_values['orders_products_id']);
|
128
|
|
129
|
// BOF GM_MOD GX-Customizer:
|
130
|
require(DIR_FS_CATALOG . 'gm/modules/gm_gprint_admin_gm_send_order.php');
|
131
|
|
132
|
if(empty($t_order_data_values['products_shipping_time'])) $t_order_data_values['products_shipping_time'] = $this->get_shipping_time($t_order_data_values['products_id']);
|
133
|
|
134
|
$t_order_data[] = array(
|
135
|
'PRODUCTS_MODEL' => $t_order_data_values['products_model'],
|
136
|
'PRODUCTS_NAME' => $t_order_data_values['products_name'],
|
137
|
'PRODUCTS_SHIPPING_TIME' => $t_order_data_values['products_shipping_time'],
|
138
|
'PRODUCTS_ATTRIBUTES' => $t_attributes_data,
|
139
|
'PRODUCTS_ATTRIBUTES_MODEL' => $t_attributes_model,
|
140
|
'PRODUCTS_PROPERTIES' => $t_properties_array,
|
141
|
'PRODUCTS_SINGLE_PRICE' => xtc_format_price_order(
|
142
|
$t_order_data_values['final_price']/$t_order_data_values['products_quantity'],
|
143
|
1,
|
144
|
$t_order->info['currency']
|
145
|
),
|
146
|
'PRODUCTS_PRICE' => xtc_format_price_order(
|
147
|
$t_order_data_values['final_price'],
|
148
|
1,
|
149
|
$t_order->info['currency']
|
150
|
),
|
151
|
'PRODUCTS_QTY' => gm_prepare_number($t_order_data_values['products_quantity'], ',')
|
152
|
);
|
153
|
}
|
154
|
|
155
|
$t_oder_total_query=xtc_db_query("
|
156
|
SELECT
|
157
|
title,
|
158
|
text,
|
159
|
class,
|
160
|
value,
|
161
|
sort_order
|
162
|
FROM " .
|
163
|
TABLE_ORDERS_TOTAL . "
|
164
|
WHERE
|
165
|
orders_id = '" . (int)$t_row['orders_id'] . "'
|
166
|
ORDER BY
|
167
|
sort_order
|
168
|
ASC
|
169
|
");
|
170
|
|
171
|
$t_order_total = array();
|
172
|
|
173
|
while ($t_oder_total_values = xtc_db_fetch_array($t_oder_total_query)) {
|
174
|
$t_order_total[] = array(
|
175
|
'TITLE' => $t_oder_total_values['title'],
|
176
|
'CLASS' => $t_oder_total_values['class'],
|
177
|
'VALUE' => $t_oder_total_values['value'],
|
178
|
'TEXT' => $t_oder_total_values['text']
|
179
|
);
|
180
|
|
181
|
if($t_oder_total_values['class'] = 'ot_total') {
|
182
|
$total = $t_oder_total_values['value'];
|
183
|
}
|
184
|
}
|
185
|
|
186
|
|
187
|
if ($t_order->info['payment_method'] != '' && $t_order->info['payment_method']!= 'no_payment') {
|
188
|
include(DIR_FS_CATALOG . 'lang/' . $_SESSION['language'] . '/modules/payment/' . $t_order->info['payment_method'] . '.php');
|
189
|
$payment_method=constant(strtoupper('MODULE_PAYMENT_'.$t_order->info['payment_method'].'_TEXT_TITLE'));
|
190
|
$smarty->assign('PAYMENT_METHOD',$payment_method);
|
191
|
$smarty->assign('PAYMENT_MODUL', $t_order->info['payment_method']);
|
192
|
}
|
193
|
|
194
|
$smarty->assign('language', $_SESSION['language']);
|
195
|
$smarty->assign('csID', $t_order->customer['csID']);
|
196
|
$smarty->assign('oID', $t_row['orders_id']);
|
197
|
$smarty->assign('COMMENTS', $t_order->info['comments']);
|
198
|
$smarty->assign('DATE', xtc_date_long($t_order->info['date_purchased']));
|
199
|
$smarty->assign('NAME', $t_order->customer['name']);
|
200
|
$smarty->assign('GENDER', $t_order->customer['gender']);
|
201
|
$smarty->assign('COMMENTS', $t_order->info['comments']);
|
202
|
$smarty->assign('EMAIL', $t_order->customer['email_address']);
|
203
|
$smarty->assign('PHONE', $t_order->customer['telephone']);
|
204
|
$smarty->assign('order_data', $t_order_data);
|
205
|
$smarty->assign('order_total', $t_order_total);
|
206
|
$smarty->assign('address_label_customer', xtc_address_format($t_order->customer['format_id'], $t_order->customer, 1, '', '<br />'));
|
207
|
$smarty->assign('address_label_shipping', xtc_address_format($t_order->delivery['format_id'], $t_order->delivery, 1, '', '<br />'));
|
208
|
$smarty->assign('address_label_payment', xtc_address_format($t_order->billing['format_id'], $t_order->billing, 1, '', '<br />'));
|
209
|
|
210
|
/* BOF TRUSTED SHOPS RATING */
|
211
|
$t_rating_enabled = gm_get_conf('GM_TS_RATING_ENABLED') == 1;
|
212
|
$t_rating_cosuccess = gm_get_conf('GM_TS_RATING_COSUCCESS') == 1;
|
213
|
if($t_rating_enabled && $t_rating_cosuccess) {
|
214
|
$coo_ts_service = new GMTSService();
|
215
|
$t_customer_email = $t_order->customer['email_address'];
|
216
|
$t_orders_id = (int)$t_row['orders_id'];
|
217
|
$this->v_output_buffer['TS_RATING'] = $coo_ts_service->getRatingLink($t_orders_id, $t_customer_email);
|
218
|
$smarty->assign('TS_RATING', $coo_ts_service->getRatingLink($t_orders_id, $t_customer_email));
|
219
|
unset($coo_ts_service);
|
220
|
}
|
221
|
/* EOF TRUSTED SHOPS RATING */
|
222
|
|
223
|
$smarty->caching = false;
|
224
|
$smarty->template_dir = DIR_FS_CATALOG . 'templates';
|
225
|
$smarty->compile_dir = DIR_FS_CATALOG . 'templates_c';
|
226
|
$smarty->config_dir = DIR_FS_CATALOG . 'lang';
|
227
|
|
228
|
// EU Bank Transfer
|
229
|
if ($t_order->info['payment_method'] == 'eustandardtransfer')
|
230
|
{
|
231
|
$smarty->assign('PAYMENT_INFO_HTML', MODULE_PAYMENT_EUTRANSFER_TEXT_DESCRIPTION);
|
232
|
$smarty->assign('PAYMENT_INFO_TXT', str_replace("<br />", "\n", MODULE_PAYMENT_EUTRANSFER_TEXT_DESCRIPTION));
|
233
|
}
|
234
|
|
235
|
// MONEYORDER
|
236
|
if ($t_order->info['payment_method'] == 'moneyorder')
|
237
|
{
|
238
|
$smarty->assign('PAYMENT_INFO_HTML', MODULE_PAYMENT_MONEYORDER_TEXT_DESCRIPTION);
|
239
|
$smarty->assign('PAYMENT_INFO_TXT', str_replace("<br />", "\n", MODULE_PAYMENT_MONEYORDER_TEXT_DESCRIPTION));
|
240
|
}
|
241
|
|
242
|
/* MAIL LOGO */
|
243
|
$t_logo_mail = MainFactory::create_object('GMLogoManager', array("gm_logo_mail"));
|
244
|
if($t_logo_mail->logo_use == '1') {
|
245
|
$smarty->assign('gm_logo_mail', $t_logo_mail->get_logo());
|
246
|
}
|
247
|
|
248
|
if(defined('VRRL_ACTIVE') && VRRL_ACTIVE == true)
|
249
|
{
|
250
|
if(gm_get_conf('GM_SHOW_WITHDRAWAL') == 1 && gm_get_conf('WITHDRAWAL_WEBFORM_ACTIVE') == '1')
|
251
|
{
|
252
|
$t_link = generate_withdrawal_link($t_order->info['orders_hash']);
|
253
|
$smarty->assign('WITHDRAWAL_LINK', $t_link);
|
254
|
}
|
255
|
|
256
|
if(gm_get_conf('GM_SHOW_WITHDRAWAL') == 1 && gm_get_conf('WITHDRAWAL_PDF_ACTIVE') == '1')
|
257
|
{
|
258
|
$t_pdf_link = HTTP_SERVER . DIR_WS_CATALOG . 'request_port.php?module=Withdrawal&action=download_withdrawal_pdf_form&language=' . $_SESSION['language_code'];
|
259
|
$smarty->assign('PDF_LINK', $t_pdf_link);
|
260
|
}
|
261
|
}
|
262
|
|
263
|
$smarty->assign('SHOW_ABANDONMENT_WITHDRAWAL_DOWNLOADS_INFO', $t_row['abandonment_download']);
|
264
|
$smarty->assign('SHOW_ABANDONMENT_WITHDRAWAL_SERVICES_INFO', $t_row['abandonment_service']);
|
265
|
|
266
|
if(defined('EMAIL_SIGNATURE')) {
|
267
|
$smarty->assign('EMAIL_SIGNATURE_HTML', nl2br(EMAIL_SIGNATURE));
|
268
|
$smarty->assign('EMAIL_SIGNATURE_TEXT', EMAIL_SIGNATURE);
|
269
|
}
|
270
|
|
271
|
# JANOLAW START
|
272
|
require_once(DIR_FS_CATALOG.'gm/classes/GMJanolaw.php');
|
273
|
$coo_janolaw = new GMJanolaw();
|
274
|
if($coo_janolaw->get_status() == true)
|
275
|
{
|
276
|
$t_info_html = $coo_janolaw->get_page_content('widerrufsbelehrung', true, true);
|
277
|
$t_info_html .= '<br/><br/>AGB<br/><br/>';
|
278
|
$t_info_html .= $coo_janolaw->get_page_content('agb', true, true);
|
279
|
$smarty->assign('JANOLAW_INFO_HTML', $t_info_html);
|
280
|
|
281
|
$t_info_text = $coo_janolaw->get_page_content('widerrufsbelehrung', false, false);
|
282
|
$t_info_text .= "\n\nAGB\n\n";
|
283
|
$t_info_text .= $coo_janolaw->get_page_content('agb', false, false);
|
284
|
$smarty->assign('JANOLAW_INFO_TEXT', $t_info_text);
|
285
|
}
|
286
|
# JANOLAW END
|
287
|
|
288
|
$this->v_html = $smarty->fetch(CURRENT_TEMPLATE.'/mail/' . $_SESSION['language'] . '/order_mail.html');
|
289
|
|
290
|
if(isset($t_link))
|
291
|
{
|
292
|
$smarty->assign('WITHDRAWAL_LINK', str_replace('&', '&', $t_link));
|
293
|
}
|
294
|
|
295
|
if(isset($t_pdf_link))
|
296
|
{
|
297
|
$smarty->assign('PDF_LINK', str_replace('&', '&', $t_pdf_link));
|
298
|
}
|
299
|
|
300
|
$smarty->assign('address_label_customer', xtc_address_format($t_order->customer['format_id'], $t_order->customer, 0, '', "\n"));
|
301
|
$smarty->assign('address_label_shipping', xtc_address_format($t_order->delivery['format_id'], $t_order->delivery, 0, '', "\n"));
|
302
|
$smarty->assign('address_label_payment', xtc_address_format($t_order->billing['format_id'], $t_order->billing, 0, '', "\n"));
|
303
|
|
304
|
$t_txt = $smarty->fetch(CURRENT_TEMPLATE.'/mail/' . $_SESSION['language'] . '/order_mail.txt');
|
305
|
|
306
|
/* save order to DB */
|
307
|
gm_save_order($t_row['orders_id'], $this->v_html, $t_txt, $t_row['gm_send_order_status']);
|
308
|
|
309
|
return true;
|
310
|
}
|
311
|
|
312
|
/**
|
313
|
* get html of the order
|
314
|
*
|
315
|
* @access public
|
316
|
* @return string $this->v_html html of the order
|
317
|
*/
|
318
|
function getHtml()
|
319
|
{
|
320
|
return $this->v_html;
|
321
|
}
|
322
|
|
323
|
function get_shipping_time($p_product_id)
|
324
|
{
|
325
|
$t_products_id = (int)$p_product_id;
|
326
|
$t_sql = xtc_db_query("SELECT products_shippingtime,shipping_status_name FROM ".TABLE_PRDUCTS.",".TABLE_SHIPPING_STATUS." WHERE products_id=".$t_products_id." AND products_shippingtime=shipping_status_id AND language_id=".$_SESSION['language']);
|
327
|
$t_time = xtc_db_fetch_array($t_sql);
|
328
|
|
329
|
return $t_time['shipping_status_name'];
|
330
|
}
|
331
|
}
|