Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Voucher] Solution for a unique voucher code generation #1453

Closed
albertmueller opened this issue Jul 14, 2020 · 2 comments
Closed

[Voucher] Solution for a unique voucher code generation #1453

albertmueller opened this issue Jul 14, 2020 · 2 comments

Comments

@albertmueller
Copy link
Contributor

Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? yes/no

As discussed, try to generate a code until it is unique, currently i got a exception that the code already exists.

My current solution:

        $uniqueCode = false;
        while (!$uniqueCode) {
            $codes = $this->cartPriceRuleVoucherCodeGenerator->generateCodes($voucherCodeConfiguration);
            $code = reset($codes);

            $existingCode = $this->cartPriceRuleVoucherRepository->findByCode($code->getCode());
            if (!$existingCode) {
                $uniqueCode = true;
            }
        }
@dlhck
Copy link
Contributor

dlhck commented Jul 15, 2020

Great solution. Maybe we can also implement a user feedback in the backend to show those codes which would have been duplicates.

@dpfaffenbauer
Copy link
Member

@davidhoeck ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants