-
-
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
Extendable adjustable updater #499
Conversation
Hi @adaddeo. Thank you for the PR. I'm not too sure about this. This is a lot of code and complexity for a level of indirection that doesn't seem to abstract anything that cleanly. Can I ask what exactly you were looking for in terms of extensibility? Maybe there is a simpler way we can achieve the functionality you're looking for. |
That'd be great. We want the ability to create new kinds of adjustment sources that maintain their own total, add them to adjustable items, and have them recalculate appropriately during updates, just like tax_rates and shipments. Example: |
@jhawthorn did that make sense or is there any additional information I can provide you with? |
If I knew the specific use case it would be helpful. Could we accomplish the same thing by applying all non-tax, non-calcellation adjustments instead of just promotion adjustments before doing tax? |
We have two uses: one is a bulk discount extension that can be assigned to products (similarly to tax categories/rates) and configured to stack on promotions or not; the other is an extension to line items that adds optional customizations (think cafepress.com), line items become unique based on a variant and a customization, with some customizations adding additional fees based on quantity. These extensions work extremely well for us and the existing adjustment logic is perfect for them. The only negative is having to monkey patch Applying all non-tax, non-cancellation adjustments instead of just promotion adjustments would work. My PR included a bunch of name changes that I thought made more sense, but I understand the hesitation of making changes without a ton of need/thought. The only crucial things required to open up adjustments are:
EDIT: We currently us run_hooks in Assuming that made sense, a few finer grain changes that would really make this open to extension would be an additional scope called competing_adjustments that is passed to |
@jhawthorn I know that was long, but wondering if you had anymore insight/feedback before this got stale? |
I was reading #425, using a save here rather than update columns would be a nice step in allowing extensions to add their own adjustments here. |
@adaddeo thanks so much for the attempt here, sorry we've been pretty quiet on our end. Every time we sat down to look at this closely we got distracted on other things to get 1.1 and 1.2 out the door. The approach is pretty neat but a little drastic for a single PR. @mamhoff has been attempting to fix the tax situation in a very similar way in: #685 that is more mature (as we've made him re-write it 4 or 5 times now) and we'll likely be going with that. After that is merged, if we can scale back the size of the changes into more smaller PR's I reckon we can get something in that is safely merge-able. These types of changes are definitely the direction I think we need to move in, but unfortunately with how bad the state we're starting with it has to progress in some incredibly small steps forward. |
This refactor adds some new extensibility options to adjustments.
AdjustableUpdater uses POROs to update adjustments. This allows for alternate adjustment source types to hook into the update of adjustments either before or after the taxes are calculated.
Calling
Spree::ItemAdjustments.new(adjustable).update
is equalivent to callingSpree::AdjustableUpdater.update(adjustable)
.I am looking for feedback before I go any further. Also, I am manually calling the AdjustmentsUpdaters at this point, but in the comments below how I show how I am proposing to call them.