Skip to content

Commit

Permalink
fix: collectionStats query completed and tested.
Browse files Browse the repository at this point in the history
  • Loading branch information
kidunot89 committed Sep 22, 2023
1 parent 786efef commit c556ab7
Show file tree
Hide file tree
Showing 8 changed files with 495 additions and 63 deletions.
1 change: 1 addition & 0 deletions includes/class-type-registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function init() {
Type\WPInputObject\Product_Taxonomy_Input::register();
Type\WPInputObject\Orderby_Inputs::register();
Type\WPInputObject\Collection_Stats_Query_Input::register();
Type\WPInputObject\Collection_Stats_Where_Args::register();

/**
* Interfaces.
Expand Down
1 change: 1 addition & 0 deletions includes/class-wp-graphql-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ private function includes() {
require $include_directory_path . 'type/input/class-shipping-line-input.php';
require $include_directory_path . 'type/input/class-tax-rate-connection-orderby-input.php';
require $include_directory_path . 'type/input/class-collection-stats-query-input.php';
require $include_directory_path . 'type/input/class-collection-stats-where-args.php';

// Include mutation type class files.
require $include_directory_path . 'mutation/class-cart-add-fee.php';
Expand Down
4 changes: 4 additions & 0 deletions includes/connection/class-products.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,10 @@ public static function get_connection_args( $extra_args = [] ): array {
'type' => 'Boolean',
'description' => __( 'Include variations in the result set.', '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' ),
],
];

if ( wc_tax_enabled() ) {
Expand Down
14 changes: 14 additions & 0 deletions includes/data/connection/class-product-connection-resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,18 @@ public function sanitize_input_fields( array $where_args ) {
}//end switch
}//end if

if ( ! empty( $where_args['rating'] ) ) {
$rating_terms = [];
foreach ( $rating as $value ) {

Check failure on line 471 in includes/data/connection/class-product-connection-resolver.php

View workflow job for this annotation

GitHub Actions / Testing WooGraphQL code quality w/ PHPStan

Undefined variable: $rating
$rating_terms[] = 'rated-' . $value;
}
$tax_query[] = [
'taxonomy' => 'product_visibility',
'field' => 'name',
'terms' => $rating_terms,
];
}

// Process "taxonomyFilter".
$tax_filter_query = [];
if ( ! empty( $where_args['taxonomyFilter'] ) ) {
Expand Down Expand Up @@ -563,6 +575,8 @@ public function sanitize_input_fields( array $where_args ) {
$query_args[ $on_sale_key ] = $on_sale_ids;
}



/**
* {@inheritDoc}
*/
Expand Down
110 changes: 110 additions & 0 deletions includes/type/input/class-collection-stats-where-args.php
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' => 'ProductTaxonomyFilterInput' ],
'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' ),
],
],
]
);
}
}
Loading

0 comments on commit c556ab7

Please sign in to comment.