Failed Conditions
Push — master ( 9c9d2b...a2b736 )
by chihiro
43:30
created

DeliveryRepository::findAllowedDeliveries()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 5

Importance

Changes 0
Metric Value
cc 5
eloc 11
nc 5
nop 2
dl 0
loc 21
ccs 11
cts 11
cp 1
crap 5
rs 8.7624
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * This program is free software; you can redistribute it and/or
11
 * modify it under the terms of the GNU General Public License
12
 * as published by the Free Software Foundation; either version 2
13
 * of the License, or (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program; if not, write to the Free Software
22
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23
 */
24
25
namespace Eccube\Repository;
26
27
use Doctrine\ORM\EntityRepository;
28
29
/**
30
 * DelivRepository
31
 *
32
 * This class was generated by the Doctrine ORM. Add your own custom
33
 * repository methods below.
34
 */
35
class DeliveryRepository extends EntityRepository
36
{
37
38 8
    public function findOrCreate($id)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
39
    {
40 8
        if ($id == 0) {
41 8
            $em = $this->getEntityManager();
42
43
            $ProductType = $em
44 8
                ->getRepository('\Eccube\Entity\Master\ProductType')
45 8
                ->findOneBy(array(), array('rank' => 'DESC'));
46
47 8
            $Delivery = $this->findOneBy(array(), array('rank' => 'DESC'));
48
49 8
            $rank = 1;
50 8
            if ($Delivery) {
51 8
                $rank = $Delivery->getRank() + 1;
52
            }
53
54 8
            $Delivery = new \Eccube\Entity\Delivery();
55
            $Delivery
56 8
                ->setRank($rank)
57 8
                ->setDelFlg(0)
58 8
                ->setProductType($ProductType);
59
        } else {
60 3
            $Delivery = $this->find($id);
61
        }
62
63 8
        return $Delivery;
64
    }
65
66
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$productTypes" missing
Loading history...
67
     * 複数の商品種別から配送業者を取得
68
     *
69
     * @param $productTypes
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
70
     * @return array
71
     */
72 129
    public function getDeliveries($productTypes)
73
    {
74
75 129
        $deliveries = $this->createQueryBuilder('d')
76 129
            ->where('d.ProductType in (:productTypes)')
77 129
            ->setParameter('productTypes', $productTypes)
78 129
            ->getQuery()
79 129
            ->getResult();
80
81 129
        return $deliveries;
82
    }
83
84
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$payments" missing
Loading history...
introduced by
Doc comment for parameter "$productTypes" missing
Loading history...
85
     * 選択可能な配送業者を取得
86
     *
87
     * @param $payments
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
88
     * @return array
89
     */
90 7
    public function findAllowedDeliveries($productTypes, $payments)
91
    {
92
93 7
        $d = $this->getDeliveries($productTypes);
94 7
        $arr = array();
95
96 7
        foreach ($d as $Delivery) {
97 6
            $paymentOptions = $Delivery->getPaymentOptions();
98
99 6
            foreach ($paymentOptions as $PaymentOption) {
100 6
                foreach ($payments as $Payment) {
101 5
                    if ($PaymentOption->getPayment()->getId() == $Payment['id']) {
102 5
                        $arr[$Delivery->getId()] = $Delivery;
103 7
                        break;
104
                    }
105
                }
106
            }
107
        }
108
109 7
        return array_values($arr);
110
    }
111
}
112