Add fallback logic to Address and Contact flags #39
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.
implements flag fallbacks for Addresses as described in #32
Currently no flag fallback support
By using the current getters like
$model->getBillingAddress()the return is way too strict and in many cases we will get a null return. But there might be a primary / shipping / any other address attached to the model that could also be used by the application.In theses cases there should be fallback.
The solution
Besides the existing methods like
getPrimaryAddress,getBillingAddress, etc. I have added a simplegetAddressmethod. This method takes 3 arguments:type: string- the flag to search for, e.g. billingtype: string- ASC / DESCtype: boolean- using strict mode, this ensures that the current methods still behave the same way.getAddresswill first check if addresses are existing on the model and if so returns the first / last address depending on the$directionparam.If no address is found to this point it will create a fallback order based on
config('lecturize.addresses.flags')and returns the next best result. If no address matches any result in this order we fallback to either the first or last address with any or no flag.Contacts do not have any methods to query by flag
While we could write a query ourselfes like:
it would be much more convenient to use the same methods known from the Addresses.
So contacts can be now also be queried by
$model->getContact($flag, $direction, $strict)