|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Shopware\Core\Checkout\Order\Aggregate\OrderLineItem; |
|
4
|
|
|
|
|
5
|
|
|
use Shopware\Core\Checkout\Cart\Price\Struct\PriceCollection; |
|
6
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection; |
|
7
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Search\Sorting\FieldSorting; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @method void add(OrderLineItemEntity $entity) |
|
11
|
|
|
* @method void set(string $key, OrderLineItemEntity $entity) |
|
12
|
|
|
* @method OrderLineItemEntity[] getIterator() |
|
13
|
|
|
* @method OrderLineItemEntity[] getElements() |
|
14
|
|
|
* @method OrderLineItemEntity|null get(string $key) |
|
15
|
|
|
* @method OrderLineItemEntity|null first() |
|
16
|
|
|
* @method OrderLineItemEntity|null last() |
|
17
|
|
|
*/ |
|
18
|
|
|
class OrderLineItemCollection extends EntityCollection |
|
19
|
|
|
{ |
|
20
|
|
|
public function getOrderIds(): array |
|
21
|
|
|
{ |
|
22
|
|
|
return $this->fmap(function (OrderLineItemEntity $orderLineItem) { |
|
23
|
24 |
|
return $orderLineItem->getOrderId(); |
|
24
|
|
|
}); |
|
25
|
24 |
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function filterByOrderId(string $id): self |
|
28
|
|
|
{ |
|
29
|
|
|
return $this->filter(function (OrderLineItemEntity $orderLineItem) use ($id) { |
|
30
|
|
|
return $orderLineItem->getOrderId() === $id; |
|
31
|
|
|
}); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function sortByCreationDate(string $sortDirection = FieldSorting::ASCENDING): void |
|
35
|
|
|
{ |
|
36
|
|
|
$this->sort(function (OrderLineItemEntity $a, OrderLineItemEntity $b) use ($sortDirection) { |
|
37
|
|
|
if ($sortDirection === FieldSorting::ASCENDING) { |
|
38
|
|
|
return $a->getCreatedAt() > $b->getCreatedAt(); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
return $a->getCreatedAt() < $b->getCreatedAt(); |
|
42
|
|
|
}); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function sortByPosition(): void |
|
46
|
|
|
{ |
|
47
|
|
|
$this->sort(function (OrderLineItemEntity $a, OrderLineItemEntity $b) { |
|
48
|
|
|
return $a->getPosition() > $b->getPosition(); |
|
49
|
|
|
}); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function getPayloadsProperty(string $property): array |
|
53
|
|
|
{ |
|
54
|
|
|
return $this->fmap(function (OrderLineItemEntity $lineItem) use ($property) { |
|
55
|
|
|
if (array_key_exists($property, $lineItem->getPayload())) { |
|
|
|
|
|
|
56
|
|
|
return $lineItem->getPayload()[$property]; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
return null; |
|
60
|
|
|
}); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function filterByType(string $type): self |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->filter(function (OrderLineItemEntity $lineItem) use ($type) { |
|
66
|
|
|
return $lineItem->getType() === $type; |
|
67
|
|
|
}); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function getApiAlias(): string |
|
71
|
|
|
{ |
|
72
|
|
|
return 'order_line_item_collection'; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function getPrices(): PriceCollection |
|
76
|
|
|
{ |
|
77
|
|
|
return new PriceCollection( |
|
78
|
|
|
array_filter(array_map(static function (OrderLineItemEntity $orderLineItem) { |
|
79
|
|
|
return $orderLineItem->getPrice(); |
|
80
|
|
|
}, array_values($this->getElements()))) |
|
81
|
|
|
); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
protected function getExpectedClass(): string |
|
85
|
|
|
{ |
|
86
|
|
|
return OrderLineItemEntity::class; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|