eventespresso / eea-attendee-mover

Addon for EE4+
GNU General Public License v2.0
0 stars 2 forks source link

Add 'Re-apply promotions' option to the attendee mover confirmation step #15

Closed Pebblo closed 4 years ago

Pebblo commented 4 years ago

I don't consider this finished yet, but I mentioned it in Slack and Brent offered to take a look and give feedback so here goes. I'll add details in this PR as the other one related to this in core is a single change to add a method to the service and its for functionality in this add-on.

Most of this seems fine, adding the option etc I don't have a problem with, however, the call to the new copyPromotionLineItems() method feels a little fragile and I'm not sure what the best way to avoid/reduce that is.

The call relies on the promotions add-on and I know I could just use class_exists() to make sure the promotions add-on is available before running it (including doing so within the method itself) or even move that method away from using functions in the promotions add-on directly but I get the feeling the service should be added from within the promotions add-on itself rather than patching it into core, right?

I don't know how the best way to go about doing that so any pointers appreciated :)

Would I need to add dependency injection to the promotions add-on and add a /domain/services/line_items/ service for example or something completely different?

Problem this Pull Request solves

It applies the promotion set on the 'original' registration to the 'new' one, without incrementing the 'usage' value of that add-on (as the original usage would have done so).

The changes in this specific PR don't do much other than add the visuals for that and the option not to apply promotions.

How has this been tested

Register onto an event and use a promotion during checkout for whatever value/percentage. Finalize.

Move the registration onto anther ticket/event and select to re-apply promotions, the 'new' registration should have the promotion applied.

(Note this intentionally skips any/all checks for promotion being valid etc and just applies it)

Checklist

tn3rb commented 4 years ago

everything looks great so far well... ...except for the things that I know you copied from code I wrote that I would likely do differently now 😞

Now with regards to simply hardcoding content specific to one add-on into code for another add-on (or into core), that's a big nope, but is also relatively easy to fix. We just need to add some filters and actions here and there. That's not a big deal because users would have to download and update to the new versions that contain your new hardcoded changes, so they may as well do so with the versions that just have some hooks added.

So this is what we do:

And that's it... at least for the code in this PR. I realize there's some other code that's not part of this PR (like whatever's in copyPromotionLineItems()) but I can't really comment on that without seeing any of it.

re:

Would I need to add dependency injection to the promotions add-on and add a /domain/services/line_items/ service for example or something completely different?

ya... really hard to say without seeing what you are trying to do.

Dependency Injection is simply the preferred way to make class A available to class B because class A's logic is required for class B to function. So if you create a class in the promotions add-on that depends on another class (or modify an existing one and add a dependency), then this is what you need to do:

re:

a /domain/services/line_items/ service

Anyways, hope that all helps. Do not hesitate to hit me up in chat to explain things or pass this back with more questions.

One last point, when you create a PR, there is an option to designate it as a Work In Progress PR which means it will not allow it to be merged to it's parent branch, but still allow you to do everything else, like request code reviews. You can convert it to a real PR later on when you are ready to get serious ;)

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 4 years ago

This issue has been automatically closed because it has been stale for a significant period of time without any activity.