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

Disable codes on apply automatically promo #3502

Merged
merged 5 commits into from
Apr 21, 2020
Merged

Disable codes on apply automatically promo #3502

merged 5 commits into from
Apr 21, 2020

Conversation

MassimilianoLattanzio
Copy link
Contributor

Description
Disabled creation of promotion code if a promotion applies automatically to all orders. Managed also old "apply-automatically" promotions with and without associated promotion codes.

Solve #3472

Checklist:

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I have updated Guides and README accordingly to this change (if needed)
  • I have added tests to cover this change (if needed)
  • I have attached screenshots to this PR for visual changes (if needed)

core/app/models/spree/order_promotion.rb Outdated Show resolved Hide resolved
core/app/models/spree/adjustment.rb Outdated Show resolved Hide resolved
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! I left some notes about things that should be improved and also, can we add a spec to test that auto applying a promotion works when there's a promotion with both codes and auto_apply_promotion set? I suspect it should work but I don't think it's currently covered.

return unless apply_automatically

errors.add(:apply_automatically, :disallowed_with_code) if codes.any?
Copy link
Member

Choose a reason for hiding this comment

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

Can you please expand a little bit more in its commit description? I'm not sure to get why this is needed.

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've added a short message to explain why this commit is needed, let me know if is clear enough

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kennyadsl did you read the new commit message? Let me know what do you think

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for updating it, I think the second part can be rewritten as:

Also, this improves backward compatibility since if we keep validating
against promotions with codes as well, it will be impossible to update 
existing apply-auto promotions that already have a code associated.

While in the first part I still don't get this sentence:

Since promotions creation is a two-step process and promo codes
are added in the second step, the validation have to be there.

Why do you say that the validation has to be there if we are removing it in this commit?

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 modified the commit description to explain why we need to remove that validation and move it in the promo code creation step, let me know if now is ok

core/config/locales/en.yml Outdated Show resolved Hide resolved
@@ -37,6 +38,10 @@ def usage_limit
promotion.per_code_usage_limit
end

def promotion_not_apply_automatically
errors.add(:base, I18n.t('spree.errors.messages.could_not_create_promotion_code_on_apply_automatically_promotion')) if promotion.apply_automatically
Copy link
Member

Choose a reason for hiding this comment

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

There's no need to use a generic key here, you can have the same result by using:

errors.add(:base, :disallaowed_with_apply_automatically) if promotion.apply_automatically

and moving the translation into:

en.activerecord.errors.models.spree/promotion_code.attributes.base.disallaowed_with_apply_automatically

(this probably needs a double check on documentation 🙂)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean the solidus developers guide? In that guide there isn't any section about the promotion code, maybe I can create a new page for the promotion codes.

Copy link
Member

Choose a reason for hiding this comment

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

this probably needs a double check on documentation

No, I meant in the Rails documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, my fault, I misunderstood 🙂

@kennyadsl
Copy link
Member

@MassimilianoLattanzio can you please fixup some commits together where it makes sense?

@MassimilianoLattanzio
Copy link
Contributor Author

@MassimilianoLattanzio can you please fixup some commits together where it makes sense?

Done 👍

Otherwise it will be possible to create useless promotions codes on promotions
that apply automatically to all orders
Deleted useless button/route in admin UI to create new
promotion code if a promotion applies automatically.
To explain that if promotion is created with apply automatically option,
promo codes creation will be disabled for that promotion.
This is important for backward compatibility since if we keep validating
against promotions with codes as well, it will be impossible to update
existing apply-auto promotions that already have a code associated.

Since promotion codes are created in a second step, the creation validation
have to be done in that step.
That requirement generate an error adding any product to
cart when exist a promotion that apply automatically without any code.
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, @MassimilianoLattanzio! 🎉

@kennyadsl kennyadsl added Needs Core Team Review changelog:solidus_backend Changes to the solidus_backend gem labels Apr 21, 2020
@aldesantis aldesantis merged commit 4e497d9 into solidusio:master Apr 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:solidus_backend Changes to the solidus_backend gem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants