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