1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of EC-CUBE |
5
|
|
|
* |
6
|
|
|
* Copyright(c) LOCKON CO.,LTD. All Rights Reserved. |
7
|
|
|
* |
8
|
|
|
* http://www.lockon.co.jp/ |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Eccube\Repository; |
15
|
|
|
|
16
|
|
|
use Doctrine\ORM\Query; |
17
|
|
|
use Eccube\Entity\Order; |
18
|
|
|
use Eccube\Entity\Payment; |
19
|
|
|
use Symfony\Bridge\Doctrine\RegistryInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* PaymentRepository |
23
|
|
|
* |
24
|
|
|
* This class was generated by the Doctrine ORM. Add your own custom |
25
|
|
|
* repository methods below. |
26
|
|
|
*/ |
27
|
|
|
class PaymentRepository extends AbstractRepository |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* PaymentRepository constructor. |
31
|
|
|
* |
32
|
|
|
* @param RegistryInterface $registry |
33
|
|
|
*/ |
34
|
722 |
|
public function __construct(RegistryInterface $registry) |
35
|
|
|
{ |
36
|
722 |
|
parent::__construct($registry, Payment::class); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
|
|
|
|
40
|
|
|
* @deprecated 呼び出し元で制御する |
41
|
|
|
* |
42
|
|
|
* @param $id |
|
|
|
|
43
|
|
|
* |
44
|
|
|
* @return \Eccube\Entity\Payment|null|object |
45
|
|
|
*/ |
46
|
8 |
|
public function findOrCreate($id) |
47
|
|
|
{ |
48
|
8 |
|
if ($id == 0) { |
49
|
8 |
|
$Payment = $this->findOneBy([], ['sort_no' => 'DESC']); |
50
|
|
|
|
51
|
8 |
|
$sortNo = 1; |
52
|
8 |
|
if ($Payment) { |
53
|
8 |
|
$sortNo = $Payment->getSortNo() + 1; |
54
|
|
|
} |
55
|
|
|
|
56
|
8 |
|
$Payment = new \Eccube\Entity\Payment(); |
57
|
|
|
$Payment |
58
|
8 |
|
->setSortNo($sortNo) |
59
|
8 |
|
->setFixed(true) |
60
|
8 |
|
->setVisible(true); |
61
|
|
|
} else { |
62
|
|
|
$Payment = $this->find($id); |
63
|
|
|
} |
64
|
|
|
|
65
|
8 |
|
return $Payment; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return array |
70
|
|
|
*/ |
71
|
1 |
|
public function findAllArray() |
72
|
|
|
{ |
73
|
|
|
$query = $this |
74
|
1 |
|
->getEntityManager() |
75
|
1 |
|
->createQuery('SELECT p FROM Eccube\Entity\Payment p INDEX BY p.id'); |
76
|
|
|
$result = $query |
77
|
1 |
|
->getResult(Query::HYDRATE_ARRAY); |
78
|
|
|
|
79
|
1 |
|
return $result; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
|
|
|
|
83
|
|
|
* 支払方法を取得 |
84
|
|
|
* 条件によってはDoctrineのキャッシュが返されるため、arrayで結果を返すパターンも用意 |
85
|
|
|
* |
86
|
|
|
* @param $delivery |
|
|
|
|
87
|
|
|
* @param $returnType true : Object、false: arrayが戻り値 |
|
|
|
|
88
|
|
|
* |
89
|
|
|
* @return array |
90
|
|
|
*/ |
91
|
58 |
|
public function findPayments($delivery, $returnType = false) |
92
|
|
|
{ |
93
|
58 |
|
$query = $this->createQueryBuilder('p') |
94
|
58 |
|
->innerJoin('Eccube\Entity\PaymentOption', 'po', 'WITH', 'po.payment_id = p.id') |
95
|
58 |
|
->where('po.Delivery = (:delivery) AND p.visible = true') |
96
|
58 |
|
->orderBy('p.sort_no', 'DESC') |
97
|
58 |
|
->setParameter('delivery', $delivery) |
98
|
58 |
|
->getQuery(); |
99
|
|
|
|
100
|
58 |
|
$query->expireResultCache(false); |
101
|
|
|
|
102
|
58 |
|
if ($returnType) { |
103
|
52 |
|
$payments = $query->getResult(); |
104
|
|
|
} else { |
105
|
6 |
|
$payments = $query->getArrayResult(); |
106
|
|
|
} |
107
|
|
|
|
108
|
58 |
|
return $payments; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
|
|
|
|
112
|
|
|
* 共通の支払方法を取得 |
113
|
|
|
* |
114
|
|
|
* @param $deliveries |
|
|
|
|
115
|
|
|
* @param bool $returnType |
|
|
|
|
116
|
|
|
* @param Order $Order |
|
|
|
|
117
|
|
|
* |
118
|
|
|
* @return array |
119
|
|
|
*/ |
120
|
57 |
|
public function findAllowedPayments($deliveries, $returnType = false, Order $Order = null) |
121
|
|
|
{ |
122
|
57 |
|
$deliveries = array_unique($deliveries); |
123
|
57 |
|
$payments = []; |
124
|
57 |
|
$isFirstLoop = true; |
125
|
57 |
|
$totalPayment = 0; |
126
|
57 |
|
if (!is_null($Order)) { |
127
|
51 |
|
$totalPayment = $Order->getSubtotal(); |
128
|
|
|
} |
129
|
57 |
|
foreach ($deliveries as $Delivery) { |
130
|
56 |
|
$paymentTmp = []; |
131
|
56 |
|
$p = $this->findPayments($Delivery, $returnType); |
132
|
56 |
|
if ($p == null) { |
133
|
|
|
continue; |
134
|
|
|
} |
135
|
56 |
|
foreach ($p as $payment) { |
136
|
56 |
|
if (empty($totalPayment)) { |
137
|
56 |
|
$paymentTmp[$payment['id']] = $payment; |
138
|
56 |
|
continue; |
139
|
|
|
} |
140
|
50 |
|
if (is_null($payment['rule_min']) |
141
|
50 |
|
|| $payment['rule_min'] <= $totalPayment |
142
|
|
|
) { |
143
|
50 |
|
if (is_null($payment['rule_max']) |
144
|
50 |
|
|| ($payment['rule_max'] && $payment['rule_max'] >= $totalPayment) |
145
|
|
|
) { |
146
|
50 |
|
$paymentTmp[$payment['id']] = $payment; |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|
151
|
56 |
|
if ($isFirstLoop) { |
152
|
56 |
|
$payments = $paymentTmp; |
153
|
56 |
|
$isFirstLoop = false; |
154
|
|
|
} else { |
155
|
4 |
|
$payments = array_intersect_key($payments, $paymentTmp); |
156
|
|
|
|
157
|
4 |
|
if (count($payments) == 0) { |
158
|
56 |
|
break; |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
} |
162
|
|
|
|
163
|
57 |
|
return $payments; |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
|