Skip to content
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

Merged
merged 9 commits into from
Nov 10, 2018

Conversation

stem
Copy link
Contributor

@stem stem commented Sep 27, 2018

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.

Copy link
Member

@kennyadsl kennyadsl left a 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?

Copy link
Member

@tvdeyen tvdeyen left a 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 %>
Copy link
Member

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(', ')
Copy link
Member

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 :)

Copy link
Contributor Author

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 !

@@ -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
Copy link
Member

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

Copy link
Contributor Author

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

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 ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Thanks

@stem
Copy link
Contributor Author

stem commented Oct 20, 2018

@kennyadsl yes I agree for the UI but I thought that there was a reason to not use the plural form in

download_promotion_code_list: Download Code List

For the variables part, I don't understand where you want me to pluralize @promotion_code. Most of them are for a single code as it lets the user create a new code and the only one I find for multiple codes is already in its plural form

@tvdeyen
Copy link
Member

tvdeyen commented Oct 20, 2018

@stem a rebase with latest master should fix the build issues.

stem added 8 commits October 21, 2018 10:32
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
@stem stem force-pushed the create-promotion-code branch from 1909a1c to e3866a2 Compare October 21, 2018 08:34
Copy link
Member

@kennyadsl kennyadsl left a 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
Copy link
Member

@kennyadsl kennyadsl Oct 31, 2018

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!

Copy link
Contributor Author

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

Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Copy link
Contributor

@ericsaupe ericsaupe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks!

@kennyadsl
Copy link
Member

@stem can you please rerun failing specs on CircleCI?

@stem
Copy link
Contributor Author

stem commented Nov 10, 2018

@kennyadsl done and it's ✅

@kennyadsl kennyadsl merged commit 5fb0c18 into solidusio:master Nov 10, 2018
@kennyadsl
Copy link
Member

Thanks!

@stem stem deleted the create-promotion-code branch April 28, 2020 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants