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

Reset Product Collection Pagination When Filtering #45693

Merged
merged 5 commits into from Mar 21, 2024

Conversation

ObliviousHarmony
Copy link
Contributor

Submission Review Guidelines:

Changes proposed in this Pull Request:

While it's true that the Product Collection block uses client-side refreshes, it is still vulnerable to the 404 thrown when a page does not exist. When the filters are changed while the block is looking at a page that no longer exists it will do a full page reload to a 404 page. This pull request adds a page reset so that it will return to the first page whenever the filters are changed.

Closes #45644.

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

  1. Add a Product Collection block and various filters to the page. Make sure you have more than one page of products by default.
  2. Navigate to a different page and adjust the filters.
  3. When you change the filter it should navigate back to the first page.

Changelog entry

  • Automatically create a changelog entry from the details below.

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Comment

Since we can't be sure that a page exists once the filters have been
changed we should reset the page when they do.
@ObliviousHarmony ObliviousHarmony added block-type: filter blocks Issues related to all of the filter blocks. block: product collection Issues related to the Product Collection block labels Mar 18, 2024
@woocommercebot woocommercebot requested review from a team and imanish003 and removed request for a team March 18, 2024 22:21
@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Mar 18, 2024
Copy link
Contributor

Hi @imanish003,

Apart from reviewing the code changes, please make sure to review the testing instructions as well.

You can follow this guide to find out what good testing instructions should look like:
https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

Copy link
Contributor

github-actions bot commented Mar 18, 2024

Test Results Summary

Commit SHA: 85f3dcd

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests25900202610m 38s
E2E Tests00036303630m 0s

To view the full API test report, click here.
To view the full E2E test report, click here.
To view all test reports, visit the WooCommerce Test Reports Dashboard.

Copy link
Contributor

@imanish003 imanish003 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @ObliviousHarmony 👋🏻

I'm a bit puzzled about the check for paged in the href. Shouldn't we apply the same logic as in woocommerce/woocommerce-blocks#9952 that was used for the older filter blocks?

For instance, on the 3rd page, the URL format is /155-2/?query-0-page=3, not containing a paged key. I've run some tests, and it seems the changes aren't functioning as anticipated due to the absence of a paged key in the URL. Could I be overlooking something here?

@ObliviousHarmony
Copy link
Contributor Author

Very interesting @imanish003!

This seems to be a consequence of the Permalink setting I had configured.

  • Plain Permalinks: The paged query parameter is used on pages such as post_type=product and product_cat=clothing.
  • Pretty Permalinks: The URL contains a /page/{page} path for pages such as post_type=product and product_cat=clothing.

In both cases pages with collection blocks use the the query-{id}-page query parameter. I've gone ahead and made changes to the pull request to accommodate these different methods of pagination.

@imanish003
Copy link
Contributor

This seems to be a consequence of the Permalink setting I had configured.

  • Plain Permalinks: The paged query parameter is used on pages such as post_type=product and product_cat=clothing.
  • Pretty Permalinks: The URL contains a /page/{page} path for pages such as post_type=product and product_cat=clothing.

In both cases pages with collection blocks use the the query-{id}-page query parameter. I've gone ahead and made changes to the pull request to accommodate these different methods of pagination.

TIL, I wasn't aware that Plain Permalink use paged query parameter. Looks like we will need add same logic here too. Can you please add a logic there as well. Because I verified that it's resuting into 404 page with old filters 🙂

@ObliviousHarmony
Copy link
Contributor Author

Alright @imanish003, I updated the logic for the legacy filters too 😄

Copy link
Contributor

@imanish003 imanish003 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright @imanish003, I updated the logic for the legacy filters too 😄

Thank you so much! I truly appreciate your effort. 🙏🏻 I've tested the changes, and everything is working perfectly. 🚀

@ObliviousHarmony ObliviousHarmony merged commit 5002b62 into trunk Mar 21, 2024
48 checks passed
@ObliviousHarmony ObliviousHarmony deleted the fix/45644-filter-page-reset branch March 21, 2024 21:03
@github-actions github-actions bot added this to the 8.8.0 milestone Mar 21, 2024
@github-actions github-actions bot added the needs: analysis Indicates if the PR requires a PR testing scrub session. label Mar 21, 2024
@veljkho veljkho added needs: external testing Indicates if the PR requires further testing conducted by testers external to the development team. status: analysis complete Indicates if a PR has been analysed by Solaris and removed needs: analysis Indicates if the PR requires a PR testing scrub session. labels Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
block: product collection Issues related to the Product Collection block block-type: filter blocks Issues related to all of the filter blocks. needs: external testing Indicates if the PR requires further testing conducted by testers external to the development team. plugin: woocommerce Issues related to the WooCommerce Core plugin. status: analysis complete Indicates if a PR has been analysed by Solaris team: Kirigami & Origami
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Product Collection 404s When Page Count Changes
3 participants