|
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\Service\PurchaseFlow; |
|
15
|
|
|
|
|
16
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
17
|
|
|
use Doctrine\Common\Collections\Collection; |
|
18
|
|
|
use Eccube\Entity\ItemInterface; |
|
19
|
|
|
use Eccube\Entity\Master\OrderItemType; |
|
20
|
|
|
use Eccube\Entity\Order; |
|
21
|
|
|
|
|
22
|
|
|
class ItemCollection extends ArrayCollection |
|
|
|
|
|
|
23
|
|
|
{ |
|
24
|
|
|
protected $type; |
|
25
|
|
|
|
|
26
|
329 |
|
public function __construct($Items, $type = null) |
|
27
|
|
|
{ |
|
28
|
329 |
|
$this->type = is_null($type) ? Order::class : $type; |
|
29
|
|
|
|
|
30
|
329 |
|
if ($Items instanceof Collection) { |
|
31
|
329 |
|
$Items = $Items->toArray(); |
|
32
|
|
|
} |
|
33
|
329 |
|
parent::__construct($Items); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
299 |
|
public function reduce(\Closure $func, $initial = null) |
|
37
|
|
|
{ |
|
38
|
299 |
|
return array_reduce($this->toArray(), $func, $initial); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
// 明細種別ごとに返すメソッド作る |
|
42
|
294 |
|
public function getProductClasses() |
|
|
|
|
|
|
43
|
|
|
{ |
|
44
|
294 |
|
return $this->filter( |
|
45
|
294 |
|
function (ItemInterface $OrderItem) { |
|
46
|
290 |
|
return $OrderItem->isProduct(); |
|
47
|
294 |
|
}); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
294 |
|
public function getDeliveryFees() |
|
51
|
|
|
{ |
|
52
|
294 |
|
return $this->filter( |
|
53
|
294 |
|
function (ItemInterface $OrderItem) { |
|
54
|
290 |
|
return $OrderItem->isDeliveryFee(); |
|
55
|
294 |
|
}); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
294 |
|
public function getCharges() |
|
59
|
|
|
{ |
|
60
|
294 |
|
return $this->filter( |
|
61
|
294 |
|
function (ItemInterface $OrderItem) { |
|
62
|
290 |
|
return $OrderItem->isCharge(); |
|
63
|
294 |
|
}); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
294 |
|
public function getDiscounts() |
|
67
|
|
|
{ |
|
68
|
294 |
|
return $this->filter( |
|
69
|
294 |
|
function (ItemInterface $OrderItem) { |
|
70
|
290 |
|
return $OrderItem->isDiscount() || $OrderItem->isPoint(); |
|
71
|
294 |
|
}); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
|
|
|
|
|
75
|
|
|
* 同名の明細が存在するかどうか. |
|
76
|
|
|
* |
|
77
|
|
|
* TODO 暫定対応. 本来は明細種別でチェックする. |
|
78
|
|
|
*/ |
|
|
|
|
|
|
79
|
|
View Code Duplication |
public function hasProductByName($productName) |
|
|
|
|
|
|
80
|
|
|
{ |
|
81
|
|
|
$OrderItems = $this->filter( |
|
82
|
|
|
function (ItemInterface $OrderItem) use ($productName) { |
|
83
|
|
|
/* @var OrderItem $OrderItem */ |
|
84
|
|
|
return $OrderItem->getProductName() == $productName; |
|
85
|
|
|
}); |
|
86
|
|
|
|
|
87
|
|
|
return !$OrderItems->isEmpty(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* 指定した受注明細区分の明細が存在するかどうか. |
|
92
|
|
|
* |
|
93
|
|
|
* @param OrderItemType $OrderItemType 受注区分 |
|
94
|
|
|
* |
|
95
|
|
|
* @return bool |
|
96
|
|
|
*/ |
|
97
|
|
View Code Duplication |
public function hasItemByOrderItemType($OrderItemType) |
|
|
|
|
|
|
98
|
|
|
{ |
|
99
|
1 |
|
$filteredItems = $this->filter(function (ItemInterface $OrderItem) use ($OrderItemType) { |
|
100
|
|
|
/* @var OrderItem $OrderItem */ |
|
101
|
1 |
|
return $OrderItem->getOrderItemType() && $OrderItem->getOrderItemType()->getId() == $OrderItemType->getId(); |
|
102
|
1 |
|
}); |
|
103
|
|
|
|
|
104
|
1 |
|
return !$filteredItems->isEmpty(); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function getType() |
|
108
|
|
|
{ |
|
109
|
|
|
return $this->type; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
329 |
|
public function sort() |
|
113
|
|
|
{ |
|
114
|
329 |
|
$Items = $this->toArray(); |
|
115
|
329 |
|
usort($Items, function (ItemInterface $a, ItemInterface $b) { |
|
116
|
237 |
|
if ($a->getOrderItemType() === $b->getOrderItemType()) { |
|
117
|
39 |
|
return ($a->getId() < $b->getId()) ? -1 : 1; |
|
118
|
229 |
|
} elseif ($a->isProduct()) { |
|
119
|
209 |
|
return -1; |
|
120
|
179 |
|
} elseif ($a->isDeliveryFee()) { |
|
121
|
163 |
|
if ($b->isProduct()) { |
|
122
|
11 |
|
return 1; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
153 |
|
return -1; |
|
126
|
169 |
|
} elseif ($a->isCharge()) { |
|
127
|
153 |
|
if ($b->isDeliveryFee() || $b->isProduct()) { |
|
128
|
2 |
|
return 1; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
153 |
|
return -1; |
|
132
|
19 |
|
} elseif ($a->isDiscount() || $a->isPoint()) { |
|
133
|
3 |
|
if ($b->isDiscount()) { |
|
134
|
|
|
return -1; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
3 |
|
if ($b->isPoint()) { |
|
138
|
|
|
return 1; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
3 |
|
if (!$b->isTax()) { |
|
142
|
3 |
|
return 1; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
return -1; |
|
146
|
16 |
|
} elseif ($a->isTax()) { |
|
147
|
|
|
return 1; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
16 |
|
return 0; |
|
151
|
329 |
|
}); |
|
152
|
|
|
|
|
153
|
329 |
|
return new self($Items); |
|
154
|
|
|
} |
|
155
|
|
|
} |
|
156
|
|
|
|