Completed
Push — master ( 00e474...9d3fbd )
by Michael
04:26
created

product.php (5 issues)

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 http://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
/**
21
 * Affichage d'un produit
22
 */
23
require __DIR__ . '/header.php';
24
require_once XOOPS_ROOT_PATH . '/class/tree.php';
25
26
$product_id = 0;
27
// Les tests **************************************************************************************
28
// Recherche du n° de produit
29
if (isset($_GET['product_id'])) {
30
    $product_id = (int)$_GET['product_id'];
31
} else {
32
    Oledrion_utils::redirect(_OLEDRION_ERROR1, 'index.php', 5);
33
}
34
// Le produit existe ?
35
$product = null;
36
$product = $h_oledrion_products->get($product_id);
37
if (!is_object($product)) {
38
    Oledrion_utils::redirect(_OLEDRION_ERROR1, 'index.php', 5);
39
}
40
41
// Le produit est en ligne ?
42
if ($product->getVar('product_online') == 0) {
43
    Oledrion_utils::redirect(_OLEDRION_ERROR2, 'index.php', 5);
44
}
45
46
// Le produit est publié ?
47 View Code Duplication
if (Oledrion_utils::getModuleOption('show_unpublished') == 0 && $product->getVar('product_submitted') > time()) {
48
    Oledrion_utils::redirect(_OLEDRION_ERROR3, 'index.php', 5);
49
}
50
51
// Faut il afficher les produit même lorsqu'ils ne sont plus en stock ?
52
if (Oledrion_utils::getModuleOption('nostock_display') == 0 && $product->getVar('product_stock') == 0) {
53
    if (xoops_trim(Oledrion_utils::getModuleOption('nostock_display')) != '') {
54
        Oledrion_utils::redirect(Oledrion_utils::getModuleOption('nostock_display'), 'main.php', 5);
55
    }
56
}
57
58
// Fin des tests, si on est encore là c'est que tout est bon **************************************
59
//$title = strip_tags($product->getVar('product_title')) . ' - ' . Oledrion_utils::getModuleName();
60
$title    = strip_tags($product->getVar('product_title'));
61
$handlers = OledrionHandler::getInstance();
62
$op       = isset($_GET['op']) ? $_GET['op'] : 'default';
63
switch ($op) {
64
    // product Print
65
    case 'print' :
66
        require_once XOOPS_ROOT_PATH . '/header.php';
67
        //
68
        $GLOBALS['current_category'] = 0;
69
        $xoopsConfig['sitename']     = $title;
70
        // product to array
71
        $product = $product->toArray();
72
        // Set local style
73
        if (file_exists(XOOPS_ROOT_PATH . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/style.css')) {
74
            $xoopsTpl->assign('localstyle', XOOPS_URL . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/style.css');
75
        } else {
76
            $xoopsTpl->assign('localstyle', XOOPS_URL . '/language/english/style.css');
77
        }
78
        // Index Variable
79
        $xoopsTpl->assign('xoops_sitename', $xoopsConfig['sitename']);
80
        $xoopsTpl->assign('xoops_pagetitle', $title);
81
        $xoopsTpl->assign('product', $product);
82
        // Display print page
83
        echo $xoopsTpl->fetch(OLEDRION_PATH . '/templates/oledrion_product_print.tpl');
84
        break;
85
86
    // product view
87
    case 'default' :
88
    default :
89
        // Lecture des TVA ********************************************************************************
90
        $vatArray = array();
91
        $vatArray = $h_oledrion_vat->getAllVats(new Oledrion_parameters());
92
        //
93
        $GLOBALS['xoopsOption']['template_main'] = 'oledrion_product.tpl';
94
        $GLOBALS['current_category']             = $product->getVar('product_cid');
95
        require_once XOOPS_ROOT_PATH . '/header.php';
96
97
        if (!OLEDRION_MY_THEME_USES_JQUERY) {
98
            $xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');
99
        }
100
        //Oledrion_utils::callJavascriptFile('noconflict.js');
101
        // Add lightbox
102
        //$xoTheme->addScript('browse.php?Frameworks/jquery/plugins/jquery.lightbox.js');
103
        //$xoTheme->addStylesheet(XOOPS_URL . '/modules/system/css/lightbox.css');
104
105
        if (isset($_GET['stock']) && $_GET['stock'] === 'add'
106
            && Oledrion_utils::isMemberOfGroup(Oledrion_utils::getModuleOption('grp_qty'))
107
        ) {
108
            $h_oledrion_products->increaseStock($product);
109
        }
110
111
        if (isset($_GET['stock']) && $_GET['stock'] === 'substract'
112
            && Oledrion_utils::isMemberOfGroup(Oledrion_utils::getModuleOption('grp_qty'))
113
        ) {
114
            $h_oledrion_products->decreaseStock($product);
115
            $h_oledrion_products->verifyLowStock($product);
116
        }
117
118
        $currentUser = Oledrion_utils::getCurrentUserID();
119
        $xoopsTpl->assign('currentUserId', $currentUser);
120
121
        $baseurl = OLEDRION_URL . basename(__FILE__) . '?product_id=' . $product->getVar('product_id');
122
123
        if (Oledrion_utils::getModuleOption('use_tags')) {
124
            require_once XOOPS_ROOT_PATH . '/modules/tag/include/tagbar.php';
125
            $xoopsTpl->assign('tagbar', tagBar($product_id, 0));
126
        }
127
128
        // Quelques options pour le template
129
        $xoopsTpl->assign('baseurl', $baseurl);
130
        $xoopsTpl->assign('nostock_msg', Oledrion_utils::getModuleOption('nostock_msg'));
131
        $xoopsTpl->assign('mod_pref', $mod_pref);
132
        // Préférences du module
133
        $xoopsTpl->assign('columnsCount', Oledrion_utils::getModuleOption('catagory_colums'));
134
        $xoopsTpl->assign('icones', $icones);
135
        $xoopsTpl->assign('canRateProducts', Oledrion_utils::getModuleOption('rateproducts'));
136
        // Préférences du module
137
        $xoopsTpl->assign('mail_link',
138
                          'mailto:?subject=' . sprintf(_OLEDRION_INTARTICLE, $xoopsConfig['sitename']) . '&amp;body=' . sprintf(_OLEDRION_INTARTFOUND, $xoopsConfig['sitename']) . ':  ' . XOOPS_URL . '/modules/oledrion/product.php?product_id='
139
                          . $product_id);
140
        $xoopsTpl->assign('canChangeQuantity', Oledrion_utils::isMemberOfGroup(Oledrion_utils::getModuleOption('grp_qty')));
141
        // Groupe autorisé à modifier les quantités depuis la page
142
        $xoopsTpl->assign('ProductStockQuantity', sprintf(_OLEDRION_QUANTITY_STOCK, $product->getVar('product_stock')));
143
144
        // Recherche de la catégorie du produit
145
        $tbl_tmp          = $tbl_categories = $tbl_ancestors = array();
146
        $tbl_categories   = $h_oledrion_cat->getAllCategories(new Oledrion_parameters());
147
        $product_category = null;
148
        $product_category = isset($tbl_categories[$product->getVar('product_cid')]) ? $tbl_categories[$product->getVar('product_cid')] : null;
149
        if (!is_object($product_category)) {
150
            Oledrion_utils::redirect(_OLEDRION_ERROR4, 'index.php', 5);
151
        }
152
153
        // Recherche de sa langue
154
        $product_vendor = null;
155
        $product_vendor = $h_oledrion_vendors->get($product->getVar('product_vendor_id'));
156
        if (!is_object($product_vendor)) {
157
            Oledrion_utils::redirect(_OLEDRION_ERROR5, 'index.php', 5);
158
        }
159
160
        // Chargement de toutes les TVA
161
        $tblVat = array();
162
        $tblVat = $h_oledrion_vat->getAllVats(new Oledrion_parameters());
163
164
        // Recherche de sa TVA
165
        $product_vat = null;
166
        if (isset($tblVat[$product->getVar('product_vat_id')])) {
167
            $product_vat = $tblVat[$product->getVar('product_vat_id')];
168
        }
169
        if (!is_object($product_vat) && Oledrion_utils::getModuleOption('use_price')) {
170
            Oledrion_utils::redirect(_OLEDRION_ERROR6, 'index.php', 5);
171
        }
172
173
        // Recherche de l'utilisateur qui a soumit ce produit
174
        $product_user = null;
175
        $userHandler = $memberHandler = xoops_getHandler('user');
176
        $product_user = $userHandler->get($product->getVar('product_submitter'), true);
177
        $xoopsTpl->assign('product_submitter', $product_user);
178
179
        // Image du bouton "Ajouter au panier"
180
        if (file_exists(OLEDRION_PATH . 'language/' . $xoopsConfig['language'] . '/image/addtocart.png')) {
181
            $addToCart     = OLEDRION_URL . 'language/' . $xoopsConfig['language'] . '/image/addtocart.png';
182
            $addToWishList = OLEDRION_URL . 'language/' . $xoopsConfig['language'] . '/image/addtowishlist.png';
183
        } else {
184
            // Fallback
185
            $addToCart     = OLEDRION_URL . 'language/english/image/addtocart.png';
186
            $addToWishList = OLEDRION_URL . 'language/english/image/addtowishlist.png';
187
        }
188
        $xoopsTpl->assign('addToCartImage', $addToCart);
189
        $xoopsTpl->assign('addToWishList', $addToWishList);
190
191
        // Recherche des fabricants du produit **********************************************
192
        $tbl_auteurs = $tbl_translators = $tbl_tmp = $tbl_tmp2 = $tbl_join1 = $tbl_join2 = array();
193
        $criteria    = new Criteria('pm_product_id', $product->getVar('product_id'), '=');
194
        $tbl_tmp     = $h_oledrion_productsmanu->getObjects($criteria, true);
195
        foreach ($tbl_tmp as $id => $item) {
196
            $tbl_tmp2[] = $item->getVar('pm_manu_id');
197
        }
198
        if (count($tbl_tmp2) > 0) {
199
            $tbl_product_manufacturers = array();
200
            $tbl_auteurs               = $h_oledrion_manufacturer->getObjects(new Criteria('manu_id', '(' . implode(',', $tbl_tmp2) . ')', 'IN'), true);
201
            foreach ($tbl_auteurs as $item) {
202
                $xoopsTpl->append('product_manufacturers', $item->toArray());
203
                $tbl_join1[] = "<a href='" . $item->getLink() . "' title='" . Oledrion_utils::makeHrefTitle($item->getVar('manu_commercialname') . ' ' . $item->getVar('manu_name')) . "'>" . $item->getVar('manu_commercialname') . ' '
204
                               . $item->getVar('manu_name') . '</a>';
205
            }
206
        }
207
        if (count($tbl_join1) > 0) {
208
            $xoopsTpl->assign('product_joined_manufacturers', implode(', ', $tbl_join1));
209
        }
210
        if (count($tbl_join2) > 0) {
211
            $xoopsTpl->assign('product_joined_vendors', implode(', ', $tbl_join2));
212
        }
213
214
        // Recherche des produits relatifs ******************************************************************
215
        $revertRelated = false;
216
        $tbl_tmp       = $tbl_tmp2 = array();
217
        $criteria      = new Criteria('related_product_id', $product->getVar('product_id'), '=');
218
        $tbl_tmp       = $h_oledrion_related->getObjects($criteria);
219
220
        // S'il n'y a pas de produits relatifs et que la bonne option est activée, on recherche les produits relatfis "dans l'autre sens" (les cas où le produit courant est marqué comme produit relatif)
221
        if (count($tbl_tmp) == 0 && OLEDRION_RELATED_BOTH) {
222
            unset($criteria);
223
            $tbl_tmp       = array();
224
            $criteria      = new Criteria('related_product_related', $product->getVar('product_id'), '=');
225
            $tbl_tmp       = $h_oledrion_related->getObjects($criteria);
226
            $revertRelated = true;
227
        }
228
229
        if (count($tbl_tmp) > 0) {
230
            foreach ($tbl_tmp as $item) {
231
                if (!$revertRelated) {
232
                    $tbl_tmp2[] = $item->getVar('related_product_related');
233
                } else {
234
                    $tbl_tmp2[] = $item->getVar('related_product_id');
235
                }
236
            }
237
            $criteria = new Criteria('product_id', '(' . implode(',', $tbl_tmp2) . ')', 'IN');
238
            $criteria->setLimit(Oledrion_utils::getModuleOption('related_limit'));
239
            $criteria->setOrder('DESC');
240
            $criteria->setSort('product_id');
241
            $tbl_related_products = array();
242
            $tbl_related_products = $h_oledrion_products->getObjects($criteria, true);
243
            if (count($tbl_related_products) > 0) {
244
                $cpt = 1;
245
                foreach ($tbl_related_products as $item) {
246
                    $tbl_tmp                     = $item->toArray();
247
                    $tbl_tmp['count']            = $cpt;
248
                    $tbl_tmp['product_category'] = isset($tbl_categories[$item->getVar('product_cid')]) ? $tbl_categories[$item->getVar('product_cid')]->toArray() : null;
249
                    $xoopsTpl->append('product_related_products', $tbl_tmp);
250
                    ++$cpt;
251
                }
252
            }
253
        }
254
255
        // Recherche des fichiers attachés au produit *******************************************************
256
        $attachedFiles      = $mp3AttachedFilesList = $attachedFilesForTemplate = array();
257
        $attachedFilesCount = $h_oledrion_files->getProductFilesCount($product->getVar('product_id'));
258
        if ($attachedFilesCount > 0) {
259
            $attachedFiles = $h_oledrion_files->getProductFiles($product->getVar('product_id'));
260
            foreach ($attachedFiles as $attachedFile) {
261
                // Recherche de fichiers MP3
262
                if ($attachedFile->isMP3()) {
263
                    $mp3AttachedFilesList[] = $attachedFile->getURL();
264
                }
265
                $attachedFilesForTemplate[] = $attachedFile->toArray();
266
            }
267
            if (count($mp3AttachedFilesList) > 0) {
268
                Oledrion_utils::callJavascriptFile('jquery.swfobject/jquery.swfobject.min.js');
269
                $xoopsTpl->assign('mp3FilesList', implode('|', $mp3AttachedFilesList));
270
            }
271
        }
272
273
        // Informations du produit **************************************************************************
274
        $tbl_tmp = array();
275
        $tbl_tmp = $product->toArray();
276
        // Fichiers attachés
277
        $tbl_tmp['attached_mp3_count']     = count($mp3AttachedFilesList);
278
        $tbl_tmp['attached_non_mp3_count'] = count($attachedFilesForTemplate) - count($mp3AttachedFilesList);
279
        $tbl_tmp['attached_files']         = $attachedFilesForTemplate;
280
        // La liste complète de tous les fichiers attachés
281
282
        $tbl_tmp['product_category'] = $product_category->toArray();
283
        $tbl_tmp['product_vendor']   = $product_vendor->toArray();
284
        if (xoops_trim($product_user->getVar('name')) != '') {
285
            $name = $product_user->getVar('name');
286
        } else {
287
            $name = $product_user->getVar('uname');
288
        }
289
        $tbl_tmp['product_submiter_name'] = $name;
290
        $linkeduser                       = '<a href="' . XOOPS_URL . '/userinfo.php?uid=' . $product_user->getVar('uid') . '">' . $name . '</a>';
291
        $tbl_tmp['product_submiter_link'] = $name;
292
        if (is_object($product_vat)) {
293
            $tbl_tmp['product_vat_rate'] = $product_vat->toArray();
294
        }
295
296
        $tbl_tmp['product_rating_formated'] = number_format($product->getVar('product_rating'), 2);
297
        if ($product->getVar('product_votes') == 1) {
298
            $tbl_tmp['product_votes_count'] = _OLEDRION_ONEVOTE;
299
        } else {
300
            $tbl_tmp['product_votes_count'] = sprintf(_OLEDRION_NUMVOTES, $product->getVar('product_votes'));
301
        }
302
        // Attributs
303
        if ($handlers->h_oledrion_attributes->getProductAttributesCount($product_id) > 0) {
0 ignored issues
show
The property h_oledrion_attributes does not exist on object<OledrionHandler>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
304
            $attributes           = array();
305
            $mandatoryFieldsCount = 0;
306
            if ($handlers->h_oledrion_caddy->isInCart($product_id)) {
0 ignored issues
show
The property h_oledrion_caddy does not exist on object<OledrionHandler>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
307
            }
308
            $attributes = $handlers->h_oledrion_attributes->constructHtmlProductAttributes($product, $mandatoryFieldsCount);
0 ignored issues
show
The property h_oledrion_attributes does not exist on object<OledrionHandler>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
309
            if (count($attributes) > 0) {
310
                Oledrion_utils::callJavascriptFile('validate/jquery.validate.min.js');
311
                Oledrion_utils::setCSS(OLEDRION_URL . 'assets/css/validate.css');
312
                $tbl_tmp['product_attributes'] = $attributes;
313
                $xoopsTpl->assign('mandatoryFieldsCount', $mandatoryFieldsCount);
314
            }
315
        }
316
        // Product
317
        $tbl_tmp['product_property1_title']  = Oledrion_utils::getModuleOption('product_property1_title');
318
        $tbl_tmp['product_property2_title']  = Oledrion_utils::getModuleOption('product_property2_title');
319
        $tbl_tmp['product_property3_title']  = Oledrion_utils::getModuleOption('product_property3_title');
320
        $tbl_tmp['product_property4_title']  = Oledrion_utils::getModuleOption('product_property4_title');
321
        $tbl_tmp['product_property5_title']  = Oledrion_utils::getModuleOption('product_property5_title');
322
        $tbl_tmp['product_property6_title']  = Oledrion_utils::getModuleOption('product_property6_title');
323
        $tbl_tmp['product_property7_title']  = Oledrion_utils::getModuleOption('product_property7_title');
324
        $tbl_tmp['product_property8_title']  = Oledrion_utils::getModuleOption('product_property8_title');
325
        $tbl_tmp['product_property9_title']  = Oledrion_utils::getModuleOption('product_property9_title');
326
        $tbl_tmp['product_property10_title'] = Oledrion_utils::getModuleOption('product_property10_title');
327
328
        $xoopsTpl->assign('product', $tbl_tmp);
329
330
        // Breadcrumb *************************************************************************************
331
        $tbl_tmp       = array();
332
        $mytree        = new XoopsObjectTree($tbl_categories, 'cat_cid', 'cat_pid');
333
        $tbl_ancestors = $mytree->getAllParent($product->getVar('product_cid'));
334
        $tbl_ancestors = array_reverse($tbl_ancestors);
335
        $tbl_tmp[]     = "<a href='" . OLEDRION_URL . "index.php' title='" . Oledrion_utils::makeHrefTitle(Oledrion_utils::getModuleName()) . "'>" . Oledrion_utils::getModuleName() . '</a>';
336 View Code Duplication
        foreach ($tbl_ancestors as $item) {
337
            $tbl_tmp[] = "<a href='" . $item->getLink() . "' title='" . Oledrion_utils::makeHrefTitle($item->getVar('cat_title')) . "'>" . $item->getVar('cat_title') . '</a>';
338
        }
339
        // Ajout de la catégorie courante
340
        $tbl_tmp[]  = "<a href='" . $product_category->getLink() . "' title='" . Oledrion_utils::makeHrefTitle($product_category->getVar('cat_title')) . "'>" . $product_category->getVar('cat_title') . '</a>';
341
        $tbl_tmp[]  = $product->getVar('product_title');
342
        $breadcrumb = implode(' &raquo; ', $tbl_tmp);
343
        $xoopsTpl->assign('breadcrumb', $breadcrumb);
344
345
        // Maj compteur de lectures ***********************************************************************
346
        if ($product->getVar('product_submitter') != $currentUser) {
347
            $h_oledrion_products->addCounter($product_id);
348
        }
349
350
        // produits précédents et suivants ******************************************************************
351
        if (Oledrion_utils::getModuleOption('showprevnextlink') == 1) {
352
            $xoopsTpl->assign('showprevnextlink', true);
353
            // Recherche du produit suivant le produit en cours.
354
            $criteria = new CriteriaCompo();
355
            $criteria->add(new Criteria('product_online', 1, '='));
356
            if (Oledrion_utils::getModuleOption('show_unpublished') == 0) {
357
                // Ne pas afficher les produits qui ne sont pas publiés
358
                $criteria->add(new Criteria('product_submitted', time(), '<='));
359
            }
360
            if (Oledrion_utils::getModuleOption('nostock_display') == 0) {
361
                // Se limiter aux seuls produits encore en stock
362
                $criteria->add(new Criteria('product_stock', 0, '>'));
363
            }
364
            $criteria->add(new Criteria('product_id', $product->getVar('product_id'), '>'));
365
            $criteria->setOrder('DESC');
366
            $criteria->setSort('product_submitted');
367
            $criteria->setLimit(1);
368
            $tbl = array();
369
            $tbl = $h_oledrion_products->getObjects($criteria);
370 View Code Duplication
            if (count($tbl) == 1) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
371
                // Trouvé
372
                $tmpProduct = null;
373
                $tmpProduct = $tbl[0];
374
                $xoopsTpl->assign('next_product_id', $tmpProduct->getVar('product_id'));
375
                $xoopsTpl->assign('next_product_title', $tmpProduct->getVar('product_title'));
376
                $xoopsTpl->assign('next_product_url_rewrited', $tmpProduct->getLink());
377
                $xoopsTpl->assign('next_product_href_title', Oledrion_utils::makeHrefTitle($tmpProduct->getVar('product_title')));
378
            } else {
379
                $xoopsTpl->assign('next_product_id', 0);
380
            }
381
382
            // Recherche du produit précédant le produit en cours.
383
            $criteria = new CriteriaCompo();
384
            $criteria->add(new Criteria('product_online', 1, '='));
385
            if (Oledrion_utils::getModuleOption('show_unpublished') == 0) {
386
                // Ne pas afficher les produits qui ne sont pas publiés
387
                $criteria->add(new Criteria('product_submitted', time(), '<='));
388
            }
389
            if (Oledrion_utils::getModuleOption('nostock_display') == 0) {
390
                // Se limiter aux seuls produits encore en stock
391
                $criteria->add(new Criteria('product_stock', 0, '>'));
392
            }
393
            $criteria->add(new Criteria('product_id', $product->getVar('product_id'), '<'));
394
            $criteria->setOrder('DESC');
395
            $criteria->setSort('product_submitted');
396
            $criteria->setLimit(1);
397
            $tbl = array();
398
            $tbl = $h_oledrion_products->getObjects($criteria);
399 View Code Duplication
            if (count($tbl) == 1) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
400
                // Trouvé
401
                $tmpProduct = null;
402
                $tmpProduct = $tbl[0];
403
                $xoopsTpl->assign('previous_product_id', $tmpProduct->getVar('product_id'));
404
                $xoopsTpl->assign('previous_product_title', $tmpProduct->getVar('product_title'));
405
                $xoopsTpl->assign('previous_product_url_rewrited', $tmpProduct->getLink());
406
                $xoopsTpl->assign('previous_product_href_title', Oledrion_utils::makeHrefTitle($tmpProduct->getVar('product_title')));
407
            } else {
408
                $xoopsTpl->assign('previous_product_id', 0);
409
            }
410
        } else {
411
            $xoopsTpl->assign('showprevnextlink', false);
412
        }
413
        // x derniers produits toutes catégories confondues *************************************************
414
        $count = Oledrion_utils::getModuleOption('summarylast');
415
        $xoopsTpl->assign('summarylast', $count);
416 View Code Duplication
        if ($count > 0) {
417
            $tblTmp = array();
418
            $tblTmp = $h_oledrion_products->getRecentProducts(new Oledrion_parameters(array(
419
                                                                                          'start'    => 0,
420
                                                                                          'limit'    => $count,
421
                                                                                          'category' => 0,
422
                                                                                          'sort'     => 'product_submitted DESC, product_title',
423
                                                                                          'order'    => '',
424
                                                                                          'excluded' => $product_id
425
                                                                                      )));
426
            foreach ($tblTmp as $item) {
427
                $product_price     = $item->getVar('product_price');
428
                $product_price_ttc = Oledrion_utils::getTTC($item->getVar('product_price'), '');
429
                if ($h_oledrion_attributes->getProductAttributesCount($item->getVar('product_id')) > 0) {
430
                    $criteria = new CriteriaCompo();
431
                    $criteria->add(new Criteria('attribute_product_id', $item->getVar('product_id')));
432
                    $attribute = $h_oledrion_attributes->getObjects($criteria, false);
433
                    foreach ($attribute as $root) {
434
                        $product_price     = $root->getVar('attribute_default_value');
435
                        $product_price_ttc = Oledrion_utils::getTTC($root->getVar('attribute_default_value'), '');
436
                    }
437
                }
438
                $datas = array(
439
                    'last_categ_product_title'        => $item->getVar('product_title'),
440
                    'last_categ_product_url_rewrited' => $item->getLink(),
441
                    'last_categ_product_href_title'   => Oledrion_utils::makeHrefTitle($item->getVar('product_title')),
442
                    'product_thumb_url'               => $item->getVar('product_thumb_url'),
443
                    'product_thumb_full_url'          => $item->getThumbUrl(),
444
                    'product_url_rewrited'            => $item->getLink(),
445
                    'product_href_title'              => Oledrion_utils::makeHrefTitle($item->getVar('product_title')),
446
                    'product_title'                   => $item->getVar('product_title'),
447
                    'product_property1'               => $item->getVar('product_property1'),
448
                    'product_property2'               => $item->getVar('product_property2'),
449
                    'product_property3'               => $item->getVar('product_property3'),
450
                    'product_property4'               => $item->getVar('product_property4'),
451
                    'product_property5'               => $item->getVar('product_property5'),
452
                    'product_property6'               => $item->getVar('product_property6'),
453
                    'product_property7'               => $item->getVar('product_property7'),
454
                    'product_property8'               => $item->getVar('product_property8'),
455
                    'product_property9'               => $item->getVar('product_property9'),
456
                    'product_property10'              => $item->getVar('product_property10'),
457
                    'product_id'                      => $item->getVar('product_id'),
458
                    'product_new'                     => $item->isNewProduct(),
459
                    'product_stock'                   => $item->getVar('product_stock'),
460
                    'product_price'                   => $product_price,
461
                    'product_price_ttc'               => $product_price_ttc
462
                );
463
                $xoopsTpl->append('product_all_categs', $datas);
464
            }
465
            unset($tblTmp);
466
        }
467
468
        // x derniers produits dans cette catégorie *********************************************************
469
        $count = Oledrion_utils::getModuleOption('summarycategory');
470
        $xoopsTpl->assign('summarycategory', $count);
471 View Code Duplication
        if ($count > 0) {
472
            $tblTmp = array();
473
            $tblTmp = $h_oledrion_products->getRecentProducts(new Oledrion_parameters(array(
474
                                                                                          'start'    => 0,
475
                                                                                          'limit'    => $count,
476
                                                                                          'category' => $product->getVar('product_cid'),
477
                                                                                          'sort'     => 'product_submitted DESC, product_title',
478
                                                                                          'order'    => '',
479
                                                                                          'excluded' => $product_id
480
                                                                                      )));
481
            foreach ($tblTmp as $item) {
482
                $product_price     = $item->getVar('product_price');
483
                $product_price_ttc = Oledrion_utils::getTTC($item->getVar('product_price'), '');
484
                if ($h_oledrion_attributes->getProductAttributesCount($item->getVar('product_id')) > 0) {
485
                    $criteria = new CriteriaCompo();
486
                    $criteria->add(new Criteria('attribute_product_id', $item->getVar('product_id')));
487
                    $attribute = $h_oledrion_attributes->getObjects($criteria, false);
488
                    foreach ($attribute as $root) {
489
                        $product_price     = $root->getVar('attribute_default_value');
490
                        $product_price_ttc = Oledrion_utils::getTTC($root->getVar('attribute_default_value'), '');
491
                    }
492
                }
493
                $datas = array(
494
                    'last_categ_product_title'        => $item->getVar('product_title'),
495
                    'last_categ_product_url_rewrited' => $item->getLink(),
496
                    'last_categ_product_href_title'   => Oledrion_utils::makeHrefTitle($item->getVar('product_title')),
497
                    'product_thumb_url'               => $item->getVar('product_thumb_url'),
498
                    'product_thumb_full_url'          => $item->getThumbUrl(),
499
                    'product_url_rewrited'            => $item->getLink(),
500
                    'product_href_title'              => Oledrion_utils::makeHrefTitle($item->getVar('product_title')),
501
                    'product_title'                   => $item->getVar('product_title'),
502
                    'product_property1'               => $item->getVar('product_property1'),
503
                    'product_property2'               => $item->getVar('product_property2'),
504
                    'product_property3'               => $item->getVar('product_property3'),
505
                    'product_property4'               => $item->getVar('product_property4'),
506
                    'product_property5'               => $item->getVar('product_property5'),
507
                    'product_property6'               => $item->getVar('product_property6'),
508
                    'product_property7'               => $item->getVar('product_property7'),
509
                    'product_property8'               => $item->getVar('product_property8'),
510
                    'product_property9'               => $item->getVar('product_property9'),
511
                    'product_property10'              => $item->getVar('product_property10'),
512
                    'product_id'                      => $item->getVar('product_id'),
513
                    'product_new'                     => $item->isNewProduct(),
514
                    'product_stock'                   => $item->getVar('product_stock'),
515
                    'product_price'                   => $product_price,
516
                    'product_price_ttc'               => $product_price_ttc
517
                );
518
                $xoopsTpl->append('product_current_categ', $datas);
519
            }
520
            unset($tblTmp);
521
        }
522
523
        // Deux c'est mieux *******************************************************************************
524
        $count = Oledrion_utils::getModuleOption('better_together');
525
        $xoopsTpl->assign('better_together', $count);
526
        if ($count > 0) {
527
            $productWith = 0;
528
            // On recherche le produit qui s'est le plus vendu avec ce produit
529
            $productWith = $h_oledrion_caddy->getBestWith($product->getVar('product_id'));
530
            if ($productWith > 0) {
531
                $tmpProduct = null;
532
                $tmpProduct = $h_oledrion_products->get($productWith);
533
                if (is_object($tmpProduct)) {
534
                    $tmp                               = array();
535
                    $tmp                               = $tmpProduct->toArray();
536
                    $tmp['product_price_ttc']          = Oledrion_utils::getTTC($tmpProduct->getVar('product_price'), $tblVat[$tmpProduct->getVar('product_vat_id')]->getVar('vat_rate'));
537
                    $tmp['product_discount_price_ttc'] = Oledrion_utils::getTTC($tmpProduct->getVar('product_discount_price'), $tblVat[$tmpProduct->getVar('product_vat_id')]->getVar('vat_rate'));
538
                    $xoopsTpl->assign('bestwith', $tmp);
539
                }
540
            }
541
        }
542
543
        // Notation produit *********************************************************************************
544
        if (Oledrion_utils::getModuleOption('rateproducts') == 1) {
545
            $canRate = true;
546
            if ($currentUser != 0) {
547
                $canRate = !$h_oledrion_votedata->hasUserAlreadyVoted($currentUser, $product->getVar('product_id'));
548
            } else {
549
                $canRate = !$h_oledrion_votedata->hasAnonymousAlreadyVoted('', $product->getVar('product_id'));
550
            }
551
            $xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');
552
            Oledrion_utils::callJavascriptFile('rateit.js');
553
            Oledrion_utils::setCSS(OLEDRION_URL . 'assets/css/rateit.css');
554
555
            $xoopsTpl->assign('userCanRate', $canRate);
556
        }
557
558
        // Meta et CSS ************************************************************************************
559
        Oledrion_utils::setCSS();
560
        Oledrion_utils::setLocalCSS($xoopsConfig['language']);
561
        if (Oledrion_utils::getModuleOption('manual_meta')) {
562
            $pageTitle       = xoops_trim($product->getVar('product_metatitle')) == '' ? $title : $product->getVar('product_metatitle');
563
            $metaDescription = xoops_trim($product->getVar('product_metadescription')) != '' ? $product->getVar('product_metadescription') : $title;
564
            $metaKeywords    = xoops_trim($product->getVar('product_metakeywords')) != '' ? $product->getVar('product_metakeywords') : Oledrion_utils::createMetaKeywords($product->getVar('product_title') . ' ' . $product->getVar('product_summary')
565
                                                                                                                                                                          . ' ' . $product->getVar('product_description'));
566
            Oledrion_utils::setMetas($pageTitle, $metaDescription, $metaKeywords);
567
        } else {
568
            Oledrion_utils::setMetas($title, $title, Oledrion_utils::createMetaKeywords($product->getVar('product_title') . ' ' . $product->getVar('product_summary') . ' ' . $product->getVar('product_description')));
569
        }
570
571
        require_once XOOPS_ROOT_PATH . '/include/comment_view.php';
572
        require_once XOOPS_ROOT_PATH . '/footer.php';
573
        break;
574
}
575