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

Make Filter Products by Stock block compatible with PHP rendered Classic Template block #6261

Merged
merged 19 commits into from Apr 21, 2022

Conversation

gigitux
Copy link
Contributor

@gigitux gigitux commented Apr 14, 2022

This PR updates the Filter Products By Stock block to work with the Classic Template block which is PHP rendered, but also still maintains compatibility with the All Products block.

Filter Products by Stock block will only work with the PHP rendered Classic Template block if the filters are applied to the URL and the page is re-rendered. This behavior happens with the Classic Themes such as Storefront.

Fixes #6137

Technical details

I believe there is a lot of space to improve the code regarding all the blocks that filter the products.
Now, there are a lot of side effects, hard to debug, and these blocks are not performant (there are a lot of rerender :'( )

Also, As said by @dinhtungdu this approach is not really extendible when we will blockify this template.

My suggestion is to dedicate some time (in cooldown or in a dedicated project) to improve the quality of the codebase regarding the block that handles filters cc @Aljullu

Testing

Automated Tests

  • Changes in this PR are covered by Automated Tests.
    • Unit tests
    • E2E tests

Manual Testing

How to test the changes in this Pull Request:

  1. With a block theme, go to Appearance > Editor > Template > Product Catalog.
  2. Add the Filter Products by Stock block above the product grid.
  3. Be sure that you have some out stock products. Check "out of stock" on the frontend.
  4. Notice the page reloads and the list of products updates accordingly.
  5. Add a test page to your site with the All Products block, and the Filter Product by Stock block and ensure no regressions have been introduced here.

User Facing Testing

These are steps for user testing (where "user" is someone interacting with this change that is not editing any code).

  • Same as above

Changelog

Allow adding the Filter Products by Stock block to Product Catalog templates to filter products.

@gigitux gigitux self-assigned this Apr 14, 2022
@gigitux gigitux force-pushed the add/6137-filter-product-by-stock branch from 3b10e75 to 92c8b5d Compare April 14, 2022 15:55
@rubikuserbot rubikuserbot requested review from a team and dinhtungdu and removed request for a team April 14, 2022 15:57
@github-actions
Copy link
Contributor

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
stock-filter.js wp-url ⚠️

This comment was automatically generated by the ./github/compare-assets action.

1 similar comment
@github-actions
Copy link
Contributor

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
stock-filter.js wp-url ⚠️

This comment was automatically generated by the ./github/compare-assets action.

@github-actions
Copy link
Contributor

github-actions bot commented Apr 14, 2022

Size Change: +1.17 kB (0%)

Total Size: 864 kB

Filename Size Change
build/active-filters-frontend.js 5.92 kB -1 B (0%)
build/active-filters.js 6.59 kB -3 B (0%)
build/all-products-frontend.js 18.1 kB +10 B (0%)
build/all-products.js 33.5 kB +9 B (0%)
build/all-reviews.js 7.78 kB +4 B (0%)
build/attribute-filter-frontend.js 17.6 kB +69 B (0%)
build/attribute-filter.js 13.4 kB +64 B (0%)
build/cart-blocks/cart-express-payment-frontend.js 5.24 kB +1 B (0%)
build/cart-blocks/cart-items-frontend.js 299 B +1 B (0%)
build/cart-blocks/cart-line-items--mini-cart-contents-block/products-table-frontend.js 5.27 kB +2 B (0%)
build/cart-blocks/cart-line-items-frontend.js 432 B +1 B (0%)
build/cart-blocks/cart-order-summary-frontend.js 1.11 kB +2 B (0%)
build/cart-blocks/cart-totals-frontend.js 322 B +1 B (0%)
build/cart-blocks/filled-cart-frontend.js 783 B +11 B (+1%)
build/cart-blocks/order-summary-coupon-form-frontend.js 2.81 kB +2 B (0%)
build/cart-blocks/order-summary-discount-frontend.js 2.31 kB +5 B (0%)
build/cart-blocks/order-summary-shipping--checkout-blocks/order-summary-shipping-frontend.js 6.34 kB +8 B (0%)
build/cart-blocks/order-summary-shipping-frontend.js 429 B +2 B (0%)
build/cart-blocks/order-summary-subtotal-frontend.js 274 B +1 B (0%)
build/cart-blocks/proceed-to-checkout-frontend.js 1.15 kB -4 B (0%)
build/cart-frontend.js 45.5 kB +21 B (0%)
build/cart.js 44.3 kB +24 B (0%)
build/checkout-blocks/actions-frontend.js 1.41 kB +3 B (0%)
build/checkout-blocks/billing-address--checkout-blocks/shipping-address-frontend.js 4.12 kB +1 B (0%)
build/checkout-blocks/billing-address-frontend.js 892 B -1 B (0%)
build/checkout-blocks/express-payment-frontend.js 5.54 kB +1 B (0%)
build/checkout-blocks/fields-frontend.js 345 B +2 B (+1%)
build/checkout-blocks/order-note-frontend.js 1.07 kB -2 B (0%)
build/checkout-blocks/order-summary-cart-items-frontend.js 3.67 kB -3 B (0%)
build/checkout-blocks/order-summary-coupon-form-frontend.js 2.96 kB -2 B (0%)
build/checkout-blocks/order-summary-frontend.js 1.1 kB +1 B (0%)
build/checkout-blocks/order-summary-shipping-frontend.js 603 B -2 B (0%)
build/checkout-blocks/payment-frontend.js 7.84 kB +23 B (0%)
build/checkout-blocks/shipping-methods-frontend.js 4.72 kB -6 B (0%)
build/checkout-blocks/totals-frontend.js 326 B +1 B (0%)
build/checkout-frontend.js 47.7 kB +41 B (0%)
build/checkout.js 45.6 kB +43 B (0%)
build/featured-category.js 8.63 kB +1 B (0%)
build/featured-product.js 10.5 kB +1 B (0%)
build/handpicked-products.js 7.11 kB -2 B (0%)
build/mini-cart-component-frontend.js 16.6 kB -3 B (0%)
build/mini-cart-contents-block/empty-cart-frontend.js 326 B -1 B (0%)
build/mini-cart-contents-block/footer--mini-cart-contents-block/products-table-frontend.js 4.69 kB +7 B (0%)
build/mini-cart-contents-block/footer-frontend.js 5.64 kB -4 B (0%)
build/mini-cart-contents-block/items-frontend.js 225 B -1 B (0%)
build/mini-cart-contents-block/products-table-frontend.js 288 B -1 B (0%)
build/mini-cart-contents-block/title-frontend.js 366 B -1 B (0%)
build/mini-cart-contents.js 22.7 kB +9 B (0%)
build/mini-cart-frontend.js 1.72 kB +1 B (0%)
build/price-filter-frontend.js 12.4 kB +32 B (0%)
build/price-filter.js 8.43 kB +20 B (0%)
build/product-add-to-cart--product-button--product-category-list--product-image--product-price--product-r--a0326d00.js 223 B -1 B (0%)
build/product-add-to-cart-frontend.js 6.96 kB -7 B (0%)
build/product-add-to-cart.js 6.64 kB +5 B (0%)
build/product-best-sellers.js 7.38 kB -2 B (0%)
build/product-button--product-category-list--product-image--product-price--product-rating--product-sale-b--e17c7c01.js 500 B -2 B (0%)
build/product-button-frontend.js 1.84 kB +2 B (0%)
build/product-button.js 1.08 kB +1 B (0%)
build/product-categories.js 2.78 kB +3 B (0%)
build/product-category-list-frontend.js 925 B -1 B (0%)
build/product-category-list.js 500 B -1 B (0%)
build/product-category.js 8.49 kB +1 B (0%)
build/product-image.js 1.07 kB -2 B (0%)
build/product-new.js 7.68 kB +2 B (0%)
build/product-on-sale.js 7.99 kB +3 B (0%)
build/product-price-frontend.js 1.94 kB +1 B (0%)
build/product-rating.js 731 B -2 B (0%)
build/product-sale-badge.js 679 B +1 B (0%)
build/product-sku.js 380 B -1 B (0%)
build/product-stock-indicator-frontend.js 1.03 kB -1 B (0%)
build/product-summary.js 918 B -1 B (0%)
build/product-tag-list-frontend.js 919 B +1 B (0%)
build/product-tag-list.js 497 B +1 B (0%)
build/product-tag.js 7.81 kB +3 B (0%)
build/product-title-frontend.js 1.3 kB +1 B (0%)
build/product-title.js 906 B -3 B (0%)
build/product-top-rated.js 7.92 kB +2 B (0%)
build/products-by-attribute.js 8.39 kB +2 B (0%)
build/reviews-by-category.js 11.2 kB +6 B (0%)
build/reviews-by-product.js 12.3 kB +1 B (0%)
build/reviews-frontend.js 7 kB -3 B (0%)
build/single-product-frontend.js 21.5 kB -3 B (0%)
build/single-product.js 10 kB +4 B (0%)
build/stock-filter-frontend.js 6.87 kB +367 B (+6%) 🔍
build/stock-filter.js 6.92 kB +359 B (+5%) 🔍
build/vendors--cart-blocks/cart-line-items--cart-blocks/cart-order-summary--cart-blocks/order-summary-shi--c02aad66-frontend.js 5.26 kB +1 B (0%)
build/vendors--cart-blocks/order-summary-shipping--checkout-blocks/billing-address--checkout-blocks/order--decc3dc6-frontend.js 20.5 kB +2 B (0%)
build/wc-blocks-style-rtl.css 22 kB +25 B (0%)
build/wc-blocks-style.css 22 kB +23 B (0%)
build/wc-blocks-vendors.js 71.3 kB -4 B (0%)
build/wc-blocks.js 2.62 kB -1 B (0%)
ℹ️ View Unchanged
Filename Size
build/blocks-checkout.js 17.4 kB
build/cart-blocks/cart-accepted-payment-methods-frontend.js 1.16 kB
build/cart-blocks/empty-cart-frontend.js 345 B
build/cart-blocks/order-summary-fee-frontend.js 273 B
build/cart-blocks/order-summary-heading-frontend.js 454 B
build/cart-blocks/order-summary-taxes-frontend.js 433 B
build/checkout-blocks/contact-information-frontend.js 2.83 kB
build/checkout-blocks/order-summary-discount-frontend.js 2.43 kB
build/checkout-blocks/order-summary-fee-frontend.js 275 B
build/checkout-blocks/order-summary-subtotal-frontend.js 273 B
build/checkout-blocks/order-summary-taxes-frontend.js 432 B
build/checkout-blocks/shipping-address-frontend.js 996 B
build/checkout-blocks/terms-frontend.js 1.22 kB
build/legacy-template.js 2.19 kB
build/mini-cart-contents-block/filled-cart-frontend.js 230 B
build/mini-cart-contents-block/shopping-button-frontend.js 287 B
build/mini-cart.js 6.1 kB
build/price-format.js 1.19 kB
build/product-add-to-cart--product-button--product-image--product-title.js 2.65 kB
build/product-add-to-cart--product-button.js 565 B
build/product-image-frontend.js 1.84 kB
build/product-price.js 1.5 kB
build/product-rating-frontend.js 1.15 kB
build/product-sale-badge-frontend.js 1.09 kB
build/product-search.js 2.18 kB
build/product-sku-frontend.js 380 B
build/product-stock-indicator.js 621 B
build/product-summary-frontend.js 1.33 kB
build/vendors--cart-blocks/cart-line-items--checkout-blocks/order-summary-cart-items--mini-cart-contents---233ab542-frontend.js 3.14 kB
build/vendors--cart-blocks/order-summary-shipping--checkout-blocks/billing-address--checkout-blocks/order--5b8feb0b-frontend.js 4.75 kB
build/vendors--mini-cart-contents-block/footer-frontend.js 6.86 kB
build/vendors--product-add-to-cart-frontend.js 7.53 kB
build/wc-blocks-data.js 9.87 kB
build/wc-blocks-editor-style-rtl.css 4.92 kB
build/wc-blocks-editor-style.css 4.92 kB
build/wc-blocks-google-analytics.js 1.56 kB
build/wc-blocks-middleware.js 930 B
build/wc-blocks-registry.js 2.7 kB
build/wc-blocks-shared-context.js 1.52 kB
build/wc-blocks-shared-hocs.js 1.14 kB
build/wc-blocks-vendors-style-rtl.css 1.28 kB
build/wc-blocks-vendors-style.css 1.28 kB
build/wc-payment-method-bacs.js 816 B
build/wc-payment-method-cheque.js 811 B
build/wc-payment-method-cod.js 909 B
build/wc-payment-method-paypal.js 837 B
build/wc-settings.js 2.61 kB

compressed-size-action

const url = currentQueryArgKeys.reduce(
( currentUrl, queryArg ) =>
removeQueryArgs( currentUrl, queryArg ),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated this logic because with the previous implementation, ALL query parameters were removed, instead only the query parameters related to the attribute filter have to be removed.

@github-actions
Copy link
Contributor

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
stock-filter.js wp-url ⚠️

This comment was automatically generated by the ./github/compare-assets action.

Copy link
Member

@dinhtungdu dinhtungdu left a comment

Choose a reason for hiding this comment

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

@gigitux The filter isn't working for me. I tested on the shop page, and the filter worked with the Active Filter block but the product grid didn't take the stock status into account. The Stock filter is still working with the All Products block as expected.

image

@tjcafferkey
Copy link
Contributor

tjcafferkey commented Apr 19, 2022

@dinhtungdu I have just fixed that in 38e3642 so should be working as expected. Please can you re-test this?

@github-actions
Copy link
Contributor

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
stock-filter.js wp-url ⚠️

This comment was automatically generated by the ./github/compare-assets action.

Copy link
Member

@dinhtungdu dinhtungdu left a comment

Choose a reason for hiding this comment

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

@tjcafferkey thanks for the update, this is working for me, the selected stock filter also appears in the Active filters block.

But when I enabled the Filter button, I got some issues:

  • The page reloads immediately after I selected a filter. It should wait until I click the filter button.
  • The selected filter doesn't appear in the Active Filters block anymore.
Screen.Recording.2022-04-20.at.10.02.39.mov

@tjcafferkey
Copy link
Contributor

Good catch @dinhtungdu apologies that this was overlooked. I've addressed your feedback in this commit 03c607f and its now ready for another round of testing.

@github-actions
Copy link
Contributor

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
stock-filter.js wp-url ⚠️

This comment was automatically generated by the ./github/compare-assets action.

assets/js/blocks/stock-filter/block.js Outdated Show resolved Hide resolved
assets/js/blocks/stock-filter/block.js Outdated Show resolved Hide resolved
assets/js/blocks/stock-filter/block.js Outdated Show resolved Hide resolved
@github-actions
Copy link
Contributor

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
stock-filter.js wp-url ⚠️

This comment was automatically generated by the ./github/compare-assets action.

@github-actions
Copy link
Contributor

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
stock-filter.js wp-url ⚠️

This comment was automatically generated by the ./github/compare-assets action.

Copy link
Member

@dinhtungdu dinhtungdu left a comment

Choose a reason for hiding this comment

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

I left a minor comment but this is LGTM so pre-approving it.

assets/js/blocks/stock-filter/block.js Outdated Show resolved Hide resolved
@github-actions github-actions bot added this to the 7.5.0 milestone Apr 20, 2022
@github-actions
Copy link
Contributor

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
stock-filter.js wp-url ⚠️

This comment was automatically generated by the ./github/compare-assets action.

@dinhtungdu dinhtungdu self-requested a review April 21, 2022 07:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
block: filter by stock Issues related to the Filter by Stock block. type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make Filter Products by Stock work with PHP templates
4 participants