diff --git a/backend/app/Services/Domain/Event/DuplicateEventService.php b/backend/app/Services/Domain/Event/DuplicateEventService.php index d845cd7d81..3de5e46eff 100644 --- a/backend/app/Services/Domain/Event/DuplicateEventService.php +++ b/backend/app/Services/Domain/Event/DuplicateEventService.php @@ -127,7 +127,6 @@ public function duplicateEvent( event: $event, newEventId: $newEvent->getId(), duplicateQuestions: $duplicateQuestions, - duplicatePromoCodes: $duplicatePromoCodes, duplicateCapacityAssignments: $duplicateCapacityAssignments, duplicateCheckInLists: $duplicateCheckInLists, oldToNewOccurrenceMap: $oldToNewOccurrenceMap, @@ -136,6 +135,10 @@ public function duplicateEvent( $this->createProductCategoryService->createDefaultProductCategory($newEvent); } + if ($duplicatePromoCodes) { + $this->clonePromoCodes($event, $newEvent->getId(), $oldProductToNewProductMap); + } + if ($duplicateOccurrences && $duplicateProducts && ! empty($oldToNewOccurrenceMap)) { $this->cloneOccurrenceProductSettings($oldToNewOccurrenceMap, $oldProductToNewProductMap, $oldPriceToNewPriceMap); } @@ -240,7 +243,6 @@ private function cloneExistingProducts( EventDomainObject $event, int $newEventId, bool $duplicateQuestions, - bool $duplicatePromoCodes, bool $duplicateCapacityAssignments, bool $duplicateCheckInLists, array $oldToNewOccurrenceMap = [], @@ -285,10 +287,6 @@ private function cloneExistingProducts( $this->clonePerProductQuestions($event, $newEventId, $oldProductToNewProductMap); } - if ($duplicatePromoCodes) { - $this->clonePromoCodes($event, $newEventId, $oldProductToNewProductMap); - } - if ($duplicateCapacityAssignments) { $this->cloneCapacityAssignments($event, $newEventId, $oldProductToNewProductMap); } @@ -377,14 +375,19 @@ private function clonePerOrderQuestions(EventDomainObject $event, int $newEventI private function clonePromoCodes(EventDomainObject $event, int $newEventId, array $oldProductToNewProductMap): void { foreach ($event->getPromoCodes() as $promoCode) { + $mappedProductIds = array_values(array_filter( + array_map( + static fn ($productId) => $oldProductToNewProductMap[$productId] ?? null, + $promoCode->getApplicableProductIds() ?? [], + ), + static fn ($productId) => $productId !== null, + )); + $this->createPromoCodeService->createPromoCode( (new PromoCodeDomainObject) ->setCode($promoCode->getCode()) ->setEventId($newEventId) - ->setApplicableProductIds(array_map( - static fn ($productId) => $oldProductToNewProductMap[$productId], - $promoCode->getApplicableProductIds() ?? [], - )) + ->setApplicableProductIds($mappedProductIds) ->setDiscountType($promoCode->getDiscountType()) ->setDiscount($promoCode->getDiscount()) ->setExpiryDate($promoCode->getExpiryDate()) diff --git a/frontend/src/components/modals/DuplicateEventModal/index.tsx b/frontend/src/components/modals/DuplicateEventModal/index.tsx index ee6d79ae29..80e4332471 100644 --- a/frontend/src/components/modals/DuplicateEventModal/index.tsx +++ b/frontend/src/components/modals/DuplicateEventModal/index.tsx @@ -76,12 +76,10 @@ export const DuplicateEventModal = ({onClose, eventId}: DuplicateEventModalProps useEffect(() => { if (eventQuery?.data) { - form.setValues({ - title: eventQuery.data.title, - description: eventQuery.data.description, - start_date: utcToTz(eventQuery.data.start_date, eventQuery.data.timezone), - end_date: utcToTz(eventQuery.data.end_date, eventQuery.data.timezone), - }); + form.setFieldValue('title', eventQuery.data.title); + form.setFieldValue('description', eventQuery.data.description); + form.setFieldValue('start_date', utcToTz(eventQuery.data.start_date, eventQuery.data.timezone)); + form.setFieldValue('end_date', utcToTz(eventQuery.data.end_date, eventQuery.data.timezone)); } }, [eventQuery.isFetched]);