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

Coupons: Increase uniqueness of coupon codes #118

Open
coreymckrill opened this issue Mar 13, 2023 · 0 comments
Open

Coupons: Increase uniqueness of coupon codes #118

coreymckrill opened this issue Mar 13, 2023 · 0 comments

Comments

@coreymckrill
Copy link
Contributor

Currently generated coupon codes take the form of "discount$amount". This means that given a small enough range of discount values and/or a large enough number of coupons to generate, you will end up generating multiple coupons with the same code. When that happens, the duplicate is skipped, but it still counts towards the total number that the CLI script generates.

One way to solve this would be to replace discount in the coupon code with a string from the faker library we're already using. In fact, the mbezhanov/faker-provider-collection library we use in the Product generator has a promotionCode method that might be perfect for this:

self::$faker->addProvider( new \Bezhanov\Faker\Provider\Commerce( self::$faker ) );

$coupon_id = sprintf(
	%s%d,
	self::$faker->promotionCode( 0 ), // We don't want random digits, we want the actual amount of the discount.
	$amount
);
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

1 participant