Skip to content

Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️

Copy promo codes when duplicating an event (#1344)

B.cd159056a3c4
diff --git a/backend/app/Services/Domain/Event/DuplicateEventService.php b/backend/app/Services/Domain/Event/DuplicateEventService.php
index d845cd7d8..3de5e46ef 100644
--- a/backend/app/Services/Domain/Event/DuplicateEventService.php
+++ b/backend/app/Services/Domain/Event/DuplicateEventService.php
@@ -127,7 +127,6 @@ class DuplicateEventService
event: $event,
newEventId: $newEvent->getId(),
duplicateQuestions: $duplicateQuestions,
- duplicatePromoCodes: $duplicatePromoCodes,
duplicateCapacityAssignments: $duplicateCapacityAssignments,
duplicateCheckInLists: $duplicateCheckInLists,
oldToNewOccurrenceMap: $oldToNewOccurrenceMap,
@@ -136,6 +135,10 @@ class DuplicateEventService
$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 @@ class DuplicateEventService
EventDomainObject $event,
int $newEventId,
bool $duplicateQuestions,
- bool $duplicatePromoCodes,
bool $duplicateCapacityAssignments,
bool $duplicateCheckInLists,
array $oldToNewOccurrenceMap = [],
@@ -285,10 +287,6 @@ class DuplicateEventService
$this->clonePerProductQuestions($event, $newEventId, $oldProductToNewProductMap);
}
- if ($duplicatePromoCodes) {
- $this->clonePromoCodes($event, $newEventId, $oldProductToNewProductMap);
- }
-
if ($duplicateCapacityAssignments) {
$this->cloneCapacityAssignments($event, $newEventId, $oldProductToNewProductMap);
}
@@ -377,14 +375,19 @@ class DuplicateEventService
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 ee6d79ae2..80e433247 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]);