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

Enable custom shipping promotions via config.spree.promotions.shipping_actions #2135

Merged

Conversation

jordan-brough
Copy link
Contributor

This updates the shipping promotion handler so that it will look for promotion
action types via Rails.application.config.spree.promotions.shipping_actions,
instead of only looking for actions of type
Spree::Promotion::Actions::FreeShipping.

This should allow applications to create their own shipping promotion actions.

…g_actions

This updates the shipping promotion handler so that it will look for promotion
action types via `Rails.application.config.spree.promotions.shipping_actions`,
instead of only looking for actions of type
`Spree::Promotion::Actions::FreeShipping`.

This should allow applications to create their own shipping promotion actions.
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.

It makes sense to me, I've only submitted a question.
Maybe it also needs a Changelog entry with some note about how to add another shipping_actions to stores?

@@ -105,6 +105,12 @@ class Engine < ::Rails::Engine
]
end

initializer 'spree.promo.register.promotions.shipping_actions', before: :load_config_initializers do |app|
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@jordan-brough jordan-brough Aug 8, 2017

Choose a reason for hiding this comment

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

At the moment we do, unfortunately. We could try to avoid the duplication by combining the contents of these two lists when reading the values, but I wonder if you might want to remove a shipping promotion action from promotions.actions so that it doesn't show up in the admin UI, but you'd want to keep it in promotions.shipping_actions so that existing orders & promotions would continue to work?

Very open to ideas on this.

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 the clarification. I have no good ideas other than the one you proposed. Anyway at the moment I can't figure out a scenario when removing something from that actions list would break existing orders and promotions. I mean, isn't the same if we remove another action from that actions list, like Spree::Promotion::Actions::CreateAdjustment?

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 here's the case that I'm thinking of:

  • Developer creates a OurGreatShippingAction promo action and adds it to the list
  • Admin creates a promo using that action
  • The store decides not to do any more of those promo actions and a developer removes the OurGreatShippingAction from the list so it doesn't show up in the admin for new promos anymore.
  • However, if this also removes the action from Spree::PromotionHandler::Shipping#active_shipping_promotions then that means that the existing promo will cease to work as well.

So we need 2 lists -- one list that indicates what actions should be available in the admin, and one list that indicates what promotions to consider in Spree::PromotionHandler::Shipping#active_shipping_promotions.

The difference from other promo actions is that other promo actions don't need a special invocation to work correctly -- i.e. other actions don't need a before_transition from: :delivery, do: :apply_shipping_promotions in order to work correctly.

Copy link
Contributor Author

@jordan-brough jordan-brough Aug 24, 2017

Choose a reason for hiding this comment

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

A couple other possibilities:

A) Just decide we don't care about the scenario above

B) Figure out how to make shipping promotions work correctly without the before_transition from: :delivery, do: :apply_shipping_promotions transition (i.e. eliminate the need to even have a Spree::PromotionHandler::Shipping class at all).

C) Think of another way to identify Shipping promo actions in Spree::PromotionHandler::Shipping. Perhaps all Shipping promo actions must inherit from a base class? Or have a is_shipping field on the action?

It might be worth just going w/ what's in this PR and iterating on it?

Copy link
Member

Choose a reason for hiding this comment

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

Got it, thanks for taking the time to explain this better. IMO it's reasonable to care about the above scenario. As you said, there could be promotions that would stop working if a developer removes that class from the list before all promos with that actions are expired or disabled.

I'm fine merging and iterating on this, maybe with time we'll be able to simplify this logic a lot since it seems like we just want to automatically try to apply some promotions after a specific checkout step (probably I'm too optimistic and it's much more complex than this 😄 ).

@@ -1,7 +1,7 @@
module Spree
module PromotionHandler
# Used for activating promotions with shipping rules
class FreeShipping
class Shipping
Copy link
Contributor

@jhawthorn jhawthorn Aug 23, 2017

Choose a reason for hiding this comment

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

We probably want to keep Spree::PromotionHandler::FreeShipping as a deprecated constant.

This is probably a good case for ActiveSupport::Deprecation::DeprecatedConstantProxy. I believe we re-add a promotion_handler/free_shipping.rb with

module Spree
  module PromotionHandler
    FreeShipping =
      ActiveSupport::Deprecation::DeprecatedConstantProxy.new('FreeShipping', 'Shipping', Spree::Deprecation)
  end
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jhawthorn nice, I hadn't seen that before. Added.

Copy link
Contributor

@jhawthorn jhawthorn left a comment

Choose a reason for hiding this comment

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

LGTM

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.

👍

@jordan-brough jordan-brough merged commit 5d022c9 into solidusio:master Aug 29, 2017
@jordan-brough jordan-brough deleted the enable-more-shipping-promos branch August 29, 2017 19:08
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.

3 participants