[REF] Move wrangling of Front end form contribution param for autoRenew back to form #15927
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
Refactoring towards cleaning up processAmount function
Before
$component is a param that is code for 'add autoRenew elements to the array'
After
$component is no longer a param. The places where this is needed are now calculated on the form
Technical Details
The processAmount function is really problematic because it's trying to do several disparate things & is called from
all over the place with unclear intent. From looking at it I see it does a few things. It reformats line items,
it does some obscure & likely flawed filtering, it generates a total cost & a tax cost and it generates a very
specifically formatted array of autoreneal properties,
The way I see this going is
have a wrapper function that just returns these & we might see that is most of what is needed
to entirely remove that from here are it makes so much less than no sense.
It worth noting all of this does very little intensive work - a DB lookup or 2 that could be cached & an iteration
through a very small array so it would be fine to have 3 functions -
that each go through the same process of generating a formatted array from price_x => 5 etc rather than trying
to pass the array around for 'performance' or to 'save work'.
From previous refactorings I would suggest we add an Order class such as eileenmcnaughton@6d60f4f where by you set the price fields
& then you can call 'getLineItems' - but that is a few steps after this....
Comments
@seamuslee001 @monishdeb @mattwire I'm hoping some combination of you can help work through this with me. I think that once we have a function to getTotalAmount from a set of price set params we'll be in a much better place to clean up a bunch of code. The confusion around passing things like line item by reference & why we have to pass in 'fields' & where that comes from has been holding us back IMHO