DiscountsHandler::getDiscountedPrice()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace XoopsModules\Oledrion;
4
5
/*
6
 You may not change or alter any portion of this comment or credits
7
 of supporting developers from this source code or any supporting source code
8
 which is considered copyrighted (c) material of the original comment or credit authors.
9
10
 This program is distributed in the hope that it will be useful,
11
 but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
*/
14
15
/**
16
 * oledrion
17
 *
18
 * @copyright   {@link https://xoops.org/ XOOPS Project}
19
 * @license     {@link http://www.fsf.org/copyleft/gpl.html GNU public license}
20
 * @author      Hervé Thouzard (http://www.herve-thouzard.com/)
21
 */
22
23
use XoopsModules\Oledrion;
24
25
/**
26
 * Gestion des réductions
27
 */
28
29
/**
30
 * Class DiscountsHandler
31
 */
32
class DiscountsHandler extends OledrionPersistableObjectHandler
33
{
34
    /**
35
     * DiscountsHandler constructor.
36
     * @param \XoopsDatabase|null $db
37
     */
38
    public function __construct(\XoopsDatabase $db = null)
39
    {
40
        //                        Table                   Classe              Id        Libellé
41
        parent::__construct($db, 'oledrion_discounts', Discounts::class, 'disc_id', 'disc_title');
0 ignored issues
show
Bug introduced by
It seems like $db can also be of type null; however, parameter $db of XoopsModules\Oledrion\Ol...tHandler::__construct() does only seem to accept XoopsDatabase, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

41
        parent::__construct(/** @scrutinizer ignore-type */ $db, 'oledrion_discounts', Discounts::class, 'disc_id', 'disc_title');
Loading history...
42
    }
43
44
    /**
45
     * @param $price
46
     * @param $discount
47
     * @return mixed
48
     */
49
    private function getDiscountedPrice($price, $discount)
50
    {
51
        return $price - ($price * ($discount / 100));
52
    }
53
54
    /**
55
     * Retourne la liste des règles qui sont applicables sur la période courante
56
     * @param void
57
     * @return array objets de type Discounts
58
     */
59
    public function getRulesForThisPeriod()
60
    {
61
        static $buffer = [];
62
        if ($buffer && is_array($buffer)) {
63
            return $buffer;
64
        }
65
66
        $critere = new \CriteriaCompo();
67
        $critere->add(new \Criteria('disc_date_from', 0, '='));
68
        $critere->add(new \Criteria('disc_date_to', 0, '='), 'OR');
69
70
        $critere2 = new \CriteriaCompo();
71
        $critere2->add(new \Criteria('disc_date_from', time(), '>='));
72
        $critere2->add(new \Criteria('disc_date_to', time(), '<='));
73
        $critere->add($critere2);
74
75
        $buffer = $this->getObjects($critere);
76
77
        return $buffer;
78
    }
79
80
    /**
81
     * @deprecated
82
     */
83
84
    /**
85
     * Renvoie la liste des règles à appliquer sur chaque produit (avec gestion de cache) pour l'utilisateur courant
86
     *
87
     * @return array Tableau d'objets de type Discounts
88
     */
89
    public function getRulesOnEachProduct()
90
    {
91
        static $buffer = [];
92
        if ($buffer && is_array($buffer)) {
93
        } else {
94
            $groups  = Oledrion\Utility::getCurrentMemberGroups();
95
            $critere = new \CriteriaCompo();
96
            $critere->add(new \Criteria('disc_on_what', Constants::OLEDRION_DISCOUNT_ON3, '='));
97
            if (count($groups) > 0) {
98
                $critere->add(new \Criteria('disc_group', '(' . implode(',', $groups) . ')', 'IN'));
99
            }
100
            $buffer = $this->getObjects($critere);
101
        }
102
103
        return $buffer;
104
    }
105
106
    /**
107
     * Renvoie la liste des règles à appliquer sur tous les produits (avec gestion de cache) pour l'utilisateur courant
108
     *
109
     * @return array Tableau d'objets de type Discounts
110
     */
111
    public function getRulesOnAllProducts()
112
    {
113
        static $buffer = [];
114
        if ($buffer && is_array($buffer)) {
115
        } else {
116
            $critere = new \CriteriaCompo();
117
            $critere->add(new \Criteria('disc_on_what', Constants::OLEDRION_DISCOUNT_ON2, '='));
118
            $tblGroups = Oledrion\Utility::getCurrentMemberGroups();
119
            $critere->add(new \Criteria('disc_group', '(' . implode(',', $tblGroups) . ')', 'IN'));
120
            $buffer = $this->getObjects($critere);
121
        }
122
123
        return $buffer;
124
    }
125
126
    /**
127
     * Renvoie la liste des règles à appliquer sur les frais de ports (avec gestion de cache) pour l'utilisateur courant
128
     *
129
     * @return array Tableau d'objets de type Discounts
130
     */
131
    public function getRulesOnShipping()
132
    {
133
        static $buffer = [];
134
        if ($buffer && is_array($buffer)) {
135
        } else {
136
            $critere = new \CriteriaCompo();
137
            $critere->add(new \Criteria('disc_on_what', Constants::OLEDRION_DISCOUNT_ON4, '='));
138
            $tblGroups = Oledrion\Utility::getCurrentMemberGroups();
139
            $critere->add(new \Criteria('disc_group', '(' . implode(',', $tblGroups) . ')', 'IN'));
140
            $buffer = $this->getObjects($critere);
141
        }
142
143
        return $buffer;
144
    }
145
146
    /**
147
     * Renvoie la liste des règles à appliquer sur les frais de ports (avec gestion de cache) pour l'utilisateur courant
148
     *
149
     * @return array Tableau d'objets de type Discounts
150
     */
151
    public function getRulesOnShipping2()
152
    {
153
        static $buffer = [];
154
        if ($buffer && is_array($buffer)) {
155
        } else {
156
            $critere = new \CriteriaCompo();
157
            $critere->add(new \Criteria('disc_on_what', Constants::OLEDRION_DISCOUNT_ON5, '='));
158
            $critere->add(new \Criteria('disc_shipping', Constants::OLEDRION_DISCOUNT_SHIPPING_TYPE2, '='));
159
            $tblGroups = Oledrion\Utility::getCurrentMemberGroups();
160
            $critere->add(new \Criteria('disc_group', '(' . implode(',', $tblGroups) . ')', 'IN'));
161
            $buffer = $this->getObjects($critere);
162
        }
163
164
        return $buffer;
165
    }
166
167
    /**
168
     * Renvoie la liste des règles à appliquer sur l'intégralité de la commande (avec gestion de cache) pour l'utilisateur courant
169
     *
170
     * @return array Tableau d'objets de type Discounts
171
     */
172
    public function getRulesOnCommand()
173
    {
174
        static $buffer = [];
175
        if ($buffer && is_array($buffer)) {
176
        } else {
177
            $critere = new \CriteriaCompo();
178
            $critere->add(new \Criteria('disc_on_what', Constants::OLEDRION_DISCOUNT_ON1, '='));
179
            $tblGroups = Oledrion\Utility::getCurrentMemberGroups();
180
            $critere->add(new \Criteria('disc_group', '(' . implode(',', $tblGroups) . ')', 'IN'));
181
            $buffer = $this->getObjects($critere);
182
        }
183
184
        return $buffer;
185
    }
186
187
    /**
188
     * Deuxième lot de réductions, à appliquer sur les frais de port
189
     *
190
     * @param float $montantShipping      Montant des frais de port
191
     * @param float $commandAmount        Le montant total de la commande
192
     * @param array $discountsDescription Descriptions des réductions appliquées
193
     */
194
    public function applyDiscountOnShipping2(&$montantShipping, $commandAmount, &$discountsDescription)
195
    {
196
        $tblRules = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $tblRules is dead and can be removed.
Loading history...
197
        $tblRules = $this->getRulesOnShipping2(); // Renvoie des objets Discounts
198
        if (count($tblRules) > 0) {
199
            foreach ($tblRules as $rule) {
200
                if ($commandAmount > (float)$rule->getVar('disc_if_amount')) {
201
                    $discountsDescription[] = $rule->getVar('disc_description');
202
                    $montantShipping        = 0.0;
203
                }
204
            }
205
        }
206
    }
207
208
    /**
209
     * Réductions à appliquer sur le montant global de la commande
210
     *
211
     * @param float $montantHT            Montant HT des produits
212
     * @param array $discountsDescription Descriptions des réductions appliquées
213
     */
214
    public function applyDiscountOnCommand(&$montantHT, &$discountsDescription)
215
    {
216
        global $commandsHandler;
217
        $tblRules = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $tblRules is dead and can be removed.
Loading history...
218
        $tblRules = $this->getRulesOnCommand(); // Renvoie des objets Discounts
219
        if (count($tblRules) > 0) {
220
            $uid = Oledrion\Utility::getCurrentUserID();
221
            foreach ($tblRules as $rule) {
222
                switch ($rule->getVar('disc_when')) {
223
                    case Constants::OLEDRION_DISCOUNT_WHEN1: // Dans tous les cas
224
225
                        if (Constants::OLEDRION_DISCOUNT_PRICE_TYPE1 == $rule->getVar('disc_percent_monney')) {
226
                            // Réduction de x pourcent
227
                            $montantHT = $this->getDiscountedPrice($montantHT, $rule->getVar('disc_amount'));
228
                            if ($montantHT < 0) {
229
                                $montantHT = 0.0;
230
                            }
231
                        } else {
232
                            // Réduction de x euros
233
                            $montantHT -= $rule->getVar('disc_amount');
234
                            if ($montantHT < 0) {
235
                                $montantHT = 0.0;
236
                            }
237
                        }
238
                        $discountsDescription[] = $rule->getVar('disc_description');
239
240
                        break;
241
                    case Constants::OLEDRION_DISCOUNT_WHEN2: // Si c'est le premier achat de l'utilisateur sur le site
242
243
                        if ($commandsHandler->isFirstCommand($uid)) {
244
                            if (Constants::OLEDRION_DISCOUNT_PRICE_TYPE1 == $rule->getVar('disc_percent_monney')) {
245
                                // Réduction de x pourcent
246
                                $montantHT = $this->getDiscountedPrice($montantHT, $rule->getVar('disc_amount'));
247
                                if ($montantHT < 0) {
248
                                    $montantHT = 0.0;
249
                                }
250
                            } else {
251
                                // Réduction de x euros
252
                                $montantHT -= $rule->getVar('disc_amount');
253
                                if ($montantHT < 0) {
254
                                    $montantHT = 0.0;
255
                                }
256
                            }
257
                            $discountsDescription[] = $rule->getVar('disc_description');
258
                        }
259
260
                        break;
261
                }
262
            }
263
        }
264
    }
265
266
    /**
267
     * Réductions à appliquer sur les frais de port de chaque produit
268
     *
269
     * @param float $montantHT            Montant HT des produits
270
     * @param array $discountsDescription Descriptions des réductions appliquées
271
     * @param int   $productQty           Quantité commandée du produit
272
     */
273
    public function applyDiscountOnShipping(&$montantHT, &$discountsDescription, $productQty)
274
    {
275
        global $commandsHandler;
276
        $tblRules = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $tblRules is dead and can be removed.
Loading history...
277
        $tblRules = $this->getRulesOnShipping(); // Renvoie des objets Discounts
278
        if (count($tblRules) > 0) {
279
            $uid = Oledrion\Utility::getCurrentUserID();
280
            foreach ($tblRules as $rule) {
281
                switch ($rule->getVar('disc_when')) {
282
                    case Constants::OLEDRION_DISCOUNT_WHEN1: // Dans tous les cas
283
284
                        if (Constants::OLEDRION_DISCOUNT_PRICE_TYPE1 == $rule->getVar('disc_percent_monney')) {
285
                            // Réduction de x pourcent
286
                            $montantHT = $this->getDiscountedPrice($montantHT, $rule->getVar('disc_amount'));
287
                            if ($montantHT < 0) {
288
                                $montantHT = 0.0;
289
                            }
290
                        } else {
291
                            // Réduction de x euros
292
                            $montantHT -= $rule->getVar('disc_amount');
293
                            if ($montantHT < 0) {
294
                                $montantHT = 0.0;
295
                            }
296
                        }
297
                        $discountsDescription[] = $rule->getVar('disc_description');
298
299
                        break;
300
                    case Constants::OLEDRION_DISCOUNT_WHEN2: // Si c'est le premier achat de l'utilisateur sur le site
301
302
                        if ($commandsHandler->isFirstCommand($uid)) {
303
                            if (Constants::OLEDRION_DISCOUNT_PRICE_TYPE1 == $rule->getVar('disc_percent_monney')) {
304
                                // Réduction de x pourcent
305
                                $montantHT = $this->getDiscountedPrice($montantHT, $rule->getVar('disc_amount'));
306
                                if ($montantHT < 0) {
307
                                    $montantHT = 0.0;
308
                                }
309
                            } else {
310
                                // Réduction de x euros
311
                                $montantHT -= $rule->getVar('disc_amount');
312
                                if ($montantHT < 0) {
313
                                    $montantHT = 0.0;
314
                                }
315
                            }
316
                            $discountsDescription[] = $rule->getVar('disc_description');
317
                        }
318
319
                        break;
320
                    case Constants::OLEDRION_DISCOUNT_WHEN4: // Si la quantité est =, >, >=, <, <= à ...
321
322
                        $qtyDiscount = false;
323
                        switch ($rule->getVar('disc_qty_criteria')) {
324
                            case 0: // =
325
326
                                if ($productQty == $rule->getVar('disc_qty_value')) {
327
                                    $qtyDiscount = true;
328
                                }
329
330
                                break;
331
                            case 1: // >
332
333
                                if ($productQty > $rule->getVar('disc_qty_value')) {
334
                                    $qtyDiscount = true;
335
                                }
336
337
                                break;
338
                            case 2: // >=
339
340
                                if ($productQty >= $rule->getVar('disc_qty_value')) {
341
                                    $qtyDiscount = true;
342
                                }
343
344
                                break;
345
                            case 3: // <
346
347
                                if ($productQty < $rule->getVar('disc_qty_value')) {
348
                                    $qtyDiscount = true;
349
                                }
350
351
                                break;
352
                            case 4: // <=
353
354
                                if ($productQty <= $rule->getVar('disc_qty_value')) {
355
                                    $qtyDiscount = true;
356
                                }
357
358
                                break;
359
                        }
360
                        if ($qtyDiscount) {
361
                            if (Constants::OLEDRION_DISCOUNT_PRICE_TYPE1 == $rule->getVar('disc_percent_monney')) {
362
                                // Réduction de x pourcents
363
                                $montantHT = $this->getDiscountedPrice($montantHT, $rule->getVar('disc_amount'));
364
                                if ($montantHT < 0) {
365
                                    $montantHT = 0.0;
366
                                }
367
                            } else {
368
                                // Réduction de x euros
369
                                $montantHT -= $rule->getVar('disc_amount');
370
                                if ($montantHT < 0) {
371
                                    $montantHT = 0.0;
372
                                }
373
                            }
374
                            $discountsDescription[] = $rule->getVar('disc_description');
375
                        }
376
377
                        break;
378
                }
379
            }
380
        }
381
    }
382
383
    /**
384
     * Réductions à appliquer sur le montant HT de TOUS les produits
385
     *
386
     * @param float $montantHT            Montant HT des produits
387
     * @param array $discountsDescription Descriptions des réductions appliquées
388
     * @param int   $productQty           Quantité commandée du produit
389
     */
390
    public function applyDiscountOnAllProducts(&$montantHT, &$discountsDescription, $productQty)
391
    {
392
        global $commandsHandler;
393
        $tblRules = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $tblRules is dead and can be removed.
Loading history...
394
        $tblRules = $this->getRulesOnAllProducts(); // Renvoie des objets Discounts
395
        if (count($tblRules) > 0) {
396
            $uid = Oledrion\Utility::getCurrentUserID();
397
            foreach ($tblRules as $rule) {
398
                switch ($rule->getVar('disc_when')) {
399
                    case Constants::OLEDRION_DISCOUNT_WHEN1: // Dans tous les cas
400
401
                        if (Constants::OLEDRION_DISCOUNT_PRICE_TYPE1 == $rule->getVar('disc_percent_monney')) {
402
                            // Réduction de x pourcent
403
                            $montantHT = $this->getDiscountedPrice($montantHT, $rule->getVar('disc_amount'));
404
                            if ($montantHT < 0) {
405
                                $montantHT = 0.0;
406
                            }
407
                        } else {
408
                            // Réduction de x euros
409
                            $montantHT -= $rule->getVar('disc_amount');
410
                            if ($montantHT < 0) {
411
                                $montantHT = 0.0;
412
                            }
413
                        }
414
                        $discountsDescription[] = $rule->getVar('disc_description');
415
416
                        break;
417
                    case Constants::OLEDRION_DISCOUNT_WHEN2: // Si c'est le premier achat de l'utilisateur sur le site
418
419
                        if ($commandsHandler->isFirstCommand($uid)) {
420
                            if (Constants::OLEDRION_DISCOUNT_PRICE_TYPE1 == $rule->getVar('disc_percent_monney')) {
421
                                // Réduction de x pourcent
422
                                $montantHT = $this->getDiscountedPrice($montantHT, $rule->getVar('disc_amount'));
423
                                if ($montantHT < 0) {
424
                                    $montantHT = 0.0;
425
                                }
426
                            } else {
427
                                // Réduction de x euros
428
                                $montantHT -= $rule->getVar('disc_amount');
429
                                if ($montantHT < 0) {
430
                                    $montantHT = 0.0;
431
                                }
432
                            }
433
                            $discountsDescription[] = $rule->getVar('disc_description');
434
                        }
435
436
                        break;
437
                    case Constants::OLEDRION_DISCOUNT_WHEN4: // Si la quantité est =, >, >=, <, <= à ...
438
439
                        $qtyDiscount = false;
440
                        switch ($rule->getVar('disc_qty_criteria')) {
441
                            case 0: // =
442
443
                                if ($productQty == $rule->getVar('disc_qty_value')) {
444
                                    $qtyDiscount = true;
445
                                }
446
447
                                break;
448
                            case 1: // >
449
450
                                if ($productQty > $rule->getVar('disc_qty_value')) {
451
                                    $qtyDiscount = true;
452
                                }
453
454
                                break;
455
                            case 2: // >=
456
457
                                if ($productQty >= $rule->getVar('disc_qty_value')) {
458
                                    $qtyDiscount = true;
459
                                }
460
461
                                break;
462
                            case 3: // <
463
464
                                if ($productQty < $rule->getVar('disc_qty_value')) {
465
                                    $qtyDiscount = true;
466
                                }
467
468
                                break;
469
                            case 4: // <=
470
471
                                if ($productQty <= $rule->getVar('disc_qty_value')) {
472
                                    $qtyDiscount = true;
473
                                }
474
475
                                break;
476
                        }
477
                        if ($qtyDiscount) {
478
                            if (Constants::OLEDRION_DISCOUNT_PRICE_TYPE1 == $rule->getVar('disc_percent_monney')) {
479
                                // Réduction de x pourcent
480
                                $montantHT = $this->getDiscountedPrice($montantHT, $rule->getVar('disc_amount'));
481
                                if ($montantHT < 0) {
482
                                    $montantHT = 0.0;
483
                                }
484
                            } else {
485
                                // Réduction de x euros
486
                                $montantHT -= $rule->getVar('disc_amount');
487
                                if ($montantHT < 0) {
488
                                    $montantHT = 0.0;
489
                                }
490
                            }
491
                            $discountsDescription[] = $rule->getVar('disc_description');
492
                        }
493
494
                        break;
495
                }
496
            }
497
        }
498
    }
499
500
    /**
501
     * Recalcul du prix HT du produit en appliquant les réductions, s'il y a lieu
502
     *
503
     * @param int   $productId            Identifiant du produit
504
     * @param float $prixHT               Prix HT du produit
505
     * @param array $discountsDescription Descriptions des réductions appliquées
506
     * @param int   $productQty           Quantité commandée du produit
507
     */
508
    public function applyDiscountOnEachProduct($productId, &$prixHT, &$discountsDescription, $productQty)
509
    {
510
        global $commandsHandler;
511
        $rules = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $rules is dead and can be removed.
Loading history...
512
        $rules = $this->getRulesOnEachProduct(); // Renvoie des objets Discounts
513
        if (count($rules) > 0) {
514
            $uid = Oledrion\Utility::getCurrentUserID();
515
            foreach ($rules as $rule) {
516
                switch ($rule->getVar('disc_when')) {
517
                    case Constants::OLEDRION_DISCOUNT_WHEN1: // Dans tous les cas
518
519
                        if (Constants::OLEDRION_DISCOUNT_PRICE_TYPE1 == $rule->getVar('disc_percent_monney')) {
520
                            // Réduction de x pourcent
521
                            $prixHT = $this->getDiscountedPrice($prixHT, $rule->getVar('disc_amount'));
522
                            if ($prixHT < 0) {
523
                                $prixHT = 0.0;
524
                            }
525
                        } else {
526
                            // Réduction de x euros
527
                            $prixHT -= $rule->getVar('disc_amount');
528
                            if ($prixHT < 0) {
529
                                $prixHT = 0.0;
530
                            }
531
                        }
532
                        $discountsDescription[] = $rule->getVar('disc_description');
533
534
                        break;
535
                    case Constants::OLEDRION_DISCOUNT_WHEN2: // Si c'est le premier achat de l'utilisateur sur le site
536
537
                        if ($commandsHandler->isFirstCommand($uid)) {
538
                            if (Constants::OLEDRION_DISCOUNT_PRICE_TYPE1 == $rule->getVar('disc_percent_monney')) {
539
                                // Réduction de x pourcent
540
                                $prixHT = $this->getDiscountedPrice($prixHT, $rule->getVar('disc_amount'));
541
                                if ($prixHT < 0) {
542
                                    $prixHT = 0.0;
543
                                }
544
                            } else {
545
                                // Réduction de x euros
546
                                $prixHT -= $rule->getVar('disc_amount');
547
                                if ($prixHT < 0) {
548
                                    $prixHT = 0.0;
549
                                }
550
                            }
551
                            $discountsDescription[] = $rule->getVar('disc_description');
552
                        }
553
554
                        break;
555
                    case Constants::OLEDRION_DISCOUNT_WHEN3: // Si le produit n'a jamais été acheté
556
557
                        if (!$commandsHandler->productAlreadyBought($uid, $productId)) {
558
                            if (Constants::OLEDRION_DISCOUNT_PRICE_TYPE1 == $rule->getVar('disc_percent_monney')) {
559
                                // Réduction de x pourcent
560
                                $prixHT = $this->getDiscountedPrice($prixHT, $rule->getVar('disc_amount'));
561
                                if ($prixHT < 0) {
562
                                    $prixHT = 0.0;
563
                                }
564
                            } else {
565
                                // Réduction de x euros
566
                                $prixHT -= $rule->getVar('disc_amount');
567
                                if ($prixHT < 0) {
568
                                    $prixHT = 0.0;
569
                                }
570
                            }
571
                            $discountsDescription[] = $rule->getVar('disc_description');
572
                        }
573
574
                        break;
575
                    case Constants::OLEDRION_DISCOUNT_WHEN4: // Si la quantité est =, >, >=, <, <= à ...
576
577
                        $qtyDiscount = false;
578
                        switch ($rule->getVar('disc_qty_criteria')) {
579
                            case 0: // =
580
581
                                if ($productQty == $rule->getVar('disc_qty_value')) {
582
                                    $qtyDiscount = true;
583
                                }
584
585
                                break;
586
                            case 1: // >
587
588
                                if ($productQty > $rule->getVar('disc_qty_value')) {
589
                                    $qtyDiscount = true;
590
                                }
591
592
                                break;
593
                            case 2: // >=
594
595
                                if ($productQty >= $rule->getVar('disc_qty_value')) {
596
                                    $qtyDiscount = true;
597
                                }
598
599
                                break;
600
                            case 3: // <
601
602
                                if ($productQty < $rule->getVar('disc_qty_value')) {
603
                                    $qtyDiscount = true;
604
                                }
605
606
                                break;
607
                            case 4: // <=
608
609
                                if ($productQty <= $rule->getVar('disc_qty_value')) {
610
                                    $qtyDiscount = true;
611
                                }
612
613
                                break;
614
                        }
615
                        if ($qtyDiscount) {
616
                            if (Constants::OLEDRION_DISCOUNT_PRICE_TYPE1 == $rule->getVar('disc_percent_monney')) {
617
                                // Réduction de x pourcent
618
                                $prixHT = $this->getDiscountedPrice($prixHT, $rule->getVar('disc_amount'));
619
                                if ($prixHT < 0) {
620
                                    $prixHT = 0.0;
621
                                }
622
                            } else {
623
                                // Réduction de x euros
624
                                $prixHT -= $rule->getVar('disc_amount');
625
                                if ($prixHT < 0) {
626
                                    $prixHT = 0.0;
627
                                }
628
                            }
629
                            $discountsDescription[] = $rule->getVar('disc_description');
630
                        }
631
632
                        break;
633
                }
634
            }
635
        }
636
    }
637
638
    /**
639
     * Supprime les remises associées à un produit
640
     *
641
     * @param int $disc_product_id
642
     * @return bool
643
     */
644
    public function removeProductFromDiscounts($disc_product_id)
645
    {
646
        $disc_product_id = (int)$disc_product_id;
647
648
        return $this->deleteAll(new \Criteria('disc_product_id', $disc_product_id, '='));
649
    }
650
}
651