-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SP-107,108,109 Bulk promo codes #285
base: main
Are you sure you want to change the base?
Conversation
Gemfile
Outdated
@@ -64,4 +64,5 @@ end | |||
spree_opts = { github: 'spree/spree', branch: 'main' } | |||
gem 'spree_core', spree_opts | |||
gem 'spree_api', spree_opts | |||
gem 'sidekiq' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't add sidekiq as a dependency - Spree::Core defines a Spree::ApplicationJob
as a base for async jobs. It's based on ApplicationJob, which means that if an application already uses a different job queue, they will be able to keep using it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Thanks!
@@ -0,0 +1,7 @@ | |||
class CreatePromotionBatch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I've mentioned before, this should live in Spree::Core, not in Spree::Backend - as it's not strictly related to the admin panel. Otherwise we won't be able to reuse this logic e.g. in the API.
87342e8
to
6b57a51
Compare
@@ -40,6 +40,7 @@ def collection | |||
params[:q][:s] ||= 'id desc' | |||
|
|||
@collection = super | |||
@collection = @collection.where(promotion_batch_id: nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why's that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order not to display the batched promotions. This would effectively flood the index view, and render it unusable.
config/routes.rb
Outdated
@@ -10,6 +10,14 @@ | |||
|
|||
resources :promotion_categories, except: [:show] | |||
|
|||
resources :promotion_batches do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we support e.g. removing an existing promotion batch? If yes, what it the consequence of this action for the promotions that were created as a part of this batch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty batches (with and without a template promotion assigned) can be deleted. For non-empty batches an error is displayed, and the cascading deletion is rolled back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would the desired behaviour be? Delete/soft-delete the associated promotions? Or should it stay like this until the associated promotions are deleted?
Note: the latter would require adding an option to manage a bulk delete (currently, an update to the template propagates to the batched promotions by recreating them).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As currently a promotion can be deleted regardless of the fact whether it's been used or not (also, when it's not depleted its limit yet), so I've added a service for deleting a batch.
redirect_back fallback_location: admin_promotions_path, alert: e.message | ||
end | ||
|
||
def duplicate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that duplicate
or populate
(following the convention you've used for the service objects)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spot on! Changed it 🙂
42bf39b
to
94743b0
Compare
7c0f51e
to
2984a67
Compare
2984a67
to
70e43f0
Compare
What?
This PR extends the bulk promo codes feature with administrative functionality through the admin panel.
Handling and administrating promotion batches:
Create batch:
create.batch.mov
Populate batch:
populate.batch.mov
Promotion codes export to CSV:
promo.codes.export.to.csv.mov
Promotion codes import from CSV:
promo.codes.import.from.csv.mov
Populate batch with options:
populate.batch.with.options.mov
Why?
New feature