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.

Revert "Bulk promo codes improvements" (#12009)

Damian Legawiec31b334e99459
diff --git a/core/app/models/spree/promotion.rb b/core/app/models/spree/promotion.rb
index f93b834bc1..841352e76a 100644
--- a/core/app/models/spree/promotion.rb
+++ b/core/app/models/spree/promotion.rb
@@ -30,7 +30,6 @@ module Spree
has_many :stores, class_name: 'Spree::Store', through: :store_promotions
has_many :promotion_batches, foreign_key: 'template_promotion_id'
- has_many :promotions_from_template, through: :promotion_batches, class_name: 'Spree::Promotion', source: :promotions
accepts_nested_attributes_for :promotion_actions, :promotion_rules
@@ -52,10 +51,8 @@ module Spree
SQL
}
scope :templates, -> { where(template: true) }
- scope :for_template_promotion_id, ->(id) { joins(:promotion_batch).where(promotion_batch: { template_promotion_id: id }) }
- self.whitelisted_ransackable_attributes = ['path', 'promotion_category_id', 'promotion_batch_id', 'code']
- self.whitelisted_ransackable_scopes = ['for_template_promotion_id']
+ self.whitelisted_ransackable_attributes = ['path', 'promotion_category_id', 'code']
def self.with_coupon_code(coupon_code)
where("lower(#{table_name}.code) = ?", coupon_code.strip.downcase).
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 ad49650037..655632018b 100644
--- a/core/app/models/spree/promotion_handler/promotion_batch_duplicator.rb
+++ b/core/app/models/spree/promotion_handler/promotion_batch_duplicator.rb
@@ -14,7 +14,6 @@ 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/app/services/spree/promotion_batches/generate_code.rb b/core/app/services/spree/promotion_batches/generate_code.rb
index 08161d8dec..f34a464768 100644
--- a/core/app/services/spree/promotion_batches/generate_code.rb
+++ b/core/app/services/spree/promotion_batches/generate_code.rb
@@ -8,7 +8,7 @@ module Spree
def call(random_characters:, prefix: nil, suffix: nil)
[
prefix,
- @random.hex(random_characters).upcase,
+ @random.hex(random_characters),
suffix
].join('')
end
diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml
index 4c17f6aabb..f1ff1ed252 100644
--- a/core/config/locales/en.yml
+++ b/core/config/locales/en.yml
@@ -1743,7 +1743,8 @@ en:
taxonomy_tree_error: The requested change has not been accepted and the tree has been returned to its previous state, please try again.
taxonomy_tree_instruction: ! '* Right click (or double tap on iOS device) a child in the tree to access the menu for adding, deleting or sorting a child.'
taxons: Taxons
- template_promotions: Template Promotions
+ template_not_found: Template promotion - not found! Assign a template before populating a batch.
+ template_promotion_already_assigned: Template promotion has already been assigned!
test: Test
test_mailer:
test_email:
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 1e98e7210d..12aa435e8e 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,7 +18,6 @@ describe Spree::PromotionHandler::PromotionBatchDuplicator do
code: 'test1',
advertise: true,
path: 'test1',
- template: true,
promotion_category: promo_category,
stores: [store, store_2])
end
@@ -32,7 +31,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', 'template'] }
+ let(:excluded_fields) { ['code', 'path', 'id', 'created_at', 'updated_at', 'deleted_at', 'promotion_batch_id', 'usage_limit'] }
context "when code is provided" do
subject { described_class.new(promotion, promotion_batch.id, code: provided_code) }
@@ -58,10 +57,6 @@ 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
diff --git a/core/spec/services/spree/promotion_batches/generate_code_spec.rb b/core/spec/services/spree/promotion_batches/generate_code_spec.rb
index f3848296c3..0f74f8eef3 100644
--- a/core/spec/services/spree/promotion_batches/generate_code_spec.rb
+++ b/core/spec/services/spree/promotion_batches/generate_code_spec.rb
@@ -10,11 +10,11 @@ module Spree
let(:suffix) { nil }
before do
- allow(random_double).to receive(:hex).with(random_characters).and_return('code')
+ allow(random_double).to receive(:hex).with(random_characters).and_return('CODE')
end
context 'when no prefix or suffix is set' do
- it 'returns randomly generated code in uppercase' do
+ it 'returns randomly generated code' do
expect(subject).to eq('CODE')
end
end