Class: Spree::CouponCodes::BulkGenerate

Inherits:
Object
  • Object
show all
Includes:
ServiceModule::Base
Defined in:
app/services/spree/coupon_codes/bulk_generate.rb

Instance Method Summary collapse

Methods included from ServiceModule::Base

prepended

Instance Method Details

#call(promotion:, quantity: 10) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/services/spree/coupon_codes/bulk_generate.rb', line 6

def call(promotion:, quantity: 10)
  coupon_codes = []

  Spree::CouponCode.transaction do
    quantity.times do
      coupon_codes << coupon_attributes(promotion).merge(code: create_code(promotion.code_prefix))
    end
    Spree::CouponCode.insert_all coupon_codes
  end

  success(promotion.reload.coupon_codes)
end