diff --git a/backend/app/Services/Application/Handlers/Attendee/EditAttendeeHandler.php b/backend/app/Services/Application/Handlers/Attendee/EditAttendeeHandler.php index 9a714d2a8..8a7051bfd 100644 --- a/backend/app/Services/Application/Handlers/Attendee/EditAttendeeHandler.php +++ b/backend/app/Services/Application/Handlers/Attendee/EditAttendeeHandler.php @@ -39,10 +39,10 @@ public function __construct( public function handle(EditAttendeeDTO $editAttendeeDTO): AttendeeDomainObject { return $this->databaseManager->transaction(function () use ($editAttendeeDTO) { - $this->validateProductId($editAttendeeDTO); - $attendee = $this->getAttendee($editAttendeeDTO); + $this->validateProductId($editAttendeeDTO, $attendee); + $this->adjustProductQuantities($attendee, $editAttendeeDTO); $updatedAttendee = $this->updateAttendee($editAttendeeDTO); @@ -84,7 +84,10 @@ private function updateAttendee(EditAttendeeDTO $editAttendeeDTO): AttendeeDomai * @throws ValidationException * @throws NoTicketsAvailableException */ - private function validateProductId(EditAttendeeDTO $editAttendeeDTO): void + private function validateProductId( + EditAttendeeDTO $editAttendeeDTO, + AttendeeDomainObject $attendee, + ): void { /** @var ProductDomainObject $product */ $product = $this->productRepository @@ -106,6 +109,11 @@ private function validateProductId(EditAttendeeDTO $editAttendeeDTO): void ]); } + // No need to check availability if the product price hasn't changed + if ($attendee->getProductPriceId() === $editAttendeeDTO->product_price_id) { + return; + } + $availableQuantity = $this->productRepository->getQuantityRemainingForProductPrice( productId: $editAttendeeDTO->product_id, productPriceId: $product->getType() === ProductPriceType::TIERED->name diff --git a/frontend/src/components/modals/ManageAttendeeModal/index.tsx b/frontend/src/components/modals/ManageAttendeeModal/index.tsx index ec82cab14..807995a69 100644 --- a/frontend/src/components/modals/ManageAttendeeModal/index.tsx +++ b/frontend/src/components/modals/ManageAttendeeModal/index.tsx @@ -61,7 +61,7 @@ export const ManageAttendeeModal = ({onClose, attendeeId}: ManageAttendeeModalPr email: attendee.email, notes: attendee.notes || "", product_id: String(attendee.product_id), - product_price_id: String(attendee.product_price_id), + product_price_id: attendee.product_price_id ? String(attendee.product_price_id) : "", }); } }, [attendee]); @@ -72,11 +72,11 @@ export const ManageAttendeeModal = ({onClose, attendeeId}: ManageAttendeeModalPr } let productPriceId = event?.product_categories ?.flatMap(category => category.products) - .find(product => product.id === form.values.product_id)?.prices?.[0]?.id; + .find(product => String(product?.id) === String(form.values.product_id))?.prices?.[0]?.id; form.setValues({ ...form.values, - product_price_id: String(productPriceId), + product_price_id: productPriceId ? String(productPriceId) : "", }); }, [form.values.product_id]);