diff --git a/promotions/app/models/solidus_promotions/promotion_code/batch_builder.rb b/promotions/app/models/solidus_promotions/promotion_code/batch_builder.rb index 14ba03543ab..9e7189f7050 100644 --- a/promotions/app/models/solidus_promotions/promotion_code/batch_builder.rb +++ b/promotions/app/models/solidus_promotions/promotion_code/batch_builder.rb @@ -43,15 +43,16 @@ def generate_random_codes new_codes = Array.new(max_codes_to_generate) { generate_random_code }.uniq codes_for_current_batch = get_unique_codes(new_codes) - codes_for_current_batch = codes_for_current_batch.map do |value| + codes_for_current_batch.filter! do |value| SolidusPromotions::PromotionCode.create!( value: value, promotion: promotion, promotion_code_batch: promotion_code_batch ) rescue ActiveRecord::RecordInvalid - nil - end.compact + false + end + created_codes += codes_for_current_batch.size end end