Code Duplication    Length = 94-94 lines in 2 locations

class/oledrion_discounts.php 2 locations

@@ 383-476 (lines=94) @@
380
     * @param array   $discountsDescription Descriptions des réductions appliquées
381
     * @param integer $productQty           Quantité commandée du produit
382
     */
383
    public function applyDiscountOnShipping(&$montantHT, &$discountsDescription, $productQty)
384
    {
385
        global $h_oledrion_commands;
386
        $tblRules = array();
387
        $tblRules = $this->getRulesOnShipping(); // Renvoie des objets Discounts
388
        if (count($tblRules) > 0) {
389
            $uid = Oledrion_utils::getCurrentUserID();
390
            foreach ($tblRules as $rule) {
391
                switch ($rule->getVar('disc_when')) {
392
                    case OLEDRION_DISCOUNT_WHEN1: // Dans tous les cas
393
                        if ($rule->getVar('disc_percent_monney') == OLEDRION_DISCOUNT_TYPE1) { // Réduction de x pourcent
394
                            $montantHT = $this->getDiscountedPrice($montantHT, $rule->getVar('disc_amount'));
395
                            if ($montantHT < 0) {
396
                                $montantHT = 0;
397
                            }
398
                        } else { // Réduction de x euros
399
                            $montantHT -= $rule->getVar('disc_amount');
400
                            if ($montantHT < 0) {
401
                                $montantHT = 0;
402
                            }
403
                        }
404
                        $discountsDescription[] = $rule->getVar('disc_description');
405
                        break;
406
407
                    case OLEDRION_DISCOUNT_WHEN2: // Si c'est le premier achat de l'utilisateur sur le site
408
                        if ($h_oledrion_commands->isFirstCommand($uid)) {
409
                            if ($rule->getVar('disc_percent_monney') == OLEDRION_DISCOUNT_TYPE1) { // Réduction de x pourcent
410
                                $montantHT = $this->getDiscountedPrice($montantHT, $rule->getVar('disc_amount'));
411
                                if ($montantHT < 0) {
412
                                    $montantHT = 0;
413
                                }
414
                            } else { // Réduction de x euros
415
                                $montantHT -= $rule->getVar('disc_amount');
416
                                if ($montantHT < 0) {
417
                                    $montantHT = 0;
418
                                }
419
                            }
420
                            $discountsDescription[] = $rule->getVar('disc_description');
421
                        }
422
                        break;
423
424
                    case OLEDRION_DISCOUNT_WHEN4: // Si la quantité est =, >, >=, <, <= à ...
425
                        $qtyDiscount = false;
426
                        switch ($rule->getVar('disc_qty_criteria')) {
427
                            case 0: // =
428
                                if ($productQty == $rule->getVar('disc_qty_value')) {
429
                                    $qtyDiscount = true;
430
                                }
431
                                break;
432
433
                            case 1: // >
434
                                if ($productQty > $rule->getVar('disc_qty_value')) {
435
                                    $qtyDiscount = true;
436
                                }
437
                                break;
438
439
                            case 2: // >=
440
                                if ($productQty >= $rule->getVar('disc_qty_value')) {
441
                                    $qtyDiscount = true;
442
                                }
443
                                break;
444
445
                            case 3: // <
446
                                if ($productQty < $rule->getVar('disc_qty_value')) {
447
                                    $qtyDiscount = true;
448
                                }
449
                                break;
450
451
                            case 4: // <=
452
                                if ($productQty <= $rule->getVar('disc_qty_value')) {
453
                                    $qtyDiscount = true;
454
                                }
455
                                break;
456
457
                        }
458
                        if ($qtyDiscount) {
459
                            if ($rule->getVar('disc_percent_monney') == OLEDRION_DISCOUNT_TYPE1) { // Réduction de x pourcents
460
                                $montantHT = $this->getDiscountedPrice($montantHT, $rule->getVar('disc_amount'));
461
                                if ($montantHT < 0) {
462
                                    $montantHT = 0;
463
                                }
464
                            } else { // Réduction de x euros
465
                                $montantHT -= $rule->getVar('disc_amount');
466
                                if ($montantHT < 0) {
467
                                    $montantHT = 0;
468
                                }
469
                            }
470
                            $discountsDescription[] = $rule->getVar('disc_description');
471
                        }
472
                        break;
473
                }
474
            }
475
        }
476
    }
477
478
    /**
479
     * Réductions à appliquer sur le montant HT de TOUS les produits
@@ 485-578 (lines=94) @@
482
     * @param array   $discountsDescription Descriptions des réductions appliquées
483
     * @param integer $productQty           Quantité commandée du produit
484
     */
485
    public function applyDiscountOnAllProducts(&$montantHT, &$discountsDescription, $productQty)
486
    {
487
        global $h_oledrion_commands;
488
        $tblRules = array();
489
        $tblRules = $this->getRulesOnAllProducts(); // Renvoie des objets Discounts
490
        if (count($tblRules) > 0) {
491
            $uid = Oledrion_utils::getCurrentUserID();
492
            foreach ($tblRules as $rule) {
493
                switch ($rule->getVar('disc_when')) {
494
                    case OLEDRION_DISCOUNT_WHEN1: // Dans tous les cas
495
                        if ($rule->getVar('disc_percent_monney') == OLEDRION_DISCOUNT_TYPE1) { // Réduction de x pourcent
496
                            $montantHT = $this->getDiscountedPrice($montantHT, $rule->getVar('disc_amount'));
497
                            if ($montantHT < 0) {
498
                                $montantHT = 0;
499
                            }
500
                        } else { // Réduction de x euros
501
                            $montantHT -= $rule->getVar('disc_amount');
502
                            if ($montantHT < 0) {
503
                                $montantHT = 0;
504
                            }
505
                        }
506
                        $discountsDescription[] = $rule->getVar('disc_description');
507
                        break;
508
509
                    case OLEDRION_DISCOUNT_WHEN2: // Si c'est le premier achat de l'utilisateur sur le site
510
                        if ($h_oledrion_commands->isFirstCommand($uid)) {
511
                            if ($rule->getVar('disc_percent_monney') == OLEDRION_DISCOUNT_TYPE1) { // Réduction de x pourcent
512
                                $montantHT = $this->getDiscountedPrice($montantHT, $rule->getVar('disc_amount'));
513
                                if ($montantHT < 0) {
514
                                    $montantHT = 0;
515
                                }
516
                            } else { // Réduction de x euros
517
                                $montantHT -= $rule->getVar('disc_amount');
518
                                if ($montantHT < 0) {
519
                                    $montantHT = 0;
520
                                }
521
                            }
522
                            $discountsDescription[] = $rule->getVar('disc_description');
523
                        }
524
                        break;
525
526
                    case OLEDRION_DISCOUNT_WHEN4: // Si la quantité est =, >, >=, <, <= à ...
527
                        $qtyDiscount = false;
528
                        switch ($rule->getVar('disc_qty_criteria')) {
529
                            case 0: // =
530
                                if ($productQty == $rule->getVar('disc_qty_value')) {
531
                                    $qtyDiscount = true;
532
                                }
533
                                break;
534
535
                            case 1: // >
536
                                if ($productQty > $rule->getVar('disc_qty_value')) {
537
                                    $qtyDiscount = true;
538
                                }
539
                                break;
540
541
                            case 2: // >=
542
                                if ($productQty >= $rule->getVar('disc_qty_value')) {
543
                                    $qtyDiscount = true;
544
                                }
545
                                break;
546
547
                            case 3: // <
548
                                if ($productQty < $rule->getVar('disc_qty_value')) {
549
                                    $qtyDiscount = true;
550
                                }
551
                                break;
552
553
                            case 4: // <=
554
                                if ($productQty <= $rule->getVar('disc_qty_value')) {
555
                                    $qtyDiscount = true;
556
                                }
557
                                break;
558
559
                        }
560
                        if ($qtyDiscount) {
561
                            if ($rule->getVar('disc_percent_monney') == OLEDRION_DISCOUNT_TYPE1) { // Réduction de x pourcent
562
                                $montantHT = $this->getDiscountedPrice($montantHT, $rule->getVar('disc_amount'));
563
                                if ($montantHT < 0) {
564
                                    $montantHT = 0;
565
                                }
566
                            } else { // Réduction de x euros
567
                                $montantHT -= $rule->getVar('disc_amount');
568
                                if ($montantHT < 0) {
569
                                    $montantHT = 0;
570
                                }
571
                            }
572
                            $discountsDescription[] = $rule->getVar('disc_description');
573
                        }
574
                        break;
575
                }
576
            }
577
        }
578
    }
579
580
    /**
581
     * Recalcul du prix HT du produit en appliquant les réductions, s'il y a lieu