Skip to content

Conversation

@bfiessinger
Copy link
Contributor

@bfiessinger bfiessinger commented May 30, 2023

implements flag fallbacks for Addresses as described in #32

How does it work?

using the magic __call method we are searching the flags defined in config and eventually use them to retrieve the addresses.
We can still call methods like getShippingAddress and getPrimaryAddress, but instead of using a dedicated method for this we now can utilize the getAddressByFlag method which walks recursively through the flags array defined in the config.

So if the flags array looks like this:

'flags' => ['public', 'primary', 'billing', 'shipping'],

and we are calling getBillingAddress the new implementation would walk up the array until it reaches the public flag if it cannot find any addresses earlier. It would not check for the shipping flag in this step.

After trying all flags and if there is still no address found based on the direction parameter the new implementation would either return the first or the last attached address as a last fallback step.

This ensures to return an address object in almost every situation.

@bfiessinger bfiessinger changed the title Add fallback logic to address flags (closes #32) Add fallback logic to address flags (closes https://github.com/Lecturize/Laravel-Addresses/issues/32) May 30, 2023
@bfiessinger bfiessinger changed the title Add fallback logic to address flags (closes https://github.com/Lecturize/Laravel-Addresses/issues/32) Add fallback logic to address flags (closes #32) May 30, 2023
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.

1 participant