Completed
Push — master ( 9d3fbd...af269e )
by Michael
09:48
created

admin/actions/orders.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
12
/**
13
 * oledrion
14
 *
15
 * @copyright   {@link https://xoops.org/ XOOPS Project}
16
 * @license     {@link http://www.fsf.org/copyleft/gpl.html GNU public license}
17
 * @author      Hervé Thouzard (http://www.herve-thouzard.com/)
18
 */
19
/**
20
 * Gestion des commandes
21
 */
22
if (!defined('OLEDRION_ADMIN')) {
23
    exit();
24
}
25
switch ($action) {
26
    // ****************************************************************************************************************
27
    case 'default': // Gestion des commandes
28
        // ****************************************************************************************************************
29
        xoops_cp_header();
30
        $adminObject = \Xmf\Module\Admin::getInstance();
31
        $adminObject->displayNavigation('index.php?op=orders');
32
        //        OledrionUtility::htitle(_MI_OLEDRION_ADMENU5, 4);
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
33
34
        $start   = isset($_GET['start']) ? (int)$_GET['start'] : 0;
35
        $filter3 = $totalOrder = 0;
36
        if (isset($_POST['filter3'])) {
37
            $filter3 = (int)$_POST['filter3'];
38
        } elseif (isset($_SESSION['filter3'])) {
39
            $filter3 = (int)$_SESSION['filter3'];
40
        } else {
41
            $filter3 = 1;
42
        }
43
        $_SESSION['filter3'] = $filter3;
44
        $selected            = array('', '', '', '', '', '');
45
        $conditions          = array(
46
            OLEDRION_STATE_NOINFORMATION,
47
            OLEDRION_STATE_VALIDATED,
48
            OLEDRION_STATE_PENDING,
49
            OLEDRION_STATE_FAILED,
50
            OLEDRION_STATE_CANCELED,
51
            OLEDRION_STATE_FRAUD,
52
            OLEDRION_STATE_PACKED,
53
            OLEDRION_STATE_SUBMITED,
54
            OLEDRION_STATE_DELIVERYED
55
        );
56
        $selected[$filter3]  = ' selected';
57
58
        $criteria = new CriteriaCompo();
59
        $criteria->add(new Criteria('cmd_id', 0, '<>'));
60
        $criteria->add(new Criteria('cmd_state', $conditions[$filter3], '='));
61
        $itemsCount = $h_oledrion_commands->getCount($criteria); // Recherche du nombre total de commandes
62
        if ($itemsCount > $limit) {
63
            $pagenav = new XoopsPageNav($itemsCount, $limit, $start, 'start', 'op=orders');
64
        }
65
        $criteria->setSort('cmd_id');
66
        $criteria->setOrder('DESC');
67
        $criteria->setLimit($limit);
68
        $criteria->setStart($start);
69
        $orders = $h_oledrion_commands->getObjects($criteria);
70
        $class  = '';
71
        echo "<table width='100%' cellspacing='1' cellpadding='3' border='0' class='outer'>";
72
        $form              = "<form method='post' name='frmfilter' id='frmfilter' action='$baseurl'><b>" . _AM_OLEDRION_LIMIT_TO . "</b> <select name='filter3' id='filter3'>
73
        <option value='0'" . $selected[0] . '>' . _OLEDRION_CMD_STATE1 . "</option>
74
        <option value='1'" . $selected[1] . '>' . _OLEDRION_CMD_STATE2 . "</option>
75
        <option value='2'" . $selected[2] . '>' . _OLEDRION_CMD_STATE3 . "</option>
76
        <option value='3'" . $selected[3] . '>' . _OLEDRION_CMD_STATE4 . "</option>
77
        <option value='4'" . $selected[4] . '>' . _OLEDRION_CMD_STATE5 . "</option>
78
        <option value='5'" . $selected[5] . '>' . _OLEDRION_CMD_STATE6 . "</option>
79
        <option value='6'" . $selected[6] . '>' . _OLEDRION_CMD_STATE7 . "</option>
80
        <option value='7'" . $selected[7] . '>' . _OLEDRION_CMD_STATE8 . "</option>
81
        <option value='8'" . $selected[8] . '>' . _OLEDRION_CMD_STATE9 . "</option>
82
        </select> <input type='hidden' name='op' id='op' value='orders'><input type='submit' name='btnfilter' id='btnfilter' value='" . _AM_OLEDRION_FILTER . "'></form>";
83
        $confValidateOrder = OledrionUtility::javascriptLinkConfirm(_AM_OLEDRION_CONF_VALIDATE);
84
        $confPackOrder     = OledrionUtility::javascriptLinkConfirm(_AM_OLEDRION_CONF_PACK);
85
        $confSubmitOrder   = OledrionUtility::javascriptLinkConfirm(_AM_OLEDRION_CONF_SUBMIT);
86
        $confDeliveryOrder = OledrionUtility::javascriptLinkConfirm(_AM_OLEDRION_CONF_DELIVERY);
87
        echo "<tr><td colspan='2' align='left'>";
88
        if (isset($pagenav) && is_object($pagenav)) {
89
            echo $pagenav->renderNav();
90
        } else {
91
            echo '&nbsp;';
92
        }
93
        $exportFormats = glob(OLEDRION_PATH . 'admin/exports/*.php');
94
        $formats       = array();
95
        foreach ($exportFormats as $format) {
96
            if (false === strpos($format, 'export.php')) {
97
                $exportName = basename(str_replace('.php', '', $format));
98
                $formats[]  = '<option value="' . $exportName . '">' . $exportName . '</option>';
99
            }
100
        }
101
        echo "</td><td><form method='post' action='$baseurl' name='frmexport' id='frmexport'>"
102
             . _AM_OLEDRION_CSV_EXPORT
103
             . "<input type='hidden' name='op' id='op' value='orders'><input type='hidden' name='action' id='action' value='export'><input type='hidden' name='cmdtype' id='cmdtype' value='$filter3'><select name='exportfilter' id='exportfilter' size='1'>"
104
             . implode("\n", $formats)
105
             . "</select> <input type='submit' name='btngoexport' id='btngoexport' value='"
106
             . _AM_OLEDRION_OK
107
             . "'></form></td><td align='right' colspan='2'>"
108
             . $form
109
             . "</td></tr>\n";
110
        echo "<tr><th align='center'>" . _AM_OLEDRION_ID . "</th><th align='center'>" . _AM_OLEDRION_DATE . "</th><th align='center'>" . _AM_OLEDRION_CLIENT . "</th><th align='center'>" . _AM_OLEDRION_TOTAL_SHIPP . "</th><th align='center'>" . _AM_OLEDRION_ACTION . '</th></tr>';
111
        foreach ($orders as $item) {
112
            $id        = $item->getVar('cmd_id');
113
            $class     = ($class === 'even') ? 'odd' : 'even';
114
            $date      = formatTimestamp(strtotime($item->getVar('cmd_date')), 's');
115
            $actions   = array();
116
            $actions[] = "<a target='_blank' href='" . OLEDRION_URL . 'invoice.php?id=' . $id . "' title='" . _OLEDRION_DETAILS . "'>" . $icones['details'] . '</a>';
117
            $actions[] = "<a target='_blank' href='$baseurl?op=orders&action=print&id=" . $id . "' title='" . _OLEDRION_PRINT_VERSION . "'>" . $icones['print'] . '</a>';
118
            $actions[] = "<a href='$baseurl?op=orders&action=delete&id=" . $id . "' title='" . _OLEDRION_DELETE . "'" . $conf_msg . '>' . $icones['delete'] . '</a>';
119
            $actions[] = "<a href='$baseurl?op=orders&action=validate&id=" . $id . "' " . $confValidateOrder . " title='" . _OLEDRION_VALIDATE_COMMAND . "'>" . $icones['ok'] . '</a>';
120
            $actions[] = "<a href='$baseurl?op=orders&action=pack&id=" . $id . "' " . $confPackOrder . " title='" . _OLEDRION_PACK . "'>" . $icones['package'] . '</a>';
121
            $actions[] = "<a href='$baseurl?op=orders&action=submit&id=" . $id . "' " . $confSubmitOrder . " title='" . _OLEDRION_SUBMIT . "'>" . $icones['submit'] . '</a>';
122
            $actions[] = "<a href='$baseurl?op=orders&action=delivery&id=" . $id . "' " . $confDeliveryOrder . " title='" . _OLEDRION_DELIVERY . "'>" . $icones['delivery'] . '</a>';
123
            $actions[] = "<a href='$baseurl?op=orders&action=track&id=" . $id . "' title='" . _OLEDRION_TRACK . "'>" . $icones['track'] . '</a>';
124
            $gift      = $item->getVar('cmd_gift') ?: '';
125
            echo "<tr class='" . $class . "'>\n";
126
            echo "<td align='center'>"
127
                 . $id
128
                 . "</td><td align='center'>"
129
                 . $date
130
                 . "</td><td align='center'>"
131
                 . $item->getVar('cmd_lastname')
132
                 . ' '
133
                 . $item->getVar('cmd_firstname')
134
                 . ' '
135
                 . $gift
136
                 . "</td><td align='center'>"
137
                 . $oledrion_Currency->amountForDisplay($item->getVar('cmd_total', 'n'))
138
                 . ' / '
139
                 . $oledrion_Currency->amountForDisplay($item->getVar('cmd_shipping'))
140
                 . "</td><td align='center'>"
141
                 . implode(' ', $actions)
142
                 . "</td>\n";
143
            echo "<tr>\n";
144
            $totalOrder += (float)$item->getVar('cmd_total', 'n');
145
        }
146
        $class = ($class === 'even') ? 'odd' : 'even';
147
        echo "<tr class='$class'><td colspan='2' align='center'><b>" . _OLEDRION_TOTAL . "</b></td><td>&nbsp;</td><td align='right'><b>" . $oledrion_Currency->amountForDisplay($totalOrder) . '</b></td><td>&nbsp;</td></tr>';
148
        echo '</table>';
149
        if (isset($pagenav) && is_object($pagenav)) {
150
            echo "<div align='right'>" . $pagenav->renderNav() . '</div>';
151
        }
152
        require_once OLEDRION_ADMIN_PATH . 'admin_footer.php';
153
        break;
154
155
    // ****************************************************************************************************************
156 View Code Duplication
    case 'delete': // Suppression d'une commande
157
        // ****************************************************************************************************************
158
        xoops_cp_header();
159
        $id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
160
        if ($id == 0) {
161
            OledrionUtility::redirect(_AM_OLEDRION_ERROR_1, $baseurl, 5);
162
        }
163
        $item = $h_oledrion_commands->get($id);
164
        if (is_object($item)) {
165
            xoops_confirm(array('op' => 'orders', 'action' => 'remove', 'id' => $id), 'index.php', _AM_OLEDRION_CONF_DELITEM);
166
        } else {
167
            OledrionUtility::redirect(_AM_OLEDRION_NOT_FOUND, $baseurl . '?op=' . $opRedirect, 5);
168
        }
169
        break;
170
171
    // ****************************************************************************************************************
172
    case 'remove': // Suppression effective d'une commande
173
        // ****************************************************************************************************************
174
        $id = isset($_POST['id']) ? (int)$_POST['id'] : 0;
175
        if (empty($id)) {
176
            OledrionUtility::redirect(_AM_OLEDRION_ERROR_1, $baseurl, 5);
177
        }
178
        $opRedirect = 'orders';
179
        $item       = $h_oledrion_commands->get($id);
180
        if (is_object($item)) {
181
            $res = $h_oledrion_commands->removeOrder($item);
182
            if ($res) {
183
                OledrionUtility::redirect(_AM_OLEDRION_SAVE_OK, $baseurl . '?op=' . $opRedirect, 2);
184
            } else {
185
                OledrionUtility::redirect(_AM_OLEDRION_SAVE_PB, $baseurl . '?op=' . $opRedirect, 5);
186
            }
187
        } else {
188
            OledrionUtility::redirect(_AM_OLEDRION_NOT_FOUND, $baseurl . '?op=' . $opRedirect, 5);
189
        }
190
        break;
191
192
    // ****************************************************************************************************************
193 View Code Duplication
    case 'validate': // Validation d'une commande
194
        // ****************************************************************************************************************
195
        xoops_cp_header();
196
        $id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
197
        if (empty($id)) {
198
            OledrionUtility::redirect(_AM_OLEDRION_ERROR_1, $baseurl, 5);
199
        }
200
        $opRedirect = 'orders';
201
        $item       = $h_oledrion_commands->get($id);
202
        if (is_object($item)) {
203
            $res = $h_oledrion_commands->validateOrder($item);
204
            if ($res) {
205
                // Send sms
206
                if (OledrionUtility::getModuleOption('sms_validate')) {
207
                    $information['to']   = ltrim($item->getVar('cmd_mobile'), 0);
208
                    $information['text'] = OledrionUtility::getModuleOption('sms_validate_text');
209
                    $sms                 = Oledrion_sms::sendSms($information);
210
                }
211
                //
212
                OledrionUtility::redirect(_AM_OLEDRION_SAVE_OK, $baseurl . '?op=' . $opRedirect, 2);
213
            } else {
214
                OledrionUtility::redirect(_AM_OLEDRION_SAVE_PB, $baseurl . '?op=' . $opRedirect, 5);
215
            }
216
        } else {
217
            OledrionUtility::redirect(_AM_OLEDRION_NOT_FOUND, $baseurl . '?op=' . $opRedirect, 5);
218
        }
219
        break;
220
221
    // ****************************************************************************************************************
222 View Code Duplication
    case 'pack': // Validation d'une commande
223
        // ****************************************************************************************************************
224
        xoops_cp_header();
225
        $id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
226
        if (empty($id)) {
227
            OledrionUtility::redirect(_AM_OLEDRION_ERROR_1, $baseurl, 5);
228
        }
229
        $opRedirect = 'orders';
230
        $item       = $h_oledrion_commands->get($id);
231
        if (is_object($item)) {
232
            $res = $h_oledrion_commands->packOrder($item);
233
            if ($res) {
234
                // Send sms
235
                if (OledrionUtility::getModuleOption('sms_validate')) {
236
                    $information['to']   = ltrim($item->getVar('cmd_mobile'), 0);
237
                    $information['text'] = OledrionUtility::getModuleOption('sms_pack_text');
238
                    $sms                 = Oledrion_sms::sendSms($information);
239
                }
240
                //
241
                OledrionUtility::redirect(_AM_OLEDRION_SAVE_OK, $baseurl . '?op=' . $opRedirect, 2);
242
            } else {
243
                OledrionUtility::redirect(_AM_OLEDRION_SAVE_PB, $baseurl . '?op=' . $opRedirect, 5);
244
            }
245
        } else {
246
            OledrionUtility::redirect(_AM_OLEDRION_NOT_FOUND, $baseurl . '?op=' . $opRedirect, 5);
247
        }
248
        break;
249
250
    // ****************************************************************************************************************
251 View Code Duplication
    case 'submit': // Validation d'une commande
252
        // ****************************************************************************************************************
253
        xoops_cp_header();
254
        $id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
255
        if (empty($id)) {
256
            OledrionUtility::redirect(_AM_OLEDRION_ERROR_1, $baseurl, 5);
257
        }
258
        $opRedirect = 'orders';
259
        $item       = $h_oledrion_commands->get($id);
260
        if (is_object($item)) {
261
            $res = $h_oledrion_commands->submitOrder($item);
262
            if ($res) {
263
                // Send sms
264
                if (OledrionUtility::getModuleOption('sms_validate')) {
265
                    $information['to']   = ltrim($item->getVar('cmd_mobile'), 0);
266
                    $information['text'] = OledrionUtility::getModuleOption('sms_submit_text');
267
                    $sms                 = Oledrion_sms::sendSms($information);
268
                }
269
                //
270
                OledrionUtility::redirect(_AM_OLEDRION_SAVE_OK, $baseurl . '?op=' . $opRedirect, 2);
271
            } else {
272
                OledrionUtility::redirect(_AM_OLEDRION_SAVE_PB, $baseurl . '?op=' . $opRedirect, 5);
273
            }
274
        } else {
275
            OledrionUtility::redirect(_AM_OLEDRION_NOT_FOUND, $baseurl . '?op=' . $opRedirect, 5);
276
        }
277
        break;
278
279
    // ****************************************************************************************************************
280 View Code Duplication
    case 'delivery': // Validation d'une commande
281
        // ****************************************************************************************************************
282
        xoops_cp_header();
283
        $id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
284
        if (empty($id)) {
285
            OledrionUtility::redirect(_AM_OLEDRION_ERROR_1, $baseurl, 5);
286
        }
287
        $opRedirect = 'orders';
288
        $item       = $h_oledrion_commands->get($id);
289
        if (is_object($item)) {
290
            $res = $h_oledrion_commands->deliveryOrder($item);
291
            if ($res) {
292
                // Send sms
293
                if (OledrionUtility::getModuleOption('sms_validate')) {
294
                    $information['to']   = ltrim($item->getVar('cmd_mobile'), 0);
295
                    $information['text'] = OledrionUtility::getModuleOption('sms_delivery_text');
296
                    $sms                 = Oledrion_sms::sendSms($information);
297
                }
298
                //
299
                OledrionUtility::redirect(_AM_OLEDRION_SAVE_OK, $baseurl . '?op=' . $opRedirect, 2);
300
            } else {
301
                OledrionUtility::redirect(_AM_OLEDRION_SAVE_PB, $baseurl . '?op=' . $opRedirect, 5);
302
            }
303
        } else {
304
            OledrionUtility::redirect(_AM_OLEDRION_NOT_FOUND, $baseurl . '?op=' . $opRedirect, 5);
305
        }
306
        break;
307
308
    // ****************************************************************************************************************
309
    case 'export': // Export des commandes au format CSV
310
        // ****************************************************************************************************************
311
        xoops_cp_header();
312
        $adminObject = \Xmf\Module\Admin::getInstance();
313
        $adminObject->displayNavigation('index.php?op=orders');
314
        OledrionUtility::htitle(_MI_OLEDRION_ADMENU5, 4);
315
316
        $orderType      = (int)$_POST['cmdtype'];
317
        $exportFilter   = $_POST['exportfilter'];
318
        $exportFilename = OLEDRION_PATH . 'admin/exports/' . $exportFilter . '.php';
319
        if (file_exists($exportFilename)) {
320
            require_once OLEDRION_PATH . 'admin/exports/export.php';
321
            require_once $exportFilename;
322
            $className = 'oledrion_' . $exportFilter . '_export';
323
            if (class_exists($className)) {
324
                $export = new $className();
325
                $export->setOrderType($orderType);
326
                $result = $export->export();
327
                if ($result === true) {
328
                    echo "<a href='" . $export->getDownloadUrl() . "'>" . _AM_OLEDRION_EXPORT_READY . '</a>';
329
                }
330
            }
331
        } else {
332
            OledrionUtility::redirect(_AM_OLEDRION_ERROR_11);
333
        }
334
        require_once OLEDRION_ADMIN_PATH . 'admin_footer.php';
335
        break;
336
337
    // ****************************************************************************************************************
338
    case 'track': // track
339
        // ****************************************************************************************************************
340
        xoops_cp_header();
341
        $adminObject = \Xmf\Module\Admin::getInstance();
342
        $adminObject->displayNavigation('index.php?op=orders');
343
        OledrionUtility::htitle(_MI_OLEDRION_ADMENU5, 4);
344
        $id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
345
        if (empty($id)) {
346
            OledrionUtility::redirect(_AM_OLEDRION_ERROR_1, $baseurl, 5);
347
        }
348
        $item = $h_oledrion_commands->get($id);
349
350
        $sform = new XoopsThemeForm(_OLEDRION_TRACK, 'frmproduct', $baseurl);
351
        $sform->setExtra('enctype="multipart/form-data"');
352
        $sform->addElement(new XoopsFormHidden('op', 'orders'));
353
        $sform->addElement(new XoopsFormHidden('action', 'savetrack'));
354
        $sform->addElement(new XoopsFormHidden('cmd_id', $item->getVar('cmd_id')));
355
        $sform->addElement(new XoopsFormText(_OLEDRION_TRACK, 'cmd_track', 50, 255, $item->getVar('cmd_track', 'e')), true);
356
        $button_tray = new XoopsFormElementTray('', '');
357
        $submit_btn  = new XoopsFormButton('', 'post', _SUBMIT, 'submit');
358
        $button_tray->addElement($submit_btn);
359
        $sform->addElement($button_tray);
360
        $sform =& OledrionUtility::formMarkRequiredFields($sform);
361
        $sform->display();
362
363
        require_once OLEDRION_ADMIN_PATH . 'admin_footer.php';
364
        break;
365
366
    // ****************************************************************************************************************
367
    case 'savetrack': // save track
368
        // ****************************************************************************************************************
369
        xoops_cp_header();
370
        $id         = isset($_POST['cmd_id']) ? (int)$_POST['cmd_id'] : 0;
371
        $item       = $h_oledrion_commands->get($id);
372
        $opRedirect = 'orders';
373
        if (!is_object($item)) {
374
            OledrionUtility::redirect(_AM_OLEDRION_NOT_FOUND, $baseurl, 5);
375
        }
376
        $item->setVar('cmd_track', $_POST['cmd_track']);
377
        $res = $h_oledrion_commands->insert($item);
378
        if ($res) {
379
            // Send sms
380
            if (OledrionUtility::getModuleOption('sms_track')) {
381
                $information['to']   = ltrim($item->getVar('cmd_mobile'), 0);
382
                $information['text'] = sprintf(OledrionUtility::getModuleOption('sms_track_text'), $_POST['cmd_track']);
383
                $sms                 = Oledrion_sms::sendSms($information);
384
            }
385
            OledrionUtility::redirect(_AM_OLEDRION_SAVE_OK, $baseurl . '?op=' . $opRedirect, 2);
386
        } else {
387
            OledrionUtility::redirect(_AM_OLEDRION_SAVE_PB, $baseurl . '?op=' . $opRedirect, 5);
388
        }
389
        break;
390
391
    // ****************************************************************************************************************
392
    case 'print': // Print invoice
393
        // ****************************************************************************************************************
394
        xoops_cp_header();
395
        error_reporting(0);
396
        @$xoopsLogger->activated = false;
397
        $cmdId = isset($_GET['id']) ? (int)$_GET['id'] : 0;
398
        if ($cmdId == 0) {
399
            OledrionUtility::redirect(_AM_OLEDRION_ERROR_1, $baseurl, 5);
400
        }
401
        $order = null;
402
        $order = $h_oledrion_commands->get($cmdId);
403
        $caddy = $tmp = $products = $vats = $manufacturers = $tmp2 = $manufacturers = $productsManufacturers = array();
404
405
        // Récupération des TVA
406
        $vats = $h_oledrion_vat->getAllVats(new Oledrion_parameters());
407
408
        // Récupération des caddy associés
409
        $caddy = $h_oledrion_caddy->getCaddyFromCommand($cmdId);
410
        if (count($caddy) == 0) {
411
            OledrionUtility::redirect(_OLEDRION_ERROR11, 'index.php', 6);
412
        }
413
414
        // Récupération de la liste des produits associés
415
        foreach ($caddy as $item) {
416
            $tmp[] = $item->getVar('caddy_product_id');
417
        }
418
419
        // Recherche des produits ***********************************************************************************************
420
        $products = $h_oledrion_products->getProductsFromIDs($tmp, true);
421
422
        // Recherche des fabricants **********************************************************************************************
423
        $tmp2 = $h_oledrion_productsmanu->getFromProductsIds($tmp);
424
        $tmp  = array();
425 View Code Duplication
        foreach ($tmp2 as $item) {
426
            $tmp[]                                                   = $item->getVar('pm_manu_id');
427
            $productsManufacturers[$item->getVar('pm_product_id')][] = $item;
428
        }
429
        $manufacturers     = $h_oledrion_manufacturer->getManufacturersFromIds($tmp);
430
        $handlers          = OledrionHandler::getInstance();
431
        $oledrion_Currency = Oledrion_Currency::getInstance();
432
        // Informations sur la commande ***************************************************************************************
433
        foreach ($caddy as $itemCaddy) {
434
            $productForTemplate = $tblJoin = $productManufacturers = $productAttributes = array();
435
            $product            = $products[$itemCaddy->getVar('caddy_product_id')];
436
            $productForTemplate = $product->toArray(); // Produit
437
            // Get cat title
438
            $cat                                     = $h_oledrion_cat->get($productForTemplate['product_cid'])->toArray();
439
            $productForTemplate['product_cat_title'] = $cat['cat_title'];
440
            // Est-ce qu'il y a des attributs ?
441
            if ($handlers->h_oledrion_caddy_attributes->getAttributesCountForCaddy($itemCaddy->getVar('caddy_id')) > 0) {
442
                $productAttributes = $handlers->h_oledrion_caddy_attributes->getFormatedAttributesForCaddy($itemCaddy->getVar('caddy_id'), $product);
443
            }
444
            $productForTemplate['product_attributes']       = $productAttributes;
445
            $productForTemplate['product_attributes_count'] = count($productAttributes[0]['attribute_options']);
446
447
            $productManufacturers = $productsManufacturers[$product->getVar('product_id')];
448
            foreach ($productManufacturers as $oledrion_productsmanu) {
449
                if (isset($manufacturers[$oledrion_productsmanu->getVar('pm_manu_id')])) {
450
                    $manufacturer = $manufacturers[$oledrion_productsmanu->getVar('pm_manu_id')];
451
                    $tblJoin[]    = $manufacturer->getVar('manu_commercialname') . ' ' . $manufacturer->getVar('manu_name');
452
                }
453
            }
454
            if (count($tblJoin) > 0) {
455
                $productForTemplate['product_joined_manufacturers'] = implode(', ', $tblJoin);
456
            }
457
            $productForTemplate['product_caddy'] = $itemCaddy->toArray();
458
            if ($productForTemplate['product_final_price_ttc']) {
459
                $discount = ($productForTemplate['product_caddy']['caddy_qte'] * $productForTemplate['product_final_price_ttc']) - ((int)$productForTemplate['product_caddy']['caddy_price']);
460
                $discount = $discount / $productForTemplate['product_caddy']['caddy_qte'];
461
            } else {
462
                $discount = 0;
463
            }
464
            $productForTemplate['product_caddy']['caddy_price_t'] = $oledrion_Currency->amountForDisplay($discount);
465
            $xoopsTpl->append('products', $productForTemplate);
466
            /*
467
               echo '<pre>';
468
               print_r($productForTemplate);
469
               echo '</pre>';
470
            */
471
        }
472
        $order = $order->toArray();
473
        $xoopsTpl->assign('order', $order);
474
        // Call template file
475
        $xoopsTpl->display(XOOPS_ROOT_PATH . '/modules/oledrion/templates/admin/oledrion_order_print.tpl');
476
        exit();
477
        xoops_cp_footer();
478
        break;
479
}
480