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 et gestion du caddy |
||
22 | */ |
||
23 | require __DIR__ . '/header.php'; |
||
24 | $GLOBALS['current_category'] = -1; |
||
25 | $GLOBALS['xoopsOption']['template_main'] = 'oledrion_caddy.tpl'; |
||
26 | require_once XOOPS_ROOT_PATH . '/header.php'; |
||
27 | require_once OLEDRION_PATH . 'class/registryfile.php'; |
||
28 | |||
29 | $xoopsTpl->assign('mod_pref', $mod_pref); // Préférences du module |
||
30 | |||
31 | if (Oledrion_utils::getModuleOption('restrict_orders', false)) { |
||
32 | $registry = new oledrion_registryfile(); |
||
33 | $text = $registry->getfile(OLEDRION_TEXTFILE5); |
||
34 | $xoopsTpl->assign('restrict_orders_text', xoops_trim($text)); |
||
35 | } else { |
||
36 | $xoopsTpl->assign('restrict_orders_text', ''); |
||
37 | } |
||
38 | |||
39 | $op = 'default'; |
||
40 | View Code Duplication | if (isset($_POST['op'])) { |
|
0 ignored issues
–
show
|
|||
41 | $op = $_POST['op']; |
||
42 | } elseif (isset($_GET['op'])) { |
||
43 | $op = $_GET['op']; |
||
44 | } |
||
45 | |||
46 | $productId = 0; |
||
47 | if (isset($_POST['product_id'])) { |
||
48 | $productId = (int)$_POST['product_id']; |
||
49 | } elseif (isset($_GET['product_id'])) { |
||
50 | $productId = (int)$_GET['product_id']; |
||
51 | } |
||
52 | |||
53 | $xoopsTpl->assign('op', $op); |
||
54 | $xoopsTpl->assign('confEmpty', Oledrion_utils::javascriptLinkConfirm(_OLEDRION_EMPTY_CART_SURE, true)); |
||
55 | $xoopsTpl->assign('confirm_delete_item', Oledrion_utils::javascriptLinkConfirm(_OLEDRION_EMPTY_ITEM_SURE, false)); |
||
56 | |||
57 | $uid = Oledrion_utils::getCurrentUserID(); |
||
58 | if ($uid > 0) { |
||
59 | $xoopsTpl->assign('isCartExists', $h_oledrion_persistent_cart->isCartExists()); |
||
60 | } else { |
||
61 | $xoopsTpl->assign('isCartExists', false); |
||
62 | } |
||
63 | |||
64 | // ******************************************************************************************************************** |
||
65 | // Liste le contenu du caddy |
||
66 | // ******************************************************************************************************************** |
||
67 | function listCart() |
||
68 | { |
||
69 | global $xoopsTpl, $uid; |
||
70 | $cartForTemplate = $discountsDescription = array(); |
||
71 | $emptyCart = false; |
||
72 | $shippingAmount = $commandAmount = $vatAmount = $commandAmountTTC = $discountsCount = $ecotaxeAmount = $discountAmount = $totalSavings = 0; |
||
73 | $goOn = ''; |
||
74 | $reductions = new oledrion_reductions(); |
||
75 | $reductions->computeCart($cartForTemplate, $emptyCart, $shippingAmount, $commandAmount, $vatAmount, $goOn, $commandAmountTTC, $discountsDescription, $discountsCount, $ecotaxeAmount, $discountAmount, $totalSavings); |
||
0 ignored issues
–
show
The call to
Oledrion_reductions::computeCart() has too many arguments starting with $ecotaxeAmount .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the ![]() |
|||
76 | $oledrion_Currency = Oledrion_Currency::getInstance(); |
||
77 | $xoopsTpl->assign('emptyCart', $emptyCart); // Caddy Vide ? |
||
78 | $xoopsTpl->assign('caddieProducts', $cartForTemplate); // Produits dans le caddy |
||
79 | $xoopsTpl->assign('shippingAmount', $oledrion_Currency->amountForDisplay($shippingAmount)); // Montant des frais de port |
||
80 | $xoopsTpl->assign('ecotaxeAmount', $oledrion_Currency->amountForDisplay($ecotaxeAmount)); // Montant des frais de port |
||
81 | $xoopsTpl->assign('commandAmount', $oledrion_Currency->amountForDisplay($commandAmount)); // Montant HT de la commande |
||
82 | $xoopsTpl->assign('discountAmount', $oledrion_Currency->amountForDisplay($discountAmount)); // Total Discount |
||
83 | $xoopsTpl->assign('totalSavings', $oledrion_Currency->amountForDisplay($totalSavings)); // Total Savings |
||
84 | $xoopsTpl->assign('vatAmount', $oledrion_Currency->amountForDisplay($vatAmount)); // Montant de la TVA |
||
85 | $xoopsTpl->assign('discountsCount', $discountsCount); // Nombre de réductions appliquées |
||
86 | $xoopsTpl->assign('goOn', $goOn); // Adresse à utiliser pour continuer ses achats |
||
87 | $xoopsTpl->assign('commandAmountTTC', $oledrion_Currency->amountForDisplay($commandAmountTTC, 'l')); // Montant TTC de la commande |
||
88 | $xoopsTpl->assign('discountsDescription', $discountsDescription); // Liste des réductions accordées |
||
89 | $showOrderButton = true; |
||
90 | $showRegistredOnly = false; |
||
91 | if (Oledrion_utils::getModuleOption('restrict_orders', false) && $uid == 0) { |
||
92 | $showRegistredOnly = true; |
||
93 | $showOrderButton = false; |
||
94 | } |
||
95 | $xoopsTpl->assign('showRegistredOnly', $showRegistredOnly); |
||
96 | $xoopsTpl->assign('showOrderButton', $showOrderButton); |
||
97 | } |
||
98 | |||
99 | // ******************************************************************************************************************** |
||
100 | // ******************************************************************************************************************** |
||
101 | // ******************************************************************************************************************** |
||
102 | switch ($op) { |
||
103 | // **************************************************************************************************************** |
||
104 | case 'update': // Recalcul des quantités |
||
105 | // **************************************************************************************************************** |
||
106 | $h_oledrion_caddy->updateQuantites(); |
||
107 | listCart(); |
||
108 | break; |
||
109 | |||
110 | // **************************************************************************************************************** |
||
111 | case 'reload': // Chargement du dernier panier enregistré |
||
112 | // **************************************************************************************************************** |
||
113 | $h_oledrion_caddy->reloadPersistentCart(); |
||
114 | listCart(); |
||
115 | break; |
||
116 | |||
117 | // **************************************************************************************************************** |
||
118 | case 'delete': // Suppression d'un élément |
||
119 | // **************************************************************************************************************** |
||
120 | $productId--; |
||
121 | $h_oledrion_caddy->deleteProduct($productId); |
||
122 | listCart(); |
||
123 | break; |
||
124 | |||
125 | // **************************************************************************************************************** |
||
126 | case 'addproduct': // Ajout d'un produit |
||
127 | // **************************************************************************************************************** |
||
128 | if ($productId == 0) { |
||
129 | Oledrion_utils::redirect(_OLEDRION_ERROR9, 'index.php', 4); |
||
130 | } |
||
131 | $product = null; |
||
132 | $product = $h_oledrion_products->get($productId); |
||
133 | if (!is_object($product)) { |
||
134 | Oledrion_utils::redirect(_OLEDRION_ERROR9, 'index.php', 4); |
||
135 | } |
||
136 | if ($product->getVar('product_online') == 0) { |
||
137 | Oledrion_utils::redirect(_OLEDRION_ERROR2, 'index.php', 4); |
||
138 | } |
||
139 | |||
140 | if ($product->getVar('product_stock') - 1 >= 0) { |
||
141 | // Options |
||
142 | $userAttributes = array(); |
||
143 | if ($product->productAttributesCount() > 0) { // Si le produit a des attributs |
||
144 | $productAttributes = array(); |
||
145 | // On commence par vérifier que les attributs obligatoires sont renseignés |
||
146 | // It starts by checking if mandatory attributes are filled |
||
147 | if ($product->getProductMandatoryAttributesCount()) { |
||
148 | $mandatoryFieldsList = array(); |
||
149 | $mandatoryFieldsList = $product->getProductMandatoryFieldsList(); |
||
150 | if (count($mandatoryFieldsList) > 0) { |
||
151 | $productUrl = $product->getLink(); |
||
152 | foreach ($mandatoryFieldsList as $mandatoryField) { |
||
153 | $mandatoryFieldKey = $mandatoryField->getAttributeNameInForm(); |
||
154 | $mandatoryFieldText = $mandatoryField->getVar('attribute_title'); |
||
155 | if (!isset($_POST[$mandatoryFieldKey]) && !$mandatoryField->hasDefaultValue()) { |
||
156 | Oledrion_utils::redirect(sprintf(_OLEDRION_MANDATORY_MISSED, $mandatoryFieldText), $productUrl, 4); |
||
157 | } |
||
158 | } |
||
159 | } |
||
160 | } |
||
161 | // Toujours là c'est que le produit a des attributs et qu'ils sont renseignés |
||
162 | //Checks if the product has more options and if they are set |
||
163 | $productAttributes = $product->getProductsAttributesList(); |
||
164 | foreach ($productAttributes as $attribute) { |
||
165 | $nameInForm = $attribute->getAttributeNameInForm(); |
||
166 | if (isset($_POST[$nameInForm])) { |
||
167 | $userAttributes[$attribute->attribute_id] = $_POST[$nameInForm]; |
||
168 | } else { // On va chercher sa valeur par défaut |
||
169 | if ($attribute->hasDefaultValue()) { |
||
170 | $userAttributes[$attribute->attribute_id] = $attribute->getAttributeDefaultValue(); |
||
171 | } |
||
172 | } |
||
173 | } |
||
174 | } |
||
175 | $h_oledrion_caddy->addProduct($productId, 1, $userAttributes); |
||
176 | $url = OLEDRION_URL . 'caddy.php'; |
||
177 | if (!OLEDRION_CART_BUG) { |
||
178 | header("Location: $url"); |
||
179 | } else { |
||
180 | listCart(); |
||
181 | } |
||
182 | } else { |
||
183 | Oledrion_utils::redirect(_OLEDRION_PROBLEM_QTY, 'index.php', 5); // Plus de stock ! |
||
184 | } |
||
185 | listCart(); |
||
186 | break; |
||
187 | |||
188 | // **************************************************************************************************************** |
||
189 | case 'empty': // Suppression du contenu du caddy |
||
190 | // **************************************************************************************************************** |
||
191 | $h_oledrion_caddy->emptyCart(); |
||
192 | listCart(); |
||
193 | break; |
||
194 | |||
195 | // **************************************************************************************************************** |
||
196 | case 'default': // Action par défaut |
||
197 | // **************************************************************************************************************** |
||
198 | listCart(); |
||
199 | break; |
||
200 | } |
||
201 | |||
202 | // Image icons |
||
203 | View Code Duplication | if (file_exists(OLEDRION_PATH . 'language/' . $xoopsConfig['language'] . '/image/step1.png')) { |
|
204 | $step1 = OLEDRION_URL . 'language/' . $xoopsConfig['language'] . '/image/step1.png'; |
||
205 | $step2 = OLEDRION_URL . 'language/' . $xoopsConfig['language'] . '/image/step2.png'; |
||
206 | $step3 = OLEDRION_URL . 'language/' . $xoopsConfig['language'] . '/image/step3.png'; |
||
207 | } else { // Fallback |
||
208 | $step1 = OLEDRION_URL . 'language/english/image/step1.png'; |
||
209 | $step2 = OLEDRION_URL . 'language/english/image/step2.png'; |
||
210 | $step3 = OLEDRION_URL . 'language/english/image/step3.png'; |
||
211 | } |
||
212 | $xoopsTpl->assign('step1', $step1); |
||
213 | $xoopsTpl->assign('step2', $step2); |
||
214 | $xoopsTpl->assign('step3', $step3); |
||
215 | |||
216 | Oledrion_utils::setCSS(); |
||
217 | Oledrion_utils::setLocalCSS($xoopsConfig['language']); |
||
218 | Oledrion_utils::loadLanguageFile('modinfo.php'); |
||
219 | |||
220 | $xoopsTpl->assign('breadcrumb', Oledrion_utils::breadcrumb(array(OLEDRION_URL . basename(__FILE__) => _MI_OLEDRION_SMNAME1))); |
||
221 | |||
222 | $title = _MI_OLEDRION_SMNAME1 . ' - ' . Oledrion_utils::getModuleName(); |
||
223 | Oledrion_utils::setMetas($title, $title); |
||
224 | require_once XOOPS_ROOT_PATH . '/footer.php'; |
||
225 |
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.