Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Clone template promotion without the template flag

Rafal Cymeryscedc27e880de
diff --git a/core/app/models/spree/promotion_handler/promotion_batch_duplicator.rb b/core/app/models/spree/promotion_handler/promotion_batch_duplicator.rb
index 655632018b..ad49650037 100644
--- a/core/app/models/spree/promotion_handler/promotion_batch_duplicator.rb
+++ b/core/app/models/spree/promotion_handler/promotion_batch_duplicator.rb
@@ -14,6 +14,7 @@ module Spree
new_promotion.path = "#{@promotion.path}_#{@code}"
new_promotion.code = @code
new_promotion.stores = @promotion.stores
+ new_promotion.template = false
ActiveRecord::Base.transaction do
new_promotion.save
diff --git a/core/spec/models/spree/promotion_handler/promotion_batch_duplicator_spec.rb b/core/spec/models/spree/promotion_handler/promotion_batch_duplicator_spec.rb
index 12aa435e8e..1e98e7210d 100644
--- a/core/spec/models/spree/promotion_handler/promotion_batch_duplicator_spec.rb
+++ b/core/spec/models/spree/promotion_handler/promotion_batch_duplicator_spec.rb
@@ -18,6 +18,7 @@ describe Spree::PromotionHandler::PromotionBatchDuplicator do
code: 'test1',
advertise: true,
path: 'test1',
+ template: true,
promotion_category: promo_category,
stores: [store, store_2])
end
@@ -31,7 +32,7 @@ describe Spree::PromotionHandler::PromotionBatchDuplicator do
let(:promotion_batch) { create(:promotion_batch) }
context 'model fields' do
- let(:excluded_fields) { ['code', 'path', 'id', 'created_at', 'updated_at', 'deleted_at', 'promotion_batch_id', 'usage_limit'] }
+ let(:excluded_fields) { ['code', 'path', 'id', 'created_at', 'updated_at', 'deleted_at', 'promotion_batch_id', 'usage_limit', 'template'] }
context "when code is provided" do
subject { described_class.new(promotion, promotion_batch.id, code: provided_code) }
@@ -57,6 +58,10 @@ describe Spree::PromotionHandler::PromotionBatchDuplicator do
it 'associates the duplicated promotion with a batch' do
expect(new_promotion.promotion_batch_id).to match promotion_batch.id
end
+
+ it 'returns a duplicate promotion with template set to false' do
+ expect(new_promotion.template?).to be_falsey
+ end
end
context 'model associations - rules' do