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
|
|
|
use Doctrine\ORM\Query; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* PaymentRepository |
32
|
|
|
* |
33
|
|
|
* This class was generated by the Doctrine ORM. Add your own custom |
34
|
|
|
* repository methods below. |
35
|
|
|
*/ |
36
|
|
|
class PaymentRepository extends EntityRepository |
37
|
|
|
{ |
38
|
|
|
|
39
|
11 |
|
public function findOrCreate($id) |
|
|
|
|
40
|
|
|
{ |
41
|
11 |
|
if ($id == 0) { |
42
|
|
|
|
43
|
8 |
|
$Payment = $this->findOneBy(array(), array('rank' => 'DESC')); |
44
|
|
|
|
45
|
8 |
|
$rank = 1; |
46
|
8 |
|
if ($Payment) { |
47
|
8 |
|
$rank = $Payment->getRank() + 1; |
48
|
|
|
} |
49
|
|
|
|
50
|
8 |
|
$Payment = new \Eccube\Entity\Payment(); |
51
|
|
|
$Payment |
52
|
8 |
|
->setRank($rank) |
53
|
8 |
|
->setDelFlg(0) |
54
|
8 |
|
->setFixFlg(1) |
55
|
8 |
|
->setChargeFlg(1); |
56
|
|
|
} else { |
57
|
3 |
|
$Payment = $this->find($id); |
58
|
|
|
} |
59
|
|
|
|
60
|
11 |
|
return $Payment; |
61
|
|
|
} |
62
|
|
|
|
63
|
1 |
|
public function findAllArray() |
64
|
|
|
{ |
65
|
|
|
|
66
|
|
|
$query = $this |
67
|
1 |
|
->getEntityManager() |
68
|
1 |
|
->createQuery('SELECT p FROM Eccube\Entity\Payment p INDEX BY p.id'); |
69
|
|
|
$result = $query |
70
|
1 |
|
->getResult(Query::HYDRATE_ARRAY); |
71
|
|
|
|
72
|
1 |
|
return $result; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* 支払方法を取得 |
77
|
|
|
* 条件によってはDoctrineのキャッシュが返されるため、arrayで結果を返すパターンも用意 |
78
|
|
|
* |
79
|
|
|
* @param $delivery |
80
|
|
|
* @param $returnType true : Object、false: arrayが戻り値 |
81
|
|
|
* @return array |
82
|
|
|
*/ |
83
|
111 |
|
public function findPayments($delivery, $returnType = false) |
84
|
|
|
{ |
85
|
|
|
|
86
|
111 |
|
$query = $this->createQueryBuilder('p') |
87
|
111 |
|
->innerJoin('Eccube\Entity\PaymentOption', 'po', 'WITH', 'po.payment_id = p.id') |
88
|
111 |
|
->where('po.Delivery = (:delivery)') |
89
|
111 |
|
->orderBy('p.rank', 'DESC') |
90
|
111 |
|
->setParameter('delivery', $delivery) |
91
|
111 |
|
->getQuery(); |
92
|
|
|
|
93
|
111 |
|
$query->expireResultCache(false); |
94
|
|
|
|
95
|
111 |
|
if ($returnType) { |
96
|
83 |
|
$payments = $query->getResult(); |
97
|
|
|
} else { |
98
|
108 |
|
$payments = $query->getArrayResult(); |
99
|
|
|
} |
100
|
|
|
|
101
|
111 |
|
return $payments; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* 共通の支払方法を取得 |
106
|
|
|
* |
107
|
|
|
* @param $deliveries |
108
|
|
|
* @return array |
109
|
|
|
*/ |
110
|
108 |
|
public function findAllowedPayments($deliveries) |
111
|
|
|
{ |
112
|
108 |
|
$payments = array(); |
113
|
108 |
|
$i = 0; |
114
|
|
|
|
115
|
108 |
|
foreach ($deliveries as $Delivery) { |
116
|
107 |
|
$p = $this->findPayments($Delivery); |
117
|
|
|
|
118
|
107 |
|
if ($i != 0) { |
119
|
|
|
|
120
|
10 |
|
$arr = array(); |
121
|
10 |
|
foreach ($p as $payment) { |
122
|
10 |
|
foreach ($payments as $pay) { |
123
|
10 |
|
if ($payment['id'] == $pay['id']) { |
124
|
8 |
|
$arr[] = $payment; |
125
|
10 |
|
break; |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
130
|
10 |
|
$payments = $arr; |
131
|
|
|
} else { |
132
|
107 |
|
$payments = $p; |
133
|
|
|
} |
134
|
108 |
|
$i++; |
135
|
|
|
} |
136
|
|
|
|
137
|
108 |
|
return $payments; |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|