Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Fix handpicked product selections when a store has over 100 products. #4534

Merged
merged 3 commits into from Aug 6, 2021

Conversation

mikejolley
Copy link
Member

There was a bug in getProductsRequests for stores with large catalogs. Our search functionality gets around page limits by including all selected products in a separate request. However, because this request had a limit or 10 products, some selected products would be left out of the list. Setting per_page to 0 (unlimited) resolves this.

When trying to make sense of the bug, I refactored the withSearchedProducts HOC to TypeScript.

Fixes #4505

How to test the changes in this Pull Request:

To test this you need a catalog with > 100 products (or you can edit the code to make it require less).

  1. Add a hand picked product block to a page.
  2. Make 20 selections. You may need to search for products to have more results appear.
  3. Save and reload the page.
  4. Confirm 20 selections remain.

Changelog

Fix handpicked product selections when a store has over 100 products.

@mikejolley mikejolley self-assigned this Aug 3, 2021
@mikejolley mikejolley requested a review from a team as a code owner August 3, 2021 15:22
@mikejolley mikejolley requested review from ralucaStan and removed request for a team August 3, 2021 15:22
@github-actions
Copy link
Contributor

github-actions bot commented Aug 3, 2021

Size Change: -390 B (0%)

Total Size: 1.06 MB

Filename Size Change
build/all-products.js 37.1 kB -182 B (0%)
build/all-reviews.js 9.61 kB +8 B (0%)
build/atomic-block-components/add-to-cart--atomic-block-components/button--atomic-block-components/image---a7e2bb9b.js 2.56 kB -3 B (0%)
build/atomic-block-components/add-to-cart--atomic-block-components/button.js 1.82 kB -3 B (0%)
build/atomic-block-components/add-to-cart.js 7.73 kB -4 B (0%)
build/atomic-block-components/price.js 2.11 kB +2 B (0%)
build/atomic-block-components/rating.js 567 B -1 B (0%)
build/atomic-block-components/sale-badge.js 868 B +1 B (0%)
build/atomic-block-components/sku.js 393 B +1 B (0%)
build/atomic-block-components/tag-list.js 471 B +1 B (0%)
build/atomic-block-components/title.js 1.29 kB +3 B (0%)
build/attribute-filter.js 11.9 kB -1 B (0%)
build/cart.js 45.6 kB +16 B (0%)
build/checkout-blocks/sample.js 173 B -1 B (-1%)
build/checkout-i2.js 48.4 kB +8 B (0%)
build/checkout.js 48.6 kB +23 B (0%)
build/featured-category.js 7.4 kB +7 B (0%)
build/featured-product.js 9.52 kB -35 B (0%)
build/handpicked-products.js 6.37 kB -185 B (-3%)
build/price-filter.js 9.6 kB +4 B (0%)
build/product-best-sellers.js 6.74 kB +7 B (0%)
build/product-categories.js 3.38 kB +1 B (0%)
build/product-category.js 7.6 kB +7 B (0%)
build/product-new.js 6.89 kB +4 B (0%)
build/product-on-sale.js 7.23 kB +6 B (0%)
build/product-search.js 2.68 kB +1 B (0%)
build/product-tag.js 6.71 kB +7 B (0%)
build/product-top-rated.js 6.86 kB +6 B (0%)
build/products-by-attribute.js 7.82 kB +4 B (0%)
build/reviews-by-category.js 11.6 kB +3 B (0%)
build/reviews-by-product.js 13.1 kB -48 B (0%)
build/single-product.js 9.8 kB -43 B (0%)
build/wc-blocks-vendors.js 235 kB -4 B (0%)
ℹ️ View Unchanged
Filename Size
build/active-filters-frontend.js 8.27 kB
build/active-filters.js 7.84 kB
build/all-products-frontend.js 23 kB
build/atomic-block-components/add-to-cart--atomic-block-components/image--atomic-block-components/title.js 334 B
build/atomic-block-components/add-to-cart-frontend.js 8.65 kB
build/atomic-block-components/button-frontend.js 1.74 kB
build/atomic-block-components/button.js 875 B
build/atomic-block-components/category-list-frontend.js 468 B
build/atomic-block-components/category-list.js 476 B
build/atomic-block-components/image-frontend.js 1.88 kB
build/atomic-block-components/image.js 1.35 kB
build/atomic-block-components/price-frontend.js 2.09 kB
build/atomic-block-components/rating-frontend.js 561 B
build/atomic-block-components/sale-badge-frontend.js 857 B
build/atomic-block-components/sku-frontend.js 388 B
build/atomic-block-components/stock-indicator-frontend.js 609 B
build/atomic-block-components/stock-indicator.js 612 B
build/atomic-block-components/summary-frontend.js 907 B
build/atomic-block-components/summary.js 912 B
build/atomic-block-components/tag-list-frontend.js 466 B
build/atomic-block-components/title-frontend.js 1.43 kB
build/attribute-filter-frontend.js 17.9 kB
build/blocks-checkout.js 21.2 kB
build/cart-frontend.js 77.8 kB
build/checkout-frontend.js 82 kB
build/checkout-i2-frontend.js 51.7 kB
build/price-filter-frontend.js 14.3 kB
build/price-format.js 1.37 kB
build/reviews-frontend.js 9.22 kB
build/single-product-frontend.js 25.7 kB
build/vendors--atomic-block-components/price-frontend.js 5.71 kB
build/wc-blocks-data.js 10.8 kB
build/wc-blocks-editor-style-rtl.css 15.4 kB
build/wc-blocks-editor-style.css 15.4 kB
build/wc-blocks-google-analytics.js 1.99 kB
build/wc-blocks-middleware.js 1.48 kB
build/wc-blocks-registry.js 2.74 kB
build/wc-blocks-shared-context.js 1.54 kB
build/wc-blocks-shared-hocs.js 1.75 kB
build/wc-blocks-style-rtl.css 19.8 kB
build/wc-blocks-style.css 19.8 kB
build/wc-blocks-vendors-style-rtl.css 1.05 kB
build/wc-blocks-vendors-style.css 1.05 kB
build/wc-blocks.js 3.51 kB
build/wc-payment-method-bacs.js 812 B
build/wc-payment-method-cheque.js 807 B
build/wc-payment-method-cod.js 903 B
build/wc-payment-method-paypal.js 844 B
build/wc-payment-method-stripe.js 12.3 kB
build/wc-settings.js 2.92 kB

compressed-size-action

@@ -39,6 +39,7 @@ const getProductsRequests = ( {
addQueryArgs( '/wc/store/products', {
catalog_visibility: 'any',
include: selected,
per_page: 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we won't need the comment above anymore:

// If we have a large catalog, we might not get all selected products in the first page

Copy link
Member Author

Choose a reason for hiding this comment

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

It's still relevant I think. With smaller catalogs the selections are guaranteed to be returned with the other results. In this use case, our first query might be missing selected things.

@mikejolley
Copy link
Member Author

Thanks for the review 🥳

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hand-Picked Products block limited to 11 products
2 participants