|
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\Payment; |
|
18
|
|
|
use Symfony\Bridge\Doctrine\RegistryInterface; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* PaymentRepository |
|
22
|
|
|
* |
|
23
|
|
|
* This class was generated by the Doctrine ORM. Add your own custom |
|
24
|
|
|
* repository methods below. |
|
25
|
|
|
*/ |
|
26
|
|
|
class PaymentRepository extends AbstractRepository |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* PaymentRepository constructor. |
|
30
|
|
|
* |
|
31
|
|
|
* @param RegistryInterface $registry |
|
32
|
|
|
*/ |
|
33
|
786 |
|
public function __construct(RegistryInterface $registry) |
|
34
|
|
|
{ |
|
35
|
786 |
|
parent::__construct($registry, Payment::class); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @return array |
|
40
|
|
|
*/ |
|
41
|
|
|
public function findAllArray() |
|
42
|
|
|
{ |
|
43
|
|
|
$query = $this |
|
44
|
|
|
->getEntityManager() |
|
45
|
8 |
|
->createQuery('SELECT p FROM Eccube\Entity\Payment p INDEX BY p.id'); |
|
46
|
|
|
$result = $query |
|
47
|
8 |
|
->getResult(Query::HYDRATE_ARRAY); |
|
48
|
8 |
|
|
|
49
|
|
|
return $result; |
|
50
|
8 |
|
} |
|
51
|
8 |
|
|
|
52
|
8 |
|
/** |
|
53
|
|
|
* 支払方法を取得 |
|
54
|
|
|
* 条件によってはDoctrineのキャッシュが返されるため、arrayで結果を返すパターンも用意 |
|
55
|
8 |
|
* |
|
56
|
|
|
* @param $delivery |
|
57
|
8 |
|
* @param $returnType true : Object、false: arrayが戻り値 |
|
58
|
8 |
|
* |
|
59
|
8 |
|
* @return array |
|
60
|
|
|
*/ |
|
61
|
|
|
public function findPayments($delivery, $returnType = false) |
|
62
|
|
|
{ |
|
63
|
|
|
$query = $this->createQueryBuilder('p') |
|
64
|
8 |
|
->innerJoin('Eccube\Entity\PaymentOption', 'po', 'WITH', 'po.payment_id = p.id') |
|
65
|
|
|
->where('po.Delivery = (:delivery) AND p.visible = true') |
|
66
|
|
|
->orderBy('p.sort_no', 'DESC') |
|
67
|
|
|
->setParameter('delivery', $delivery) |
|
68
|
|
|
->getQuery(); |
|
69
|
|
|
|
|
70
|
1 |
|
$query->expireResultCache(false); |
|
71
|
|
|
|
|
72
|
|
|
if ($returnType) { |
|
73
|
1 |
|
$payments = $query->getResult(); |
|
74
|
1 |
|
} else { |
|
75
|
|
|
$payments = $query->getArrayResult(); |
|
76
|
1 |
|
} |
|
77
|
|
|
|
|
78
|
1 |
|
return $payments; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* 共通の支払方法を取得 |
|
83
|
|
|
* |
|
84
|
|
|
* @param $deliveries |
|
85
|
|
|
* |
|
86
|
|
|
* @return array |
|
87
|
|
|
*/ |
|
88
|
|
|
public function findAllowedPayments($deliveries, $returnType = false) |
|
89
|
|
|
{ |
|
90
|
58 |
|
$payments = []; |
|
91
|
|
|
$saleTypes = []; |
|
92
|
58 |
|
foreach ($deliveries as $Delivery) { |
|
93
|
58 |
|
$p = $this->findPayments($Delivery, $returnType); |
|
94
|
58 |
|
if ($p == null) { |
|
95
|
58 |
|
continue; |
|
96
|
58 |
|
} |
|
97
|
58 |
|
foreach ($p as $payment) { |
|
98
|
|
|
$payments[$payment['id']] = $payment; |
|
99
|
58 |
|
$saleTypes[$Delivery->getSaleType()->getId()][$payment['id']] = true; |
|
100
|
|
|
} |
|
101
|
58 |
|
} |
|
102
|
52 |
|
|
|
103
|
|
|
foreach ($payments as $key => $payment) { |
|
104
|
6 |
|
foreach ($saleTypes as $row) { |
|
105
|
|
|
if (!isset($row[$payment['id']])) { |
|
106
|
|
|
unset($payments[$key]); |
|
107
|
58 |
|
continue; |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
return $payments; |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|