Skip to content

Add taxonomy support to Product Collection Data API endpoint #59608

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

Conversation

dinhtungdu
Copy link
Member

Submission Review Guidelines:

Changes proposed in this Pull Request:

This PR adds taxonomy support to the Product Collection Data API endpoint, enabling clients to retrieve taxonomy counts (such as categories and tags) for products in a collection.

Key changes:

  • Added calculate_taxonomy_counts parameter to the product collection data endpoint
  • Implemented taxonomy count calculation logic that returns term IDs and their corresponding product counts
  • Enhanced test coverage to verify taxonomy counts for both categories and tags

Closes WOOPLUG-4766
Closes #59130

How to test the changes in this Pull Request:

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

  1. Set up a test environment with WooCommerce installed
  2. Create test products and assign them to various categories and tags
  3. Make a REST API request to /wc/store/v1/products/collection-data with the calculate_taxonomy_counts parameter:
    GET /wc/store/v1/products/collection-data?calculate_taxonomy_counts[]=product_cat&calculate_taxonomy_counts[]=product_tag
    
  4. Verify the response includes a taxonomy_counts array with term IDs and their corresponding product counts
  5. Test with different taxonomy combinations to ensure accurate count calculations
  6. Run the PHPUnit tests to verify all functionality works correctly:
    pnpm run test:php:env tests/php/src/Blocks/StoreApi/Routes/ProductCollectionData.php
    

Changelog entry

  • Automatically create a changelog entry from the details below.
Changelog Entry Details

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

Add taxonomy support to Product Collection Data API endpoint with calculate_taxonomy_counts parameter

Use + operator instead of array_merge to preserve term IDs when
combining taxonomy counts from multiple taxonomies.
Change calculate_taxonomy_counts from array of objects to simple
array of taxonomy name strings since query types are not needed
for taxonomies.

Before: calculate_taxonomy_counts[0][taxonomy]=product_cat
After: calculate_taxonomy_counts[0]=product_cat
@dinhtungdu dinhtungdu requested review from a team as code owners July 11, 2025 05:35
@dinhtungdu dinhtungdu requested review from opr and removed request for a team July 11, 2025 05:35
@github-actions github-actions bot added Documentation Issues and PRs related to improving documentation plugin: woocommerce Issues related to the WooCommerce Core plugin. labels Jul 11, 2025
@woocommercebot woocommercebot requested review from a team and gigitux and removed request for a team July 11, 2025 05:35
Copy link
Contributor

github-actions bot commented Jul 11, 2025

Testing Guidelines

Hi @gigitux @opr @woocommerce/developer-advocacy,

Apart from reviewing the code changes, please make sure to review the testing instructions (Guide) and verify that relevant tests (E2E, Unit, Integration, etc.) have been added or updated as needed.

Reminder: PR reviewers are required to document testing performed. This includes:

  • 🖼️ Screenshots or screen recordings.
  • 📝 List of functionality tested / steps followed.
  • 🌐 Site details (environment attributes such as hosting type, plugins, theme, store size, store age, and relevant settings).
  • 🔍 Any analysis performed, such as assessing potential impacts on environment attributes and other plugins, conducting performance profiling, or using LLM/AI-based analysis.

⚠️ Within the testing details you provide, please ensure that no sensitive information (such as API keys, passwords, user data, etc.) is included in this public issue.

Copy link
Contributor

coderabbitai bot commented Jul 11, 2025

📝 Walkthrough

Walkthrough

Support for taxonomy term counts was added to the Product Collection Data API in WooCommerce. This includes a new calculate_taxonomy_counts parameter in the API, updates to documentation and schema, backend logic to compute and return taxonomy counts, and new tests to verify the feature.

Changes

File(s) Change Summary
docs/apis/store-api/resources-endpoints/product-collection-data.md Updated documentation to describe the new calculate_taxonomy_counts parameter, with example request and response.
plugins/woocommerce/changelog/59608-wooplug-4766-product-collection-data-api-add-support-for-taxonomy Added changelog entry for taxonomy counts support in Product Collection Data API.
plugins/woocommerce/src/StoreApi/Routes/V1/ProductCollectionData.php Added calculate_taxonomy_counts parameter to endpoint, handled request logic, and included taxonomy counts in response.
plugins/woocommerce/src/StoreApi/Schemas/V1/ProductCollectionDataSchema.php Added taxonomy_counts property to schema and included it in API responses.
plugins/woocommerce/src/StoreApi/Utilities/ProductQueryFilters.php Added get_taxonomy_counts method to compute taxonomy term counts for a product query.
plugins/woocommerce/src/StoreApi/Utilities/ProductQuery.php Updated class to implement QueryClausesGenerator and corrected method signature/type hints.
plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/ProductCollectionData.php Added and extended tests for taxonomy counts, including new test method and schema validation.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API as ProductCollectionData API
    participant Filters as ProductQueryFilters
    participant Query as ProductQuery
    participant Data as FilterDataProvider

    Client->>API: GET /products/collection-data?calculate_taxonomy_counts=[...]
    API->>Filters: get_taxonomy_counts(request, taxonomies)
    Filters->>Query: request_to_query_vars(request)
    Filters->>Data: get(FilterDataProvider)
    Filters->>Data: get_taxonomy_counts(query_vars, taxonomy)
    Data-->>Filters: {term_id: count, ...}
    Filters-->>API: taxonomy_counts array
    API-->>Client: Response with taxonomy_counts
Loading

Possibly related PRs


📜 Recent review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3172255 and d97d6f3.

📒 Files selected for processing (1)
  • docs/apis/store-api/resources-endpoints/product-collection-data.md (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/apis/store-api/resources-endpoints/product-collection-data.md

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@dinhtungdu dinhtungdu closed this Jul 11, 2025
@dinhtungdu dinhtungdu reopened this Jul 11, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
plugins/woocommerce/src/StoreApi/Routes/V1/ProductCollectionData.php (1)

171-185: Refactor: Simplify redundant condition checks

The nested condition checks can be simplified since ! empty( $request['calculate_taxonomy_counts'] ) already ensures the parameter exists and is not empty.

-if ( ! empty( $request['calculate_taxonomy_counts'] ) ) {
-	$taxonomies              = $request['calculate_taxonomy_counts'];
-	$data['taxonomy_counts'] = [];
-
-	if ( $taxonomies ) {
-		$counts = $filters->get_taxonomy_counts( $request, $taxonomies );
-
-		foreach ( $counts as $key => $value ) {
-			$data['taxonomy_counts'][] = (object) [
-				'term'  => $key,
-				'count' => $value,
-			];
-		}
-	}
-}
+if ( ! empty( $request['calculate_taxonomy_counts'] ) ) {
+	$taxonomies              = $request['calculate_taxonomy_counts'];
+	$data['taxonomy_counts'] = [];
+	$counts                  = $filters->get_taxonomy_counts( $request, $taxonomies );
+
+	foreach ( $counts as $key => $value ) {
+		$data['taxonomy_counts'][] = (object) [
+			'term'  => $key,
+			'count' => $value,
+		];
+	}
+}
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b68a087 and 7b714fe.

📒 Files selected for processing (7)
  • docs/apis/store-api/resources-endpoints/product-collection-data.md (2 hunks)
  • plugins/woocommerce/changelog/59608-wooplug-4766-product-collection-data-api-add-support-for-taxonomy (1 hunks)
  • plugins/woocommerce/src/StoreApi/Routes/V1/ProductCollectionData.php (3 hunks)
  • plugins/woocommerce/src/StoreApi/Schemas/V1/ProductCollectionDataSchema.php (2 hunks)
  • plugins/woocommerce/src/StoreApi/Utilities/ProductQuery.php (2 hunks)
  • plugins/woocommerce/src/StoreApi/Utilities/ProductQueryFilters.php (1 hunks)
  • plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/ProductCollectionData.php (9 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
`plugins/woocommerce/tests/**/*.php`: Run WooCommerce PHPUnit tests for specific...

plugins/woocommerce/tests/**/*.php: Run WooCommerce PHPUnit tests for specific files or directories using the command: pnpm run test:php:env {relative_path} --verbose, and ensure the command is run in the plugins/woocommerce directory.

📄 Source: CodeRabbit Inference Engine (.cursor/rules/woo-phpunit.mdc)

List of files the instruction was applied to:

  • plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/ProductCollectionData.php
`**/*.{php,js,ts,jsx,tsx}`: Don't trust that extension developers will follow th...

**/*.{php,js,ts,jsx,tsx}: Don't trust that extension developers will follow the best practices, make sure the code:

  • Guards against unexpected inputs.
  • Sanitizes and validates any potentially dangerous inputs.
  • Is backwards compatible.
  • Is readable and intuitive.
  • Has unit or E2E tests where applicable.

⚙️ Source: CodeRabbit Configuration File

List of files the instruction was applied to:

  • plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/ProductCollectionData.php
  • plugins/woocommerce/src/StoreApi/Routes/V1/ProductCollectionData.php
  • plugins/woocommerce/src/StoreApi/Utilities/ProductQueryFilters.php
  • plugins/woocommerce/src/StoreApi/Schemas/V1/ProductCollectionDataSchema.php
  • plugins/woocommerce/src/StoreApi/Utilities/ProductQuery.php
🧠 Learnings (7)
📓 Common learnings
Learnt from: dinhtungdu
PR: woocommerce/woocommerce#59499
File: plugins/woocommerce/src/Internal/ProductFilters/QueryClauses.php:327-332
Timestamp: 2025-07-10T04:22:27.625Z
Learning: In the WooCommerce ProductFilters QueryClauses class, the $chosen_taxonomies parameter in add_taxonomy_clauses() already contains only validated public product taxonomies. The validation occurs upstream in the Params class during parameter registration, so additional taxonomy existence validation in the processing methods is redundant.
plugins/woocommerce/changelog/59608-wooplug-4766-product-collection-data-api-add-support-for-taxonomy (1)
Learnt from: dinhtungdu
PR: woocommerce/woocommerce#59499
File: plugins/woocommerce/src/Internal/ProductFilters/QueryClauses.php:327-332
Timestamp: 2025-07-10T04:22:27.625Z
Learning: In the WooCommerce ProductFilters QueryClauses class, the $chosen_taxonomies parameter in add_taxonomy_clauses() already contains only validated public product taxonomies. The validation occurs upstream in the Params class during parameter registration, so additional taxonomy existence validation in the processing methods is redundant.
plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/ProductCollectionData.php (2)
Learnt from: dinhtungdu
PR: woocommerce/woocommerce#59499
File: plugins/woocommerce/src/Internal/ProductFilters/QueryClauses.php:327-332
Timestamp: 2025-07-10T04:22:27.625Z
Learning: In the WooCommerce ProductFilters QueryClauses class, the $chosen_taxonomies parameter in add_taxonomy_clauses() already contains only validated public product taxonomies. The validation occurs upstream in the Params class during parameter registration, so additional taxonomy existence validation in the processing methods is redundant.
Learnt from: mreishus
PR: woocommerce/woocommerce#58891
File: plugins/woocommerce/src/Blocks/Utils/BlocksSharedState.php:0-0
Timestamp: 2025-06-16T21:59:26.255Z
Learning: In WooCommerce's CartSchema::get_item_response() method, when called in the context of BlocksSharedState::register_cart_interactivity(), the method returns a plain array rather than a WP_REST_Response object, making it directly suitable for wp_interactivity_state() without needing to call ->get_data().
plugins/woocommerce/src/StoreApi/Routes/V1/ProductCollectionData.php (2)
Learnt from: dinhtungdu
PR: woocommerce/woocommerce#59499
File: plugins/woocommerce/src/Internal/ProductFilters/QueryClauses.php:327-332
Timestamp: 2025-07-10T04:22:27.625Z
Learning: In the WooCommerce ProductFilters QueryClauses class, the $chosen_taxonomies parameter in add_taxonomy_clauses() already contains only validated public product taxonomies. The validation occurs upstream in the Params class during parameter registration, so additional taxonomy existence validation in the processing methods is redundant.
Learnt from: mreishus
PR: woocommerce/woocommerce#58891
File: plugins/woocommerce/src/Blocks/Utils/BlocksSharedState.php:0-0
Timestamp: 2025-06-16T21:59:26.255Z
Learning: In WooCommerce's CartSchema::get_item_response() method, when called in the context of BlocksSharedState::register_cart_interactivity(), the method returns a plain array rather than a WP_REST_Response object, making it directly suitable for wp_interactivity_state() without needing to call ->get_data().
plugins/woocommerce/src/StoreApi/Utilities/ProductQueryFilters.php (1)
Learnt from: dinhtungdu
PR: woocommerce/woocommerce#59499
File: plugins/woocommerce/src/Internal/ProductFilters/QueryClauses.php:327-332
Timestamp: 2025-07-10T04:22:27.625Z
Learning: In the WooCommerce ProductFilters QueryClauses class, the $chosen_taxonomies parameter in add_taxonomy_clauses() already contains only validated public product taxonomies. The validation occurs upstream in the Params class during parameter registration, so additional taxonomy existence validation in the processing methods is redundant.
plugins/woocommerce/src/StoreApi/Schemas/V1/ProductCollectionDataSchema.php (2)
Learnt from: dinhtungdu
PR: woocommerce/woocommerce#59499
File: plugins/woocommerce/src/Internal/ProductFilters/QueryClauses.php:327-332
Timestamp: 2025-07-10T04:22:27.625Z
Learning: In the WooCommerce ProductFilters QueryClauses class, the $chosen_taxonomies parameter in add_taxonomy_clauses() already contains only validated public product taxonomies. The validation occurs upstream in the Params class during parameter registration, so additional taxonomy existence validation in the processing methods is redundant.
Learnt from: mreishus
PR: woocommerce/woocommerce#58891
File: plugins/woocommerce/src/Blocks/Utils/BlocksSharedState.php:0-0
Timestamp: 2025-06-16T21:59:26.255Z
Learning: In WooCommerce's CartSchema::get_item_response() method, when called in the context of BlocksSharedState::register_cart_interactivity(), the method returns a plain array rather than a WP_REST_Response object, making it directly suitable for wp_interactivity_state() without needing to call ->get_data().
plugins/woocommerce/src/StoreApi/Utilities/ProductQuery.php (1)
Learnt from: dinhtungdu
PR: woocommerce/woocommerce#59499
File: plugins/woocommerce/src/Internal/ProductFilters/QueryClauses.php:327-332
Timestamp: 2025-07-10T04:22:27.625Z
Learning: In the WooCommerce ProductFilters QueryClauses class, the $chosen_taxonomies parameter in add_taxonomy_clauses() already contains only validated public product taxonomies. The validation occurs upstream in the Params class during parameter registration, so additional taxonomy existence validation in the processing methods is redundant.
🧬 Code Graph Analysis (1)
plugins/woocommerce/src/StoreApi/Routes/V1/ProductCollectionData.php (1)
plugins/woocommerce/src/StoreApi/Utilities/ProductQueryFilters.php (1)
  • get_taxonomy_counts (224-250)
🪛 PHPMD (2.15.0)
plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/ProductCollectionData.php

183-183: Avoid unused local variables such as '$fixtures'. (Unused Code Rules)

(UnusedLocalVariable)

🔇 Additional comments (16)
plugins/woocommerce/changelog/59608-wooplug-4766-product-collection-data-api-add-support-for-taxonomy (1)

1-4: LGTM - Changelog entry is properly formatted.

The changelog entry correctly documents the new feature with appropriate significance (minor) and type (add).

docs/apis/store-api/resources-endpoints/product-collection-data.md (3)

10-10: LGTM - Example URL correctly demonstrates the new parameter.

The example URL shows proper usage of the calculate_taxonomy_counts parameter as an array.


13-19: LGTM - Parameter documentation is clear and consistent.

The parameter table correctly describes the new calculate_taxonomy_counts parameter with appropriate type (array) and description.


67-81: LGTM - Response example accurately shows the new taxonomy_counts structure.

The example response correctly demonstrates the expected structure with term IDs and counts.

plugins/woocommerce/src/StoreApi/Schemas/V1/ProductCollectionDataSchema.php (2)

121-143: LGTM - Schema property follows consistent pattern.

The taxonomy_counts property definition is consistent with other count properties in the schema, using the same structure with term and count fields.


164-164: LGTM - Property correctly added to response.

The taxonomy_counts data is properly included in the response array.

plugins/woocommerce/src/StoreApi/Utilities/ProductQueryFilters.php (1)

217-250: LGTM - Well-implemented taxonomy counting method.

The get_taxonomy_counts method follows the established pattern of other count methods in this class. It correctly:

  • Clears pagination and sorting parameters to get accurate counts
  • Uses the FilterDataProvider with ProductQuery as QueryClausesGenerator
  • Preserves array keys when merging counts using the + operator
  • Leverages the existing taxonomy validation that occurs upstream

The implementation is secure and consistent with WooCommerce coding standards.

plugins/woocommerce/src/StoreApi/Utilities/ProductQuery.php (3)

9-9: LGTM - Interface import added correctly.

The QueryClausesGenerator interface import is properly added to support the new functionality.


17-17: LGTM - Interface implementation enables FilterDataProvider usage.

Implementing the QueryClausesGenerator interface allows this class to be used with the FilterDataProvider for taxonomy counting.


350-353: LGTM - Method signature corrected with proper type hints.

The method signature now has proper type hints (array $args and \WP_Query $wp_query) which improves type safety and corrects the previous incorrect \WC_Query reference.

plugins/woocommerce/src/StoreApi/Routes/V1/ProductCollectionData.php (2)

76-76: LGTM: Consistent initialization pattern

The null initialization of taxonomy_counts follows the same pattern as other similar fields in the response data structure.


240-248: LGTM: Well-defined parameter structure

The parameter definition follows REST API best practices with proper type definition, description, and default value. The array of strings structure is appropriate for taxonomy names.

plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/ProductCollectionData.php (4)

55-55: LGTM: Consistent test assertions

The additions of taxonomy_counts null assertions in existing tests maintain consistency with the established testing pattern for other optional fields.

Also applies to: 73-73, 107-107, 143-143, 163-163


179-278: Excellent comprehensive test coverage

The test method provides thorough coverage of the taxonomy counts feature:

  • Tests both single and multiple taxonomies
  • Verifies response structure and data types
  • Validates actual count accuracy
  • Uses proper WordPress taxonomy functions for test data setup

The test follows best practices and will effectively catch regressions in the taxonomy counting functionality.


291-291: LGTM: Parameter validation updated

The collection params test is correctly updated to include the new calculate_taxonomy_counts parameter.


306-329: LGTM: Schema validation enhanced

The schema test is properly updated to include taxonomy setup and parameter usage, ensuring the response structure validation covers the new feature.

Copy link
Contributor

github-actions bot commented Jul 11, 2025

Test using WordPress Playground

The changes in this pull request can be previewed and tested using a WordPress Playground instance.
WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Test this pull request with WordPress Playground.

Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit.

Copy link
Contributor

@gigitux gigitux left a comment

Choose a reason for hiding this comment

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

Thanks for working on this! I left one comment regarding the DI in the src folder. Besides this, everything LGTM! I'm not approving because I want to ensure that I tested the PR correctly.

/wc/store/v1/products/collection-data?calculate_taxonomy_counts[]=product_cat&calculate_taxonomy_counts[]=product_tag

Can you clarify this step in the testing instruction? If I use this URL structure, I got:

Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 20480 bytes)

With this URL, everything works as expected:

/wc/store/v1/products/collection-data?calculate_taxonomy_counts=product_cat, product_tag right?

$query_vars = $product_query->prepare_objects_query( $request );

// Use FilterData with ProductQuery as QueryClausesGenerator.
$container = wc_get_container();
Copy link
Contributor

Choose a reason for hiding this comment

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

Checking the documentation, in the src folder, the DI should be done in a different way: https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/src/README.md#1-other-classes-in-the-src-directory

Copy link
Member Author

Choose a reason for hiding this comment

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

Store API (and Blocks) has its own container, so it's not possible to follow that guide right now. See #43772 (comment)

* Test taxonomy calculation method.
*/
public function test_calculate_taxonomy_counts() {
$fixtures = new FixtureData();
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like not necessary

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, I will delete this. It was used initially but I forgot to remove after a refactor.

@dinhtungdu
Copy link
Member Author

@gigitux both URLs should work fine. I'm curious what can cause the error for you. It's working as expected on my end. You should still get the same array of two either using comma separated string or the array notion. 🤔

image image

Copy link
Contributor

@gigitux gigitux left a comment

Choose a reason for hiding this comment

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

Thanks for addressing the feedback!

It was an issue on my env because I tested again, and everything works as expected with both URL structures.ì 🚀

Image

@opr opr removed their request for review July 15, 2025 15:41
…d syntax

- Change from array syntax calculate_taxonomy_counts[0]=product_cat to comma-separated calculate_taxonomy_counts=product_cat
- Update cURL example to show multiple taxonomies with comma separation
- Both formats work due to WordPress REST API parameter parsing, but comma-separated is more concise
@dinhtungdu dinhtungdu merged commit 003028d into trunk Jul 17, 2025
26 checks passed
@dinhtungdu dinhtungdu deleted the wooplug-4766-product-collection-data-api-add-support-for-taxonomy branch July 17, 2025 10:03
Copy link
Contributor

⚠️ API Documentation Reminder

Hi @dinhtungdu! Your PR contains REST API changes. Please consider updating the REST API documentation if your changes affect the public API.

Changed API files:

plugins/woocommerce/src/StoreApi/Routes/V1/ProductCollectionData.php
plugins/woocommerce/src/StoreApi/Schemas/V1/ProductCollectionDataSchema.php
plugins/woocommerce/src/StoreApi/Utilities/ProductQuery.php
plugins/woocommerce/src/StoreApi/Utilities/ProductQueryFilters.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Issues and PRs related to improving documentation plugin: woocommerce Issues related to the WooCommerce Core plugin.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Product Collection Data API: add support for taxonomy
2 participants