Skip to content

Commit

Permalink
Merge pull request #5787 from mamhoff/move-promotion-code-batch-services
Browse files Browse the repository at this point in the history
Move promotion code batch services
  • Loading branch information
tvdeyen authored Jun 14, 2024
2 parents 20ddfc4 + d293d0d commit 90d5770
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 11 deletions.
3 changes: 1 addition & 2 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ Layout/EmptyLinesAroundAttributeAccessor:
- "core/app/models/spree/address/state_validator.rb"
- "core/app/models/spree/order_updater.rb"
- "core/app/models/spree/promotion/order_adjustments_recalculator.rb"
- "core/app/models/spree/promotion_code/batch_builder.rb"
- "core/app/models/spree/stock_quantities.rb"
- "core/app/models/spree/variant.rb"
- "core/lib/spree/app_configuration.rb"
Expand Down Expand Up @@ -311,7 +310,7 @@ Rails/ApplicationController:
# This cop supports unsafe autocorrection (--autocorrect-all).
Rails/ApplicationJob:
Exclude:
- "core/app/jobs/spree/promotion_code_batch_job.rb"
- "legacy_promotions/app/jobs/spree/promotion_code_batch_job.rb"

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Expand Down
9 changes: 0 additions & 9 deletions core/app/models/spree/promotion_code_batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,5 @@ class CantProcessStartedBatch < StandardError
def finished?
state == "completed"
end

def process
if state == "pending"
update!(state: "processing")
PromotionCodeBatchJob.perform_later(self)
else
raise CantProcessStartedBatch.new("Batch #{id} already started")
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module SolidusLegacyPromotions
module SpreePromotionCodeBatchDecorator
def process
if state == "pending"
update!(state: "processing")
Spree::PromotionCodeBatchJob.perform_later(self)
else
raise Spree::PromotionCodeBatch::CantProcessStartedBatch.new("Batch #{id} already started")
end
end

Spree::PromotionCodeBatch.prepend(self)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

class ::Spree::PromotionCode::BatchBuilder
attr_reader :promotion_code_batch, :options

delegate :promotion, :number_of_codes, :base_code, to: :promotion_code_batch

DEFAULT_OPTIONS = {
Expand Down

0 comments on commit 90d5770

Please sign in to comment.