-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
Getting the Product Collection location/context #43997
Getting the Product Collection location/context #43997
Conversation
Test Results SummaryCommit SHA: c4498af
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. |
plugins/woocommerce-blocks/assets/js/blocks/product-template/utils.tsx
Outdated
Show resolved
Hide resolved
Hi @xristos3490, @imanish003, @woocommerce/woo-fse 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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work @kmanijak!
I tried all available contexts described in the requirements, but I've been attempting some edge cases, like adding a Single Product block inside another or a product template. Everything is working great!
Taxonomies are also working; post-related returns in a generic context and product-related returns have the required term IDs when applicable.
Issues
- The Product Catalog template still returns a generic context.
Notes
- Perhaps using the full taxonomy name is better and more aligned with PHP. e.g.,
cat
becomesproduct_cat
etc. - We need to decide on the context structure. Especially when it comes to handling partial contexts vs. unavailable ones (e.g., The Product Catalog template vs. a Products By Attribute template vs. Products by Category template). We'll do this async in Slack, as we discussed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Karol,
I've left a few minor comments, but everything appears to be functioning well. Excellent work! 🚀
plugins/woocommerce-blocks/assets/js/blocks/product-template/utils.tsx
Outdated
Show resolved
Hide resolved
plugins/woocommerce-blocks/assets/js/blocks/product-template/utils.tsx
Outdated
Show resolved
Hide resolved
plugins/woocommerce-blocks/assets/js/blocks/product-template/utils.tsx
Outdated
Show resolved
Hide resolved
plugins/woocommerce-blocks/assets/js/blocks/product-template/utils.tsx
Outdated
Show resolved
Hide resolved
plugins/woocommerce-blocks/assets/js/blocks/product-template/utils.tsx
Outdated
Show resolved
Hide resolved
plugins/woocommerce-blocks/assets/js/blocks/product-template/utils.tsx
Outdated
Show resolved
Hide resolved
plugins/woocommerce-blocks/assets/js/blocks/product-template/utils.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey Karol, the changes look good to me! Also, I like the new approach for E2E testing. 🙌🏻
I left a minor comment but pre-approving the PR. 🚀
Quick note: Perhaps you could update the PR description. For example, it still mentions that it's a POC, but I believe we've moved beyond that stage 😅
...woocommerce-blocks/tests/e2e/tests/product-collection/product-collection.block_theme.spec.ts
Outdated
Show resolved
Hide resolved
...woocommerce-blocks/tests/e2e/tests/product-collection/product-collection.block_theme.spec.ts
Outdated
Show resolved
Hide resolved
* Early implementation of getting the Product Collection location/context * Solve the problem of async fetch in the hook * Improve typing * Import core data store instead of hardcoding store name * Recognise Product Category and Product Tag * Remove attr property from archive location data * Unify states naming * Add TODO entry * Display the info about the location of Product Collection * Improve the typing * Recognise if Product Collection is nested in Single Product block * Improve cases descriptions and add some defaults to potentially undefined values * Change the taxonomies sourceData * Recognise Mini Cart as Cart context * Recognise attribute as archive contect but no taxonomy * Refactor the function into single useEffect and clean it up * Fix typo * Remove unnecessary import * Stop rendering the output in Editor (it was for demo purposes) * Pass location data to Product Template query in Editor * Replace templateSlugs literal strings with object reference * Rename parseResponse function to more specific name getIdFromResponse * Add dpeendency array to useEffect * Refactor templates detection * Use full taxonomy names instead of shortcuts * Write down scenarios to test * Working scenario * Change the verification way for more robust * Add more robust methods to include Single Product block * Add test Product Collection in Single Product block in a Single Product Template * Imprvoe the order of veryfing the requests * Fix linter issues. Although that makes code less readable * Improve the useGetLocation typing so it's more generic * Rework the E2E tests regarding location of Product Collection and limit their number * Bring back necessary eslint-disable * Remove unused imports * Uncomment line required for other tests * Add changelog * Rename constant from BLOCK_NAME to BLOCK_SLUG as it's a slug * Add a BLOCK_NAME constant and replace the literal block name usages in E2E tests * Fix post merge issues * Fix test after merge * Adjust the tests to kick off waiting for request before action that triggers them
Getting the Product Collection location/context
This PR includes creating a
useGetLocation
hook that recognizes the location and context of Product Collection block (and potentially other blocks).Examples:
Note: the below screenshot were taken for demo purposes. The block doesn't render that data in the Editor in this PR!
Prerequisites to testing:
product isproductcollection
Testing steps:
location[type]
isproduct
location[sourceData][productId]
is empty:location[type]: 'archive'
location[sourceData][taxonomy]: 'product_cat'
location[sourceData][taxonomy]:
location[type]: 'archive'
location[sourceData][taxonomy]: 'product_cat'
location[sourceData][taxonomy]: SPECIFIC_CATEGORY_ID
location[type]: 'product'
location[sourceData][productId]: SPECIFIC_PRODUCT_ID
location[type]: 'product'
location[sourceData][productID]: PRODUCT_ID
location[type]: 'product'
location[sourceData][productID]: PRODUCT_ID_FROM_SINGLE_PRODUCT_BLOCK }
location[type]: 'cart'
location[type]: 'generic'
Additional instructions - how to add custom templates or modify some blocks
Create "Single Product: SPECIFIC_PRODUCT template"
Adding Product Collection inside Single Product block
Product Collection in Mini Cart Contents
Closes: #43694