diff --git a/src/elements/Code.php b/src/elements/Code.php index 23e9183..8ffc95d 100644 --- a/src/elements/Code.php +++ b/src/elements/Code.php @@ -302,7 +302,10 @@ public function afterSave(bool $isNew) $codeRecord->lineItemId = $this->lineItemId; $codeRecord->orderId = $this->orderId; $codeRecord->voucherId = $this->voucherId; - $codeRecord->codeKey = $this->generateCodeKey(); + + // Generate a code key if not already set + $codeRecord->codeKey = $this->codeKey ?? $this->generateCodeKey(); + // set the codeKey to the Code as well to use it directly $this->codeKey = $codeRecord->codeKey; }