-
-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
collectionStats
query added (#785)
* feat: collectionStats query added * fix: `collectionStats` query completed and tested. * chore: Linter and PHPStan compliance met * chore: ProductTaxonomy values fixed. * chore: CollectionStatsQueryTest tweaked for CI
- Loading branch information
Showing
14 changed files
with
922 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
/** | ||
* WPEnum Type - AttributeOperatorEnum | ||
* | ||
* @package WPGraphQL\WooCommerce\Type\WPEnum | ||
* @since TBD | ||
*/ | ||
|
||
namespace WPGraphQL\WooCommerce\Type\WPEnum; | ||
|
||
/** | ||
* Class Attribute_Operator_Enum | ||
*/ | ||
class Attribute_Operator_Enum { | ||
/** | ||
* Registers type | ||
* | ||
* @return void | ||
*/ | ||
public static function register() { | ||
register_graphql_enum_type( | ||
'AttributeOperatorEnum', | ||
[ | ||
'description' => __( 'Collection statistic attributes operators', 'wp-graphql-woocommerce' ), | ||
'values' => [ | ||
'IN' => [ 'value' => 'IN' ], | ||
'NOT_IN' => [ 'value' => 'NOT IN' ], | ||
'AND' => [ 'value' => 'AND' ], | ||
], | ||
] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
/** | ||
* WPEnum Type - ProductAttributeEnum | ||
* | ||
* @package WPGraphQL\WooCommerce\Type\WPEnum | ||
* @since TBD | ||
*/ | ||
|
||
namespace WPGraphQL\WooCommerce\Type\WPEnum; | ||
|
||
use WPGraphQL\Type\WPEnumType; | ||
|
||
/** | ||
* Class Product_Attribute_Enum | ||
*/ | ||
class Product_Attribute_Enum { | ||
/** | ||
* Registers type | ||
* | ||
* @return void | ||
*/ | ||
public static function register() { | ||
// Get values from product attributes. | ||
$taxonomy_values = []; | ||
$taxonomies = wc_get_attribute_taxonomy_names(); | ||
|
||
foreach ( $taxonomies as $taxonomy ) { | ||
$tax_object = get_taxonomy( $taxonomy ); | ||
|
||
if ( false !== $tax_object && in_array( 'product', $tax_object->object_type, true ) ) { | ||
$taxonomy_values[ WPEnumType::get_safe_name( $taxonomy ) ] = [ 'value' => $taxonomy ]; | ||
} | ||
} | ||
|
||
register_graphql_enum_type( | ||
'ProductAttributeEnum', | ||
[ | ||
'description' => __( 'Product attribute taxonomies', 'wp-graphql-woocommerce' ), | ||
'values' => $taxonomy_values, | ||
] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
includes/type/input/class-collection-stats-query-input.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
/** | ||
* WPInputObjectType - CollectionStatsQueryInput | ||
* | ||
* @package WPGraphQL\WooCommerce\Type\WPInputObject | ||
* @since TBD | ||
*/ | ||
|
||
namespace WPGraphQL\WooCommerce\Type\WPInputObject; | ||
|
||
/** | ||
* Class Collection_Stats_Query_Input | ||
*/ | ||
class Collection_Stats_Query_Input { | ||
/** | ||
* Registers type | ||
* | ||
* @return void | ||
*/ | ||
public static function register() { | ||
register_graphql_input_type( | ||
'CollectionStatsQueryInput', | ||
[ | ||
'description' => __( 'Taxonomy query', 'wp-graphql-woocommerce' ), | ||
'fields' => [ | ||
'taxonomy' => [ | ||
'type' => [ 'non_null' => 'ProductAttributeEnum' ], | ||
'description' => __( 'Product Taxonomy', 'wp-graphql-woocommerce' ), | ||
], | ||
'relation' => [ | ||
'type' => [ 'non_null' => 'RelationEnum' ], | ||
'description' => __( 'Taxonomy relation to query', 'wp-graphql-woocommerce' ), | ||
], | ||
], | ||
] | ||
); | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
includes/type/input/class-collection-stats-where-args.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
/** | ||
* WPInputObjectType - CollectionStatsWhereArgs | ||
* | ||
* @package WPGraphQL\WooCommerce\Type\WPInputObject | ||
* @since TBD | ||
*/ | ||
|
||
namespace WPGraphQL\WooCommerce\Type\WPInputObject; | ||
|
||
/** | ||
* Class Collection_Stats_Where_Args | ||
*/ | ||
class Collection_Stats_Where_Args { | ||
/** | ||
* Registers type | ||
* | ||
* @return void | ||
*/ | ||
public static function register() { | ||
register_graphql_input_type( | ||
'CollectionStatsWhereArgs', | ||
[ | ||
'description' => __( 'Arguments used to filter the collection results', 'wp-graphql-woocommerce' ), | ||
'fields' => [ | ||
'search' => [ | ||
'type' => 'String', | ||
'description' => __( 'Limit result set to products based on a keyword search.', 'wp-graphql-woocommerce' ), | ||
], | ||
'slugIn' => [ | ||
'type' => [ 'list_of' => 'String' ], | ||
'description' => __( 'Limit result set to products with specific slugs.', 'wp-graphql-woocommerce' ), | ||
], | ||
'typeIn' => [ | ||
'type' => [ 'list_of' => 'ProductTypesEnum' ], | ||
'description' => __( 'Limit result set to products assigned to a group of specific types.', 'wp-graphql-woocommerce' ), | ||
], | ||
'exclude' => [ | ||
'type' => [ 'list_of' => 'Int' ], | ||
'description' => __( 'Ensure result set excludes specific IDs.', 'wp-graphql-woocommerce' ), | ||
], | ||
'include' => [ | ||
'type' => [ 'list_of' => 'Int' ], | ||
'description' => __( 'Limit result set to specific ids.', 'wp-graphql-woocommerce' ), | ||
], | ||
'sku' => [ | ||
'type' => 'String', | ||
'description' => __( 'Limit result set to products with specific SKU(s). Use commas to separate.', 'wp-graphql-woocommerce' ), | ||
], | ||
'featured' => [ | ||
'type' => 'Boolean', | ||
'description' => __( 'Limit result set to featured products.', 'wp-graphql-woocommerce' ), | ||
], | ||
'parentIn' => [ | ||
'type' => [ 'list_of' => 'Int' ], | ||
'description' => __( 'Specify objects whose parent is in an array.', 'wp-graphql-woocommerce' ), | ||
], | ||
'parentNotIn' => [ | ||
'type' => [ 'list_of' => 'Int' ], | ||
'description' => __( 'Specify objects whose parent is not in an array.', 'wp-graphql-woocommerce' ), | ||
], | ||
'categoryIn' => [ | ||
'type' => [ 'list_of' => 'String' ], | ||
'description' => __( 'Limit result set to products assigned to a group of specific categories by name.', 'wp-graphql-woocommerce' ), | ||
], | ||
'categoryIdIn' => [ | ||
'type' => [ 'list_of' => 'Int' ], | ||
'description' => __( 'Limit result set to products assigned to a specific group of category IDs.', 'wp-graphql-woocommerce' ), | ||
], | ||
'tagIn' => [ | ||
'type' => [ 'list_of' => 'String' ], | ||
'description' => __( 'Limit result set to products assigned to a specific group of tags by name.', 'wp-graphql-woocommerce' ), | ||
], | ||
'tagIdIn' => [ | ||
'type' => [ 'list_of' => 'Int' ], | ||
'description' => __( 'Limit result set to products assigned to a specific group of tag IDs.', 'wp-graphql-woocommerce' ), | ||
], | ||
'attributes' => [ | ||
'type' => [ 'list_of' => 'ProductAttributeFilterInput' ], | ||
'description' => __( 'Limit result set to products with a specific attribute. Use the taxonomy name/attribute slug.', 'wp-graphql-woocommerce' ), | ||
], | ||
'stockStatus' => [ | ||
'type' => [ 'list_of' => 'StockStatusEnum' ], | ||
'description' => __( 'Limit result set to products in stock or out of stock.', 'wp-graphql-woocommerce' ), | ||
], | ||
'onSale' => [ | ||
'type' => 'Boolean', | ||
'description' => __( 'Limit result set to products on sale.', 'wp-graphql-woocommerce' ), | ||
], | ||
'minPrice' => [ | ||
'type' => 'Float', | ||
'description' => __( 'Limit result set to products based on a minimum price.', 'wp-graphql-woocommerce' ), | ||
], | ||
'maxPrice' => [ | ||
'type' => 'Float', | ||
'description' => __( 'Limit result set to products based on a maximum price.', 'wp-graphql-woocommerce' ), | ||
], | ||
'visibility' => [ | ||
'type' => 'CatalogVisibilityEnum', | ||
'description' => __( 'Limit result set to products with a specific visibility level.', 'wp-graphql-woocommerce' ), | ||
], | ||
'rating' => [ | ||
'type' => [ 'list_of' => 'Integer' ], | ||
'description' => __( 'Limit result set to products with a specific average rating. Must be between 1 and 5', 'wp-graphql-woocommerce' ), | ||
], | ||
], | ||
] | ||
); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
includes/type/input/class-product-attribute-filter-input.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
* WPInputObjectType - ProductAttributeFilterInput | ||
* | ||
* @package WPGraphQL\WooCommerce\Type\WPInputObject | ||
* @since TBD | ||
*/ | ||
|
||
namespace WPGraphQL\WooCommerce\Type\WPInputObject; | ||
|
||
/** | ||
* Class Product_Attribute_Filter_Input | ||
*/ | ||
class Product_Attribute_Filter_Input { | ||
/** | ||
* Registers type | ||
* | ||
* @return void | ||
*/ | ||
public static function register() { | ||
register_graphql_input_type( | ||
'ProductAttributeFilterInput', | ||
[ | ||
'description' => __( 'Product filter', 'wp-graphql-woocommerce' ), | ||
'fields' => [ | ||
'taxonomy' => [ | ||
'type' => [ 'non_null' => 'ProductAttributeEnum' ], | ||
'description' => __( 'Which field to select taxonomy term by.', 'wp-graphql-woocommerce' ), | ||
], | ||
'terms' => [ | ||
'type' => [ 'list_of' => 'String' ], | ||
'description' => __( 'A list of term slugs', 'wp-graphql-woocommerce' ), | ||
], | ||
'ids' => [ | ||
'type' => [ 'list_of' => 'Int' ], | ||
'description' => __( 'A list of term ids', 'wp-graphql-woocommerce' ), | ||
], | ||
'operator' => [ | ||
'type' => 'AttributeOperatorEnum', | ||
'description' => __( 'Filter operation type', 'wp-graphql-woocommerce' ), | ||
], | ||
], | ||
] | ||
); | ||
} | ||
} |
Oops, something went wrong.