|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Eccube\Service\Calculator; |
|
4
|
|
|
|
|
5
|
|
|
use Eccube\Entity\Master\OrderItemType; |
|
6
|
|
|
use Eccube\Entity\ItemInterface; |
|
7
|
|
|
use Eccube\Entity\Order; |
|
8
|
|
|
|
|
9
|
|
|
class OrderItemCollection extends \Doctrine\Common\Collections\ArrayCollection |
|
|
|
|
|
|
10
|
|
|
{ |
|
11
|
|
|
protected $type; |
|
12
|
|
|
|
|
13
|
124 |
|
public function __construct($OrderItems, $type = null) |
|
|
|
|
|
|
14
|
|
|
{ |
|
15
|
|
|
// $OrderItems が Collection だったら toArray(); する |
|
16
|
124 |
|
$this->type = is_null($type) ? Order::class : $type; |
|
17
|
124 |
|
parent::__construct($OrderItems); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function reduce(\Closure $func, $initial = null) |
|
|
|
|
|
|
21
|
|
|
{ |
|
22
|
|
|
return array_reduce($this->toArray(), $func, $initial); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
// 明細種別ごとに返すメソッド作る |
|
26
|
124 |
|
public function getProductClasses() |
|
|
|
|
|
|
27
|
|
|
{ |
|
28
|
124 |
|
return $this->filter( |
|
29
|
|
|
function(ItemInterface $OrderItem) { |
|
|
|
|
|
|
30
|
124 |
|
return $OrderItem->isProduct(); |
|
31
|
124 |
|
}); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function getDeliveryFees() |
|
|
|
|
|
|
35
|
|
|
{ |
|
36
|
|
|
return $this->filter( |
|
37
|
|
|
function(ItemInterface $OrderItem) { |
|
|
|
|
|
|
38
|
|
|
return $OrderItem->isDeliveryFee(); |
|
39
|
|
|
}); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function getCharges() |
|
|
|
|
|
|
43
|
|
|
{ |
|
44
|
|
|
return $this->filter( |
|
45
|
|
|
function(ItemInterface $OrderItem) { |
|
|
|
|
|
|
46
|
|
|
return $OrderItem->isCharge(); |
|
47
|
|
|
}); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function getDiscounts() |
|
|
|
|
|
|
51
|
|
|
{ |
|
52
|
|
|
return $this->filter( |
|
53
|
|
|
function(ItemInterface $OrderItem) { |
|
|
|
|
|
|
54
|
|
|
return $OrderItem->isDiscount(); |
|
55
|
|
|
}); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
|
|
|
|
|
59
|
|
|
* 同名の明細が存在するかどうか. |
|
60
|
|
|
* |
|
61
|
|
|
* TODO 暫定対応. 本来は明細種別でチェックする. |
|
62
|
|
|
*/ |
|
|
|
|
|
|
63
|
|
View Code Duplication |
public function hasProductByName($productName) |
|
|
|
|
|
|
64
|
|
|
{ |
|
65
|
|
|
$OrderItems = $this->filter( |
|
66
|
|
|
function (ItemInterface $OrderItem) use ($productName) { |
|
67
|
|
|
/* @var OrderItem $OrderItem */ |
|
68
|
|
|
return $OrderItem->getProductName() == $productName; |
|
69
|
|
|
}); |
|
70
|
|
|
return !$OrderItems->isEmpty(); |
|
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* 指定した受注明細区分の明細が存在するかどうか |
|
75
|
|
|
* @param OrderItemType $OrderItemType 受注区分 |
|
76
|
|
|
* @return boolean |
|
77
|
|
|
*/ |
|
78
|
|
View Code Duplication |
public function hasItemByOrderItemType($OrderItemType) |
|
|
|
|
|
|
79
|
|
|
{ |
|
80
|
|
|
$filteredItems = $this->filter(function(ItemInterface $OrderItem) use ($OrderItemType) { |
|
|
|
|
|
|
81
|
|
|
/* @var OrderItem $OrderItem */ |
|
82
|
|
|
return $OrderItem->getOrderItemType() && $OrderItem->getOrderItemType()->getId() == $OrderItemType->getId(); |
|
83
|
|
|
}); |
|
84
|
|
|
return !$filteredItems->isEmpty(); |
|
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function getType() |
|
|
|
|
|
|
88
|
|
|
{ |
|
89
|
|
|
return $this->type; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|