Skip to content
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

Agent search by postal code + filters #25

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

Saggre
Copy link

@Saggre Saggre commented Feb 2, 2022

Add the following filters for modifying agent search address:

  • smart_send_agent_search_country
  • smart_send_agent_search_postal_code
  • smart_send_agent_search_city
  • smart_send_agent_search_street

and allow searching for agents with just country and postcode when no street is provided.

My use case for this is that some payment gateways like Klarna (widely used in many countries that PostNord also operates in), only dynamically update shipping country and postcode at checkout and leave city and street address blank. This solution should work out of the box with Klarna and gives more flexibility to users.

@bilfeldt
Copy link
Member

bilfeldt commented Feb 3, 2022

@Saggre Thanks for the PR - the issue regarding Klarna is clearly worth addressing.

I suggest that instead of implementing multiple filters, then a single filter is added like so:

$agentSearchAddress = apply_filters('smart_send_agent_search_address', [
    'country' => empty($_POST['s_country']) ? null : wc_clean($_POST['s_country']),
    'postal_code' => empty($_POST['s_postcode']) ? null : wc_clean($_POST['s_postcode']),
    'city' => empty($_POST['s_city']) ? null : wc_clean($_POST['s_city']),
    'address' => empty($_POST['s_address']) ? null : wc_clean($_POST['s_address']),
]);

let me know if this would cover the use-case you have in mind?

@Saggre
Copy link
Author

Saggre commented Feb 4, 2022

@bilfeldt Yeah, this will work as well as long as city and street are allowed to be empty after the filter (and postal code search will be used as a fallback)

if(empty($street) || strlen($street) < 5){
  $ss_agents = $this->find_closest_agents_by_postal_code($carrier, $country, $postal_code);
}else{
  $ss_agents = $this->find_closest_agents_by_address($carrier, $country, $postal_code, $city, $street);
}

@bilfeldt
Copy link
Member

bilfeldt commented Feb 6, 2022

@Saggre I have made the proposed changes now. Do you agree this will solve the challenges you have had?

@Saggre
Copy link
Author

Saggre commented Feb 7, 2022

@bilfeldt Yeah this will solve our problem. I just removed an extra comma

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.

2 participants