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 @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/modals/ManageAttendeeModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -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]);

Expand Down
Loading