Code Duplication    Length = 94-94 lines in 2 locations

class/oledrion_discounts.php 2 locations

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