|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Eccube\Service\Calculator; |
|
4
|
|
|
|
|
5
|
|
|
use Eccube\Entity\Master\OrderItemType; |
|
6
|
|
|
use Eccube\Entity\ShipmentItem; |
|
7
|
|
|
|
|
8
|
|
|
class ShipmentItemCollection extends \ArrayIterator |
|
|
|
|
|
|
9
|
|
|
{ |
|
10
|
|
|
public function __construct($ShipmentItems, $flags = 0) |
|
|
|
|
|
|
11
|
|
|
{ |
|
12
|
|
|
// $ShipmentItems が Collection だったら toArray(); する |
|
13
|
|
|
parent::__construct($ShipmentItems, $flags); |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
// 明細種別ごとに返すメソッド作る |
|
17
|
|
|
public function getProductClasses() |
|
|
|
|
|
|
18
|
|
|
{ |
|
19
|
|
|
return $this->subCollection(OrderItemType::PRODUCT); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function getDeliveryFees() |
|
|
|
|
|
|
23
|
|
|
{ |
|
24
|
|
|
return $this->subCollection(OrderItemType::DELIVERY_FEE); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* 指定した受注明細区分だけの明細を取得. |
|
29
|
|
|
* @param int $orderItemTypeId 受注明細区分ID |
|
30
|
|
|
* @return ShipmentItemCollection |
|
31
|
|
|
*/ |
|
32
|
|
|
private function subCollection($orderItemTypeId) |
|
33
|
|
|
{ |
|
34
|
|
|
return new self(array_filter($this->getArrayCopy(), function($ShipmentItem) use ($orderItemTypeId) { |
|
|
|
|
|
|
35
|
|
|
/* @var ShipmentItem $ShipmentItem */ |
|
36
|
|
|
return $ShipmentItem->getOrderItemType() && $ShipmentItem->getOrderItemType()->getId() == $orderItemTypeId; |
|
37
|
|
|
})); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
|
|
|
|
|
41
|
|
|
* 同名の明細が存在するかどうか. |
|
42
|
|
|
* |
|
43
|
|
|
* TODO 暫定対応. 本来は明細種別でチェックする. |
|
44
|
|
|
*/ |
|
|
|
|
|
|
45
|
|
|
public function hasProductByName($productName) |
|
|
|
|
|
|
46
|
|
|
{ |
|
47
|
|
|
$ShipmentItems = array_filter($this->getArrayCopy(), |
|
48
|
|
|
function ($ShipmentItem) use ($productName) { |
|
49
|
|
|
/* @var ShipmentItem $ShipmentItem */ |
|
50
|
|
|
return $ShipmentItem->getProductName() == $productName; |
|
51
|
|
|
}); |
|
52
|
|
|
return !empty($ShipmentItems); |
|
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
// map, filter, reduce も実装したい |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* 指定した受注明細区分の明細が存在するかどうか |
|
58
|
|
|
* @param OrderItemType $OrderItemType 受注区分 |
|
59
|
|
|
* @return boolean |
|
60
|
|
|
*/ |
|
61
|
|
|
public function hasItemByOrderItemType($OrderItemType) |
|
62
|
|
|
{ |
|
63
|
|
|
$filteredItems = array_filter($this->getArrayCopy(), function($ShipmentItem) use ($OrderItemType) { |
|
|
|
|
|
|
64
|
|
|
/* @var ShipmentItem $ShipmentItem */ |
|
65
|
|
|
return $ShipmentItem->getOrderItemType() && $ShipmentItem->getOrderItemType()->getId() == $OrderItemType->getId(); |
|
66
|
|
|
}); |
|
67
|
|
|
return !empty($filteredItems); |
|
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|