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
);
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, thembezhanov/faker-provider-collection
library we use in the Product generator has apromotionCode
method that might be perfect for this: