Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function __invoke(CompleteOrderRequest $request, int $eventId, string $or
: null,
]),
'products' => $request->input('products'),
'event_id' => $eventId,
]));
} catch (ResourceConflictException $e) {
return $this->errorResponse($e->getMessage(), Response::HTTP_CONFLICT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Exception;
use HiEvents\DomainObjects\AttendeeDomainObject;
use HiEvents\DomainObjects\Enums\ProductType;
use HiEvents\DomainObjects\EventSettingDomainObject;
use HiEvents\DomainObjects\Generated\AttendeeDomainObjectAbstract;
use HiEvents\DomainObjects\Generated\OrderDomainObjectAbstract;
use HiEvents\DomainObjects\Generated\ProductPriceDomainObjectAbstract;
Expand All @@ -24,6 +25,7 @@
use HiEvents\Repository\Eloquent\Value\Relationship;
use HiEvents\Repository\Interfaces\AffiliateRepositoryInterface;
use HiEvents\Repository\Interfaces\AttendeeRepositoryInterface;
use HiEvents\Repository\Interfaces\EventSettingsRepositoryInterface;
use HiEvents\Repository\Interfaces\OrderRepositoryInterface;
use HiEvents\Repository\Interfaces\ProductPriceRepositoryInterface;
use HiEvents\Repository\Interfaces\QuestionAnswerRepositoryInterface;
Expand Down Expand Up @@ -55,6 +57,7 @@ public function __construct(
private readonly ProductQuantityUpdateService $productQuantityUpdateService,
private readonly ProductPriceRepositoryInterface $productPriceRepository,
private readonly DomainEventDispatcherService $domainEventDispatcherService,
private readonly EventSettingsRepositoryInterface $eventSettingsRepository,
)
{
}
Expand Down Expand Up @@ -90,7 +93,16 @@ public function handle(string $orderShortId, CompleteOrderDTO $orderData): Order
return $updatedOrder;
});

OrderStatusChangedEvent::dispatch($updatedOrder);
/** @var EventSettingDomainObject $eventSettings */
$eventSettings = $this->eventSettingsRepository->findFirstWhere([
'event_id' => $orderData->event_id,
]);

event(new OrderStatusChangedEvent(
order: $updatedOrder,
sendEmails: true,
createInvoice: $eventSettings->getEnableInvoicing(),
));

if ($updatedOrder->isOrderCompleted()) {
$this->domainEventDispatcherService->dispatch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ class CompleteOrderDTO extends BaseDTO
/**
* @param CompleteOrderOrderDTO $order
* @param Collection<CompleteOrderProductDataDTO> $products
* @param int $event_id
*/
public function __construct(
public CompleteOrderOrderDTO $order,
#[CollectionOf(CompleteOrderProductDataDTO::class)]
public Collection $products
public Collection $products,
public int $event_id,
)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
use Carbon\Carbon;
use Exception;
use HiEvents\DomainObjects\AttendeeDomainObject;
use HiEvents\DomainObjects\EventSettingDomainObject;
use HiEvents\DomainObjects\OrderDomainObject;
use HiEvents\DomainObjects\OrderItemDomainObject;
use HiEvents\DomainObjects\ProductPriceDomainObject;
use HiEvents\DomainObjects\Status\OrderStatus;
use HiEvents\Exceptions\ResourceConflictException;
use HiEvents\Repository\Interfaces\AffiliateRepositoryInterface;
use HiEvents\Repository\Interfaces\AttendeeRepositoryInterface;
use HiEvents\Repository\Interfaces\EventSettingsRepositoryInterface;
use HiEvents\Repository\Interfaces\OrderRepositoryInterface;
use HiEvents\Repository\Interfaces\ProductPriceRepositoryInterface;
use HiEvents\Repository\Interfaces\QuestionAnswerRepositoryInterface;
Expand Down Expand Up @@ -44,6 +46,7 @@ class CompleteOrderHandlerTest extends TestCase
private CompleteOrderHandler $completeOrderHandler;
private DomainEventDispatcherService $domainEventDispatcherService;
private AffiliateRepositoryInterface|MockInterface $affiliateRepository;
private EventSettingsRepositoryInterface $eventSettingsRepository;

protected function setUp(): void
{
Expand All @@ -60,6 +63,7 @@ protected function setUp(): void
$this->productPriceRepository = Mockery::mock(ProductPriceRepositoryInterface::class);
$this->domainEventDispatcherService = Mockery::mock(DomainEventDispatcherService::class);
$this->affiliateRepository = Mockery::mock(AffiliateRepositoryInterface::class);
$this->eventSettingsRepository = Mockery::mock(EventSettingsRepositoryInterface::class);

$this->completeOrderHandler = new CompleteOrderHandler(
$this->orderRepository,
Expand All @@ -68,7 +72,8 @@ protected function setUp(): void
$this->questionAnswersRepository,
$this->productQuantityUpdateService,
$this->productPriceRepository,
$this->domainEventDispatcherService
$this->domainEventDispatcherService,
$this->eventSettingsRepository,
);
}

Expand Down Expand Up @@ -97,6 +102,8 @@ public function testHandleSuccessfullyCompletesOrder(): void

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

$this->eventSettingsRepository->shouldReceive('findFirstWhere')->andReturn($this->createMockEventSetting());

$this->completeOrderHandler->handle($orderShortId, $orderData);

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

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

$this->eventSettingsRepository->shouldReceive('findFirstWhere')->andReturn($this->createMockEventSetting());

$this->domainEventDispatcherService->shouldReceive('dispatch')
->withArgs(function (OrderEvent $event) use ($order) {
return $event->type === DomainEventType::ORDER_CREATED
Expand Down Expand Up @@ -201,6 +210,8 @@ public function testHandleDoesNotUpdateProductQuantitiesForPaidOrder(): void

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

$this->eventSettingsRepository->shouldReceive('findFirstWhere')->andReturn($this->createMockEventSetting());

$this->completeOrderHandler->handle($orderShortId, $orderData);

$this->expectNotToPerformAssertions();
Expand Down Expand Up @@ -269,6 +280,7 @@ private function createMockCompleteOrderDTO(): CompleteOrderDTO
return new CompleteOrderDTO(
order: $orderDTO,
products: new Collection([$attendeeDTO])
,event_id: 1
);
}

Expand Down Expand Up @@ -313,4 +325,11 @@ private function createMockAttendee(): AttendeeDomainObject|MockInterface
$attendee->shouldReceive('getProductId')->andReturn(1);
return $attendee;
}

private function createMockEventSetting(): EventSettingDomainObject
{
return (new EventSettingDomainObject())
->setId(1)
->setEventId(1);
}
}
Loading
Loading