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

Feature/post type enhancements #1689

Merged
merged 11 commits into from
Jun 28, 2021
Merged

Conversation

mustafauysal
Copy link
Contributor

Description of the Change

This PR tries to address two problems, related to post_type support.

  • In order to restrict the autosuggest query by post_type. I have added a control that checks [name="post_type"] input and applying particular post_type to query. Therefore, we can show only the "products" for WooCommerce's own search bar.

  • I have changed facet's query build logic a bit, now ep_facet_allowed_query_args allows to extend allowed query parameters. post_type and s are supported by default.

Alternate Designs

  • Perhaps, we can add a new flag item for Autosuggest's localize script to understand that request made from a product page

Benefits

Improving post_type support without adding custom code

Possible Drawbacks

Verification Process

[Autosuggest]

  • Install WooCommerce
  • Activate EP's Woo and Autosuggest feature
  • Visit /shop/ page
  • Enter the search query and see the suggested results

[Facets]

  • Make a WooCommerce product search
  • Check facet's widgets have post_type on the target url

Screenshot

(first input Woo's search, second is generic)

Screen Shot 2020-03-05 at 15 49 25

Checklist:

  • I have read the CONTRIBUTING document.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests passed.

Applicable Issues

#1687, #1684

Changelog Entry

  • Autosuggest: respects the [name="post_type"] input in the same form.
  • Additional query parameters can register through ep_facet_allowed_query_args for facets

@felipeelia felipeelia self-assigned this Jul 21, 2020
@JakePT JakePT self-assigned this Apr 14, 2021
@JakePT JakePT force-pushed the feature/1687-post-type-enhancements branch from fa6c668 to 9ef4606 Compare April 15, 2021 10:20
@JakePT
Copy link
Contributor

JakePT commented Apr 15, 2021

I have update the PR so that the JavaScript changes to autosuggest have been applied to an up to date version of that script, and don't use jQuery.

I also updated the JavaScript to support different possible post type inputs in the search form, including:

  • a single hidden input, as used by WooComerce.
  • multiple hidden post type inputs that use post_type[] to query multiple post types.
  • post type checkboxes using post_type[].
  • post type radio buttons that use post_type.
  • post type radio buttons that use post_type, with a hidden post_type input as a default fallback.

All of those are possible with searchform.php, so this version ensures that the autosuggest behaviour matches the behaviour of submitting the form.

I used a couple FormData methods for this which aren't supported in IE, like getAll(), and I'm not certain if the build process for this plugin will handle IE11 support for that, so that will need to be tested.

This probably also addresses #2135.

@oscarssanchez
Copy link
Contributor

@JakePT can you let me know how the post type feature is planned to work? I was thinking it should add a post type support in the facet widget but seems it is not the case.

@JakePT
Copy link
Contributor

JakePT commented Apr 17, 2021

@JakePT can you let me know how the post type feature is planned to work? I was thinking it should add a post type support in the facet widget but seems it is not the case.

It just limits autosuggest results to whichever post type is being searched by the search form. The main example is WooCommerce, which uses a hidden post_type field in the form to search products. This picks up on that so that autosuggest only shows products.

@mckdemps mckdemps added this to the 3.6.0 milestone Jun 15, 2021
@oscarssanchez oscarssanchez self-assigned this Jun 15, 2021
@felipeelia
Copy link
Member

felipeelia commented Jun 15, 2021

Let's please adjust the @since tag before merging @JakePT and @oscarssanchez

@JakePT
Copy link
Contributor

JakePT commented Jun 25, 2021

Let's please adjust the @since tag before merging @JakePT and @oscarssanchez

Done @felipeelia

JakePT
JakePT previously approved these changes Jun 25, 2021
@felipeelia felipeelia merged commit 3c3ff85 into develop Jun 28, 2021
@felipeelia felipeelia deleted the feature/1687-post-type-enhancements branch June 28, 2021 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Intelligently detect product search fields and restrict results in Autosuggest
6 participants