-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathOrderCommand.php
More file actions
123 lines (102 loc) · 4.38 KB
/
Copy pathOrderCommand.php
File metadata and controls
123 lines (102 loc) · 4.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
declare(strict_types=1);
namespace App\Command;
use Ibexa\Contracts\Core\Repository\PermissionResolver;
use Ibexa\Contracts\Core\Repository\UserService;
use Ibexa\Contracts\CoreSearch\Values\Query\Criterion\LogicalOr;
use Ibexa\Contracts\OrderManagement\OrderServiceInterface;
use Ibexa\Contracts\OrderManagement\Value\Order\OrderQuery;
use Ibexa\Contracts\OrderManagement\Value\Order\Query\Criterion\CompanyNameCriterion;
use Ibexa\Contracts\OrderManagement\Value\Order\Query\Criterion\CustomerNameCriterion;
use Ibexa\Contracts\OrderManagement\Value\Order\Query\Criterion\IdentifierCriterion;
use Ibexa\Contracts\OrderManagement\Value\OrderCurrency;
use Ibexa\Contracts\OrderManagement\Value\OrderItem;
use Ibexa\Contracts\OrderManagement\Value\OrderItemProduct;
use Ibexa\Contracts\OrderManagement\Value\OrderItemValue;
use Ibexa\Contracts\OrderManagement\Value\OrderUser;
use Ibexa\Contracts\OrderManagement\Value\OrderValue;
use Ibexa\Contracts\OrderManagement\Value\Struct\OrderCreateStruct;
use Ibexa\Contracts\OrderManagement\Value\Struct\OrderUpdateStruct;
use Money;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
#[AsCommand(
name: 'doc:order'
)]
final class OrderCommand extends Command
{
public function __construct(
private readonly PermissionResolver $permissionResolver,
private readonly UserService $userService,
private readonly OrderServiceInterface $orderService
) {
parent::__construct();
}
public function configure(): void
{
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$currentUser = $this->userService->loadUserByLogin('admin');
$this->permissionResolver->setCurrentUserReference($currentUser);
// Get order by identifier
$orderIdentifier = '2e897b31-0d7a-46d3-ba45-4eb65fe02790';
$order = $this->orderService->getOrderByIdentifier($orderIdentifier);
$output->writeln(sprintf('Order %s has status %s', $orderIdentifier, $order->getStatus()));
// Get order by id
$orderId = 1;
$order = $this->orderService->getOrder($orderId);
$output->writeln(sprintf('Order %d has status %s', $orderId, $order->getStatus()));
// OrderCreateStruct parameters
$items = [
new OrderItem(
10,
new OrderItemValue(
new Money\Money(12, new Money\Currency('EUR')),
new Money\Money(10, new Money\Currency('EUR')),
'12',
new Money\Money(24, new Money\Currency('EUR')),
new Money\Money(20, new Money\Currency('EUR')),
),
new OrderItemProduct(
1,
'desk1',
'Desk 1'
)
),
];
$value = new OrderValue(
new Money\Money(20, new Money\Currency('EUR')),
new Money\Money(120, new Money\Currency('EUR')),
new Money\Money(100, new Money\Currency('EUR')),
);
$user = new OrderUser(14, 'johndoe', 'jd@example.com');
$currency = new OrderCurrency(1, 'EUR');
// Create order
$orderCreateStruct = new OrderCreateStruct(
$user,
$currency,
$value,
'local_shop',
$items
);
$order = $this->orderService->createOrder($orderCreateStruct);
$output->writeln(sprintf('Created order with identifier %s', $order->getIdentifier()));
// Update order
$orderUpdateStruct = new OrderUpdateStruct('processed');
$this->orderService->updateOrder($order, $orderUpdateStruct);
$output->writeln(sprintf('Changed order status to %s', $order->getStatus()));
// Query for orders
$orderCriterions = [
new IdentifierCriterion('c328773e-8daa-4465-86d5-4d7890f3aa86'),
new CompanyNameCriterion('IBM'),
new CustomerNameCriterion('foo_user'),
];
$orderQuery = new OrderQuery(new LogicalOr(...$orderCriterions));
$orders = $this->orderService->findOrders($orderQuery);
$output->writeln(sprintf('Found %d orders with provided criteria', count($orders)));
return self::SUCCESS;
}
}