From cc09cfabeabede4bdcc6eb5eed092cc0c542b35a Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Wed, 12 Jun 2024 14:28:16 +0200 Subject: [PATCH 1/4] Move PromotionCodeBatchBuilder to solidus_legacy_promotions --- .rubocop_todo.yml | 1 - .../app/models/spree/promotion_code/batch_builder.rb | 1 + .../spec/models/spree/promotion_code/batch_builder_spec.rb | 0 3 files changed, 1 insertion(+), 1 deletion(-) rename {core => legacy_promotions}/app/models/spree/promotion_code/batch_builder.rb (99%) rename {core => legacy_promotions}/spec/models/spree/promotion_code/batch_builder_spec.rb (100%) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index b8d47b2e57c..0157596d7d5 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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" diff --git a/core/app/models/spree/promotion_code/batch_builder.rb b/legacy_promotions/app/models/spree/promotion_code/batch_builder.rb similarity index 99% rename from core/app/models/spree/promotion_code/batch_builder.rb rename to legacy_promotions/app/models/spree/promotion_code/batch_builder.rb index 26fa1d63745..60eb7873bba 100644 --- a/core/app/models/spree/promotion_code/batch_builder.rb +++ b/legacy_promotions/app/models/spree/promotion_code/batch_builder.rb @@ -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 = { diff --git a/core/spec/models/spree/promotion_code/batch_builder_spec.rb b/legacy_promotions/spec/models/spree/promotion_code/batch_builder_spec.rb similarity index 100% rename from core/spec/models/spree/promotion_code/batch_builder_spec.rb rename to legacy_promotions/spec/models/spree/promotion_code/batch_builder_spec.rb From 6d0a975e2af80efc0c03b0b5786aac1df7c45724 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Wed, 12 Jun 2024 13:03:33 +0200 Subject: [PATCH 2/4] Move PromotionCodeBatch#process to solidus_legacy_promotions We need to temporarily freedom-patch Spree::PromotionCodeBatch, because the model class needs to stay in Solidus Core, but the tests, jobs and mailers are already in `solidus_legacy_promotions`. Once everything is moved, we can merge the model and the decorator again. --- core/app/models/spree/promotion_code_batch.rb | 9 --------- .../spree_promotion_code_batch_decorator.rb | 16 ++++++++++++++++ .../models/spree/promotion_code_batch_spec.rb | 0 3 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 legacy_promotions/app/decorators/solidus_legacy_promotions/models/spree_promotion_code_batch_decorator.rb rename {core => legacy_promotions}/spec/models/spree/promotion_code_batch_spec.rb (100%) diff --git a/core/app/models/spree/promotion_code_batch.rb b/core/app/models/spree/promotion_code_batch.rb index 85a17be14be..66cbcc50d6a 100644 --- a/core/app/models/spree/promotion_code_batch.rb +++ b/core/app/models/spree/promotion_code_batch.rb @@ -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 diff --git a/legacy_promotions/app/decorators/solidus_legacy_promotions/models/spree_promotion_code_batch_decorator.rb b/legacy_promotions/app/decorators/solidus_legacy_promotions/models/spree_promotion_code_batch_decorator.rb new file mode 100644 index 00000000000..fdb8c85454b --- /dev/null +++ b/legacy_promotions/app/decorators/solidus_legacy_promotions/models/spree_promotion_code_batch_decorator.rb @@ -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 diff --git a/core/spec/models/spree/promotion_code_batch_spec.rb b/legacy_promotions/spec/models/spree/promotion_code_batch_spec.rb similarity index 100% rename from core/spec/models/spree/promotion_code_batch_spec.rb rename to legacy_promotions/spec/models/spree/promotion_code_batch_spec.rb From 83304b5df47767b0b95908546b92d84f2d6292bf Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Wed, 12 Jun 2024 10:37:31 +0200 Subject: [PATCH 3/4] Move PromotionCodeBatchMailer to solidus_legacy_promotions --- .../app/mailers/spree/promotion_code_batch_mailer.rb | 0 .../promotion_code_batch_errored.text.erb | 0 .../promotion_code_batch_finished.text.erb | 0 .../spec/mailers/spree}/promotion_code_batch_mailer_spec.rb | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename {core => legacy_promotions}/app/mailers/spree/promotion_code_batch_mailer.rb (100%) rename {core => legacy_promotions}/app/views/spree/promotion_code_batch_mailer/promotion_code_batch_errored.text.erb (100%) rename {core => legacy_promotions}/app/views/spree/promotion_code_batch_mailer/promotion_code_batch_finished.text.erb (100%) rename {core/spec/mailers => legacy_promotions/spec/mailers/spree}/promotion_code_batch_mailer_spec.rb (100%) diff --git a/core/app/mailers/spree/promotion_code_batch_mailer.rb b/legacy_promotions/app/mailers/spree/promotion_code_batch_mailer.rb similarity index 100% rename from core/app/mailers/spree/promotion_code_batch_mailer.rb rename to legacy_promotions/app/mailers/spree/promotion_code_batch_mailer.rb diff --git a/core/app/views/spree/promotion_code_batch_mailer/promotion_code_batch_errored.text.erb b/legacy_promotions/app/views/spree/promotion_code_batch_mailer/promotion_code_batch_errored.text.erb similarity index 100% rename from core/app/views/spree/promotion_code_batch_mailer/promotion_code_batch_errored.text.erb rename to legacy_promotions/app/views/spree/promotion_code_batch_mailer/promotion_code_batch_errored.text.erb diff --git a/core/app/views/spree/promotion_code_batch_mailer/promotion_code_batch_finished.text.erb b/legacy_promotions/app/views/spree/promotion_code_batch_mailer/promotion_code_batch_finished.text.erb similarity index 100% rename from core/app/views/spree/promotion_code_batch_mailer/promotion_code_batch_finished.text.erb rename to legacy_promotions/app/views/spree/promotion_code_batch_mailer/promotion_code_batch_finished.text.erb diff --git a/core/spec/mailers/promotion_code_batch_mailer_spec.rb b/legacy_promotions/spec/mailers/spree/promotion_code_batch_mailer_spec.rb similarity index 100% rename from core/spec/mailers/promotion_code_batch_mailer_spec.rb rename to legacy_promotions/spec/mailers/spree/promotion_code_batch_mailer_spec.rb From d293d0d982ffe659f8d85603b08fd4a1e2bb4585 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Wed, 12 Jun 2024 10:39:42 +0200 Subject: [PATCH 4/4] Move PromotionCodeBatchJob to legacy_promotions --- .rubocop_todo.yml | 2 +- .../app/jobs/spree/promotion_code_batch_job.rb | 0 .../spec/jobs/spree}/promotion_code_batch_job_spec.rb | 0 3 files changed, 1 insertion(+), 1 deletion(-) rename {core => legacy_promotions}/app/jobs/spree/promotion_code_batch_job.rb (100%) rename {core/spec/jobs => legacy_promotions/spec/jobs/spree}/promotion_code_batch_job_spec.rb (100%) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 0157596d7d5..7a70952dbfa 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -310,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). diff --git a/core/app/jobs/spree/promotion_code_batch_job.rb b/legacy_promotions/app/jobs/spree/promotion_code_batch_job.rb similarity index 100% rename from core/app/jobs/spree/promotion_code_batch_job.rb rename to legacy_promotions/app/jobs/spree/promotion_code_batch_job.rb diff --git a/core/spec/jobs/promotion_code_batch_job_spec.rb b/legacy_promotions/spec/jobs/spree/promotion_code_batch_job_spec.rb similarity index 100% rename from core/spec/jobs/promotion_code_batch_job_spec.rb rename to legacy_promotions/spec/jobs/spree/promotion_code_batch_job_spec.rb