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

Add: menu-order orderby option for Product Attribute Terms route #11232

Merged
merged 2 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
11 changes: 5 additions & 6 deletions src/StoreApi/docs/product-attribute-terms.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ GET /products/attributes/:id/terms
GET /products/attributes/:id/terms&orderby=slug
dinhtungdu marked this conversation as resolved.
Show resolved Hide resolved
```

| 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 -->