Skip to content

Commit e7dfc50

Browse files
authored
Feature: Order table UI/UX improvements (#904)
1 parent e28aea7 commit e7dfc50

File tree

8 files changed

+625
-219
lines changed

8 files changed

+625
-219
lines changed

backend/app/Http/Actions/Orders/Public/CompleteOrderActionPublic.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function __invoke(CompleteOrderRequest $request, int $eventId, string $or
3434
: null,
3535
]),
3636
'products' => $request->input('products'),
37+
'event_id' => $eventId,
3738
]));
3839
} catch (ResourceConflictException $e) {
3940
return $this->errorResponse($e->getMessage(), Response::HTTP_CONFLICT);

backend/app/Services/Application/Handlers/Order/CompleteOrderHandler.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Exception;
99
use HiEvents\DomainObjects\AttendeeDomainObject;
1010
use HiEvents\DomainObjects\Enums\ProductType;
11+
use HiEvents\DomainObjects\EventSettingDomainObject;
1112
use HiEvents\DomainObjects\Generated\AttendeeDomainObjectAbstract;
1213
use HiEvents\DomainObjects\Generated\OrderDomainObjectAbstract;
1314
use HiEvents\DomainObjects\Generated\ProductPriceDomainObjectAbstract;
@@ -24,6 +25,7 @@
2425
use HiEvents\Repository\Eloquent\Value\Relationship;
2526
use HiEvents\Repository\Interfaces\AffiliateRepositoryInterface;
2627
use HiEvents\Repository\Interfaces\AttendeeRepositoryInterface;
28+
use HiEvents\Repository\Interfaces\EventSettingsRepositoryInterface;
2729
use HiEvents\Repository\Interfaces\OrderRepositoryInterface;
2830
use HiEvents\Repository\Interfaces\ProductPriceRepositoryInterface;
2931
use HiEvents\Repository\Interfaces\QuestionAnswerRepositoryInterface;
@@ -55,6 +57,7 @@ public function __construct(
5557
private readonly ProductQuantityUpdateService $productQuantityUpdateService,
5658
private readonly ProductPriceRepositoryInterface $productPriceRepository,
5759
private readonly DomainEventDispatcherService $domainEventDispatcherService,
60+
private readonly EventSettingsRepositoryInterface $eventSettingsRepository,
5861
)
5962
{
6063
}
@@ -90,7 +93,16 @@ public function handle(string $orderShortId, CompleteOrderDTO $orderData): Order
9093
return $updatedOrder;
9194
});
9295

93-
OrderStatusChangedEvent::dispatch($updatedOrder);
96+
/** @var EventSettingDomainObject $eventSettings */
97+
$eventSettings = $this->eventSettingsRepository->findFirstWhere([
98+
'event_id' => $orderData->event_id,
99+
]);
100+
101+
event(new OrderStatusChangedEvent(
102+
order: $updatedOrder,
103+
sendEmails: true,
104+
createInvoice: $eventSettings->getEnableInvoicing(),
105+
));
94106

95107
if ($updatedOrder->isOrderCompleted()) {
96108
$this->domainEventDispatcherService->dispatch(

backend/app/Services/Application/Handlers/Order/DTO/CompleteOrderDTO.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ class CompleteOrderDTO extends BaseDTO
1111
/**
1212
* @param CompleteOrderOrderDTO $order
1313
* @param Collection<CompleteOrderProductDataDTO> $products
14+
* @param int $event_id
1415
*/
1516
public function __construct(
1617
public CompleteOrderOrderDTO $order,
1718
#[CollectionOf(CompleteOrderProductDataDTO::class)]
18-
public Collection $products
19+
public Collection $products,
20+
public int $event_id,
1921
)
2022
{
2123
}

backend/tests/Unit/Services/Application/Handlers/Order/CompleteOrderHandlerTest.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
use Carbon\Carbon;
66
use Exception;
77
use HiEvents\DomainObjects\AttendeeDomainObject;
8+
use HiEvents\DomainObjects\EventSettingDomainObject;
89
use HiEvents\DomainObjects\OrderDomainObject;
910
use HiEvents\DomainObjects\OrderItemDomainObject;
1011
use HiEvents\DomainObjects\ProductPriceDomainObject;
1112
use HiEvents\DomainObjects\Status\OrderStatus;
1213
use HiEvents\Exceptions\ResourceConflictException;
1314
use HiEvents\Repository\Interfaces\AffiliateRepositoryInterface;
1415
use HiEvents\Repository\Interfaces\AttendeeRepositoryInterface;
16+
use HiEvents\Repository\Interfaces\EventSettingsRepositoryInterface;
1517
use HiEvents\Repository\Interfaces\OrderRepositoryInterface;
1618
use HiEvents\Repository\Interfaces\ProductPriceRepositoryInterface;
1719
use HiEvents\Repository\Interfaces\QuestionAnswerRepositoryInterface;
@@ -44,6 +46,7 @@ class CompleteOrderHandlerTest extends TestCase
4446
private CompleteOrderHandler $completeOrderHandler;
4547
private DomainEventDispatcherService $domainEventDispatcherService;
4648
private AffiliateRepositoryInterface|MockInterface $affiliateRepository;
49+
private EventSettingsRepositoryInterface $eventSettingsRepository;
4750

4851
protected function setUp(): void
4952
{
@@ -60,6 +63,7 @@ protected function setUp(): void
6063
$this->productPriceRepository = Mockery::mock(ProductPriceRepositoryInterface::class);
6164
$this->domainEventDispatcherService = Mockery::mock(DomainEventDispatcherService::class);
6265
$this->affiliateRepository = Mockery::mock(AffiliateRepositoryInterface::class);
66+
$this->eventSettingsRepository = Mockery::mock(EventSettingsRepositoryInterface::class);
6367

6468
$this->completeOrderHandler = new CompleteOrderHandler(
6569
$this->orderRepository,
@@ -68,7 +72,8 @@ protected function setUp(): void
6872
$this->questionAnswersRepository,
6973
$this->productQuantityUpdateService,
7074
$this->productPriceRepository,
71-
$this->domainEventDispatcherService
75+
$this->domainEventDispatcherService,
76+
$this->eventSettingsRepository,
7277
);
7378
}
7479

@@ -97,6 +102,8 @@ public function testHandleSuccessfullyCompletesOrder(): void
97102

98103
$this->productQuantityUpdateService->shouldReceive('updateQuantitiesFromOrder');
99104

105+
$this->eventSettingsRepository->shouldReceive('findFirstWhere')->andReturn($this->createMockEventSetting());
106+
100107
$this->completeOrderHandler->handle($orderShortId, $orderData);
101108

102109
$this->assertTrue(true);
@@ -169,6 +176,8 @@ public function testHandleUpdatesProductQuantitiesForFreeOrder(): void
169176

170177
$this->productQuantityUpdateService->shouldReceive('updateQuantitiesFromOrder')->once();
171178

179+
$this->eventSettingsRepository->shouldReceive('findFirstWhere')->andReturn($this->createMockEventSetting());
180+
172181
$this->domainEventDispatcherService->shouldReceive('dispatch')
173182
->withArgs(function (OrderEvent $event) use ($order) {
174183
return $event->type === DomainEventType::ORDER_CREATED
@@ -201,6 +210,8 @@ public function testHandleDoesNotUpdateProductQuantitiesForPaidOrder(): void
201210

202211
$this->productQuantityUpdateService->shouldNotReceive('updateQuantitiesFromOrder');
203212

213+
$this->eventSettingsRepository->shouldReceive('findFirstWhere')->andReturn($this->createMockEventSetting());
214+
204215
$this->completeOrderHandler->handle($orderShortId, $orderData);
205216

206217
$this->expectNotToPerformAssertions();
@@ -269,6 +280,7 @@ private function createMockCompleteOrderDTO(): CompleteOrderDTO
269280
return new CompleteOrderDTO(
270281
order: $orderDTO,
271282
products: new Collection([$attendeeDTO])
283+
,event_id: 1
272284
);
273285
}
274286

@@ -313,4 +325,11 @@ private function createMockAttendee(): AttendeeDomainObject|MockInterface
313325
$attendee->shouldReceive('getProductId')->andReturn(1);
314326
return $attendee;
315327
}
328+
329+
private function createMockEventSetting(): EventSettingDomainObject
330+
{
331+
return (new EventSettingDomainObject())
332+
->setId(1)
333+
->setEventId(1);
334+
}
316335
}

0 commit comments

Comments
 (0)