Class: Spree::PromotionHandler::PromotionDuplicator
- Inherits:
-
Object
- Object
- Spree::PromotionHandler::PromotionDuplicator
- Defined in:
- app/models/spree/promotion_handler/promotion_duplicator.rb
Instance Method Summary collapse
- #duplicate ⇒ Object
-
#initialize(promotion, random_string: nil) ⇒ PromotionDuplicator
constructor
A new instance of PromotionDuplicator.
Constructor Details
#initialize(promotion, random_string: nil) ⇒ PromotionDuplicator
Returns a new instance of PromotionDuplicator.
4 5 6 7 |
# File 'app/models/spree/promotion_handler/promotion_duplicator.rb', line 4 def initialize(promotion, random_string: nil) @promotion = promotion @random_string = random_string || generate_random_string(4) end |
Instance Method Details
#duplicate ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/models/spree/promotion_handler/promotion_duplicator.rb', line 9 def duplicate @new_promotion = @promotion.dup @new_promotion.path = "#{@promotion.path}_#{@random_string}" @new_promotion.name = "New #{@promotion.name}" @new_promotion.code = "#{@promotion.code}_#{@random_string}" @new_promotion.stores = @promotion.stores ActiveRecord::Base.transaction do @new_promotion.save copy_rules copy_actions end @new_promotion end |