-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Create a new promotion code inside an existing promotion #2872
Conversation
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.
👍on changes and the execution, thanks!
I just think we should use codes at plural for naming both for variables (eg. @promotion_codes
) and in the UI (eg. View Codes List
).
Do you agree?
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.
I really like that feature. The implementation is also 👌
I have some minor nits that would be great if you could address them.
Thanks for contributing
<div class="col-4"> | ||
<%= f.field_container :value do %> | ||
<%= f.label :value, class: 'required' %> | ||
<%= f.text_field :value, class: 'fullwidth', required: true %> |
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.
Wrong indention
flash[:success] = flash_message_for(@promotion_code, :successfully_created) | ||
redirect_to admin_promotion_promotion_codes_url(@promotion) | ||
else | ||
flash.now[:error] = @promotion_code.errors.full_messages.join(', ') |
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.
.full_messages.to_sentence
will do the same as .join(', ')
but uses an "and" as last divider. Very unlikely we have more than one error, but still :)
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.
I have copied it from
flash[:error] = @promotion.errors.full_messages.join(", ") |
I'll update both !
core/config/locales/en.yml
Outdated
@@ -1145,6 +1145,7 @@ en: | |||
customer_returns: Customer Returns | |||
create: Create | |||
create_a_new_account: Create a new account | |||
create_promotion_code: Create Promotion Code |
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.
I think we should use the same capitalization we use on the other translations
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.
Agree !
I was using the same as in
solidus/core/config/locales/en.yml
Line 1203 in f265506
download_promotion_code_list: Download Code List |
Do you want me do modify both of them to be more like the rest of the translations ?
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.
Yes. Thanks
@kennyadsl yes I agree for the UI but I thought that there was a reason to not use the plural form in solidus/core/config/locales/en.yml Line 1203 in f265506
For the variables part, I don't understand where you want me to pluralize |
@stem a rebase with latest master should fix the build issues. |
The old name wasn't that explicit about what it is testing
Let users explicitly create a new code on an existing promotion, without checking if it's a "single" or "multiple" promotion type because it's already possible do switch from a "single" to "multiple" using the `Spree::PromotionCodeBatch` creation process. This let the user creates a new code without using the "batch" method so that it can explicitly choose a new code without using random suffixes.
`.full_messages.to_sentence` will do the same as `.full_messages.join(', ')` but uses an "and" as last divider
1909a1c
to
e3866a2
Compare
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.
Left a question, I think this PR is ok as is, just curious
|
||
def new | ||
@promotion = Spree::Promotion.accessible_by(current_ability, :read).find(params[:promotion_id]) | ||
@promotion_code = @promotion.promotion_codes.new |
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.
just wondering why we are not using ActiveRecord build
here. Is there a specific reason? I think you can even do @promotion.build_promotion_code
right?
Same in the create method where it's not a conventional create. I'm taking a look at scaffolded rails controller templates.
Let me know!
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.
@promotion.build_promotion_code
does not seems to exists :
irb(main):009:0> promotion = Spree::Promotion.last
irb(main):010:0> promotion.build_promotion_code
Traceback (most recent call last):
1: from (irb):10
NoMethodError (undefined method `build_promotion_code' for #<Spree::Promotion:0x00007f625b3b2e18>)
Did you mean? build_promotion_category
And new
or build
return the same object :
irb(main):011:0> promotion.promotion_codes.build
=> #<Spree::PromotionCode id: nil, promotion_id: 65, value: nil, created_at: nil, updated_at: nil, promotion_code_batch_id: nil>
irb(main):012:0> promotion.promotion_codes.new
=> #<Spree::PromotionCode id: nil, promotion_id: 65, value: nil, created_at: nil, updated_at: nil, promotion_code_batch_id: nil>
I've switched to build
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.
Thanks!
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.
Looks great, thanks!
@stem can you please rerun failing specs on CircleCI? |
@kennyadsl done and it's ✅ |
Thanks! |
Hi folks,
@epicery we use a lot the promotion system, more particularly PromotionCode instead of PromotionCodeBatch.
Maybe we overlooked something inside the PromotionCodeBatch, but we really don't want our PromotionCode to have a suffix when we're adding one on an existing Promotion
First, we were manually creating PromotionCode objects inside an existing Promotion using the console, but it kind of suc**
Lately, we've developed the few missing parts that enable a backend user to autonomously create these new PromotionCode.
I though it might interest other people, so I made it more generic and made this PR.
Pls, let me know what you think about it.