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

Getting the Product Collection location/context #43997

Merged
merged 48 commits into from
Feb 12, 2024

Conversation

kmanijak
Copy link
Contributor

@kmanijak kmanijak commented Jan 23, 2024

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!

In Specific category template (Category: Clothing) In Single Product template In post/page
image image image

Prerequisites to testing:

  1. To verify the location, go to Developer Tools -> Network tab
  2. Search for: product isproductcollection

Testing steps:

  1. Try adding Product Collection block (choose some collection, for example, "Featured") in multiple places (example scenarios are provided in the next step) and verify the proper payload is sent with the request by checking Payload tab.
  • Example from Single Product template:
    • location[type] is product
    • productId is unknown, hence location[sourceData][productId] is empty:

Screen Shot 2024-02-09 at 17 43 51 PM

  1. Here are some example scenarios, but try to break it as well by trying something else:
Scenario Output
Products by Category/Tag/Attribute template location[type]: 'archive'
location[sourceData][taxonomy]: 'product_cat'
location[sourceData][taxonomy]:
Category: SPECIFIC_CATEGORY template location[type]: 'archive'
location[sourceData][taxonomy]: 'product_cat'
location[sourceData][taxonomy]: SPECIFIC_CATEGORY_ID
Product Collection in Single Product block in Category: SPECIFIC_CATEGORY template location[type]: 'product'
location[sourceData][productId]: SPECIFIC_PRODUCT_ID
Product Collection in Single Product: SPECIFIC_PRODUCT template location[type]: 'product'
location[sourceData][productID]: PRODUCT_ID
In the above scenario, add Single Product block and Product Collection inside location[type]: 'product'
location[sourceData][productID]: PRODUCT_ID_FROM_SINGLE_PRODUCT_BLOCK }
Product Collection in Mini Cart Contents location[type]: 'cart'
Page/Post location[type]: 'generic'
  1. Location type matches the closest context and ID is provided if available.

Additional instructions - how to add custom templates or modify some blocks

Create "Single Product: SPECIFIC_PRODUCT template"

  1. Go to Editor -> Templates -> "+" button -> Single Item: Product
  2. Choose some product

Adding Product Collection inside Single Product block

  1. Add "Single Product" block from the inserter
image
  1. Choose some product and click "Done"
  2. Open List View of blocks
  3. Expand Single Product block -> Columns -> Column
  4. Click "Three dots" menu next to some of the inner blocks and click "Add After"
  5. Insert Product Collection and choose some collection, for example "Featured"
image

Product Collection in Mini Cart Contents

  1. Go to Editor -> Patterns -> Scroll to the very bottom and choose "Mini Cart" -> "Mini Cart"
image
  1. Edit template part
  2. Open List view of blocks
  3. Expand Mini Cart Contents -> Filled Mini Cart -> Mini Cart Items
  4. Click "Three dots" menu next to some of the inner blocks and click "Add After"
  5. Insert Product Collection and choose some collection, for example "Featured"

Closes: #43694

Copy link
Contributor

github-actions bot commented Jan 23, 2024

Test Results Summary

Commit SHA: c4498af

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests25900202610m 37s
E2E Tests296002103177m 13s

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.

@kmanijak kmanijak changed the title Getting the Product Collection location/context POC: Getting the Product Collection location/context Jan 26, 2024
Copy link
Contributor

github-actions bot commented Jan 26, 2024

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:
https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

Copy link
Member

@xristos3490 xristos3490 left a 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 becomes product_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.

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.

Hi Karol,

I've left a few minor comments, but everything appears to be functioning well. Excellent work! 🚀

@kmanijak kmanijak marked this pull request as ready for review February 9, 2024 16:57
@woocommercebot woocommercebot requested a review from a team February 9, 2024 16:57
@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Feb 9, 2024
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 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 😅

@kmanijak kmanijak merged commit 2750e79 into trunk Feb 12, 2024
41 checks passed
@kmanijak kmanijak deleted the 43694/get-product-collection-location-context branch February 12, 2024 19:59
@github-actions github-actions bot added this to the 8.7.0 milestone Feb 12, 2024
@github-actions github-actions bot added the needs: analysis Indicates if the PR requires a PR testing scrub session. label Feb 12, 2024
@Stojdza Stojdza added status: analysis complete Indicates if a PR has been analysed by Solaris needs: internal testing Indicates if the PR requires further testing conducted by Solaris and removed needs: analysis Indicates if the PR requires a PR testing scrub session. labels Feb 13, 2024
jonathansadowski pushed a commit that referenced this pull request May 3, 2024
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: internal testing Indicates if the PR requires further testing conducted by Solaris plugin: woocommerce Issues related to the WooCommerce Core plugin. status: analysis complete Indicates if a PR has been analysed by Solaris
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Product Collection: POC - get information about context/location of PC block in Editor
5 participants