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 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
|
|
|
|
39
|
8 |
|
public function findOrCreate($id) |
40
|
|
|
{ |
41
|
8 |
|
if ($id == 0) { |
42
|
8 |
|
$em = $this->getEntityManager(); |
43
|
|
|
|
44
|
|
|
$ProductType = $em |
45
|
8 |
|
->getRepository('\Eccube\Entity\Master\ProductType') |
46
|
8 |
|
->findOneBy(array(), array('rank' => 'DESC')); |
47
|
|
|
|
48
|
8 |
|
$Delivery = $this->findOneBy(array(), array('rank' => 'DESC')); |
49
|
|
|
|
50
|
8 |
|
$rank = 1; |
51
|
8 |
|
if ($Delivery) { |
52
|
8 |
|
$rank = $Delivery->getRank() + 1; |
53
|
|
|
} |
54
|
|
|
|
55
|
8 |
|
$Delivery = new \Eccube\Entity\Delivery(); |
56
|
|
|
$Delivery |
57
|
8 |
|
->setRank($rank) |
58
|
8 |
|
->setDelFlg(0) |
59
|
8 |
|
->setProductType($ProductType); |
60
|
|
|
} else { |
61
|
3 |
|
$Delivery = $this->find($id); |
62
|
|
|
} |
63
|
|
|
|
64
|
8 |
|
return $Delivery; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
|
|
|
|
68
|
|
|
* 複数の商品種別から配送業者を取得 |
69
|
|
|
* |
70
|
|
|
* @param $productTypes |
71
|
|
|
* @return array |
72
|
|
|
*/ |
73
|
176 |
|
public function getDeliveries($productTypes) |
74
|
|
|
{ |
75
|
|
|
|
76
|
176 |
|
$deliveries = $this->createQueryBuilder('d') |
77
|
176 |
|
->where('d.ProductType in (:productTypes)') |
78
|
176 |
|
->setParameter('productTypes', $productTypes) |
79
|
176 |
|
->getQuery() |
80
|
176 |
|
->getResult(); |
81
|
|
|
|
82
|
176 |
|
return $deliveries; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* 選択可能な配送業者を取得 |
87
|
|
|
* |
88
|
|
|
* @param $payments |
89
|
|
|
* @return array |
90
|
|
|
*/ |
91
|
7 |
|
public function findAllowedDeliveries($productTypes, $payments) |
92
|
|
|
{ |
93
|
|
|
|
94
|
7 |
|
$d = $this->getDeliveries($productTypes); |
95
|
7 |
|
$arr = array(); |
96
|
|
|
|
97
|
7 |
|
foreach ($d as $Delivery) { |
98
|
6 |
|
$paymentOptions = $Delivery->getPaymentOptions(); |
99
|
|
|
|
100
|
6 |
|
foreach ($paymentOptions as $PaymentOption) { |
101
|
6 |
|
foreach ($payments as $Payment) { |
102
|
5 |
|
if ($PaymentOption->getPayment() instanceof Payment) { |
103
|
5 |
|
if ($PaymentOption->getPayment()->getId() == $Payment['id']) { |
104
|
5 |
|
$arr[$Delivery->getId()] = $Delivery; |
105
|
7 |
|
break; |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
112
|
7 |
|
return array_values($arr); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|