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

Commit

Permalink
Add: menu-order orderby option for Product Attribute Terms route (#…
Browse files Browse the repository at this point in the history
…11232)

Co-authored-by: Mike Jolley <[email protected]>
  • Loading branch information
dinhtungdu and mikejolley authored Oct 17, 2023
1 parent 3e4b656 commit 34af3bf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions assets/js/blocks/attribute-filter/block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ const AttributeFilterBlock = ( {
resourceName: 'products/attributes/terms',
resourceValues: [ attributeObject?.id || 0 ],
shouldSelect: blockAttributes.attributeId > 0,
query: { orderby: 'menu_order' },
} );

const { results: filteredCounts, isLoading: filteredCountsLoading } =
Expand Down
11 changes: 11 additions & 0 deletions src/StoreApi/Routes/V1/ProductAttributeTerms.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ public function get_args() {
];
}

/**
* Get the query params for collections of attributes.
*
* @return array
*/
public function get_collection_params() {
$params = parent::get_collection_params();
$params['orderby']['enum'][] = 'menu_order';
return $params;
}

/**
* Get a collection of attribute terms.
*
Expand Down
13 changes: 6 additions & 7 deletions src/StoreApi/docs/product-attribute-terms.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

```http
GET /products/attributes/:id/terms
GET /products/attributes/:id/terms&orderby=slug
GET /products/attributes/:id/terms?orderby=slug
```

| Attribute | Type | Required | Description |
| :-------- | :------ | :------: | :---------------------------------------------------------------------------- |
| `id` | integer | Yes | The ID of the attribute to retrieve terms for. |
| `order` | string | no | Order ascending or descending. Allowed values: `asc`, `desc` |
| `orderby` | string | no | Sort collection by object attribute. Allowed values: `name`, `slug`, `count`. |
| Attribute | Type | Required | Description |
| :-------- | :------ | :------: | :------------------------------------------------------------------------------------------ |
| `id` | integer | Yes | The ID of the attribute to retrieve terms for. |
| `order` | string | no | Order ascending or descending. Allowed values: `asc`, `desc` |
| `orderby` | string | no | Sort collection by object attribute. Allowed values: `name`, `slug`, `count`, `menu_order`. |

```sh
curl "https://example-store.com/wp-json/wc/store/v1/products/attributes/1/terms"
Expand Down Expand Up @@ -43,4 +43,3 @@ curl "https://example-store.com/wp-json/wc/store/v1/products/attributes/1/terms"
🐞 Found a mistake, or have a suggestion? [Leave feedback about this document here.](https://github.com/woocommerce/woocommerce-blocks/issues/new?assignees=&labels=type%3A+documentation&template=--doc-feedback.md&title=Feedback%20on%20./src/StoreApi/docs/product-attribute-terms.md)

<!-- /FEEDBACK -->

0 comments on commit 34af3bf

Please sign in to comment.