Skip to content

Commit 81502f9

Browse files
authored
fix: ProductUnion interface added (#797)
* fix: ProductUnion interface added * chore: Linter and PHPStan compliance met
1 parent 277cef0 commit 81502f9

12 files changed

+132
-407
lines changed

access-functions.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,45 @@
66
* @since 0.0.1
77
*/
88

9-
if ( ! function_exists( 'wc_graphql_starts_with' ) ) {
9+
if ( ! function_exists( 'str_starts_with' ) ) {
1010
/**
11-
* Checks if source string starts with the target string
11+
* Polyfill for PHP 8 str_starts_with function.
12+
* Checks if a string starts with a given substring.
13+
*
14+
* @see https://www.php.net/manual/en/function.str-starts-with.php
1215
*
1316
* @param string $haystack - Source string.
1417
* @param string $needle - Target string.
1518
*
16-
* @return bool
19+
* @return bool - True if $haystack starts with $needle, false otherwise.
1720
*/
18-
function wc_graphql_starts_with( $haystack, $needle ) {
21+
function str_starts_with( $haystack, $needle ) {
1922
$length = strlen( $needle );
2023
return ( substr( $haystack, 0, $length ) === $needle );
2124
}
2225
}
2326

24-
if ( ! function_exists( 'wc_graphql_ends_with' ) ) {
27+
if ( ! function_exists( 'str_ends_with' ) ) {
2528
/**
26-
* Checks if source string ends with the target string
29+
* Polyfill for PHP 8 str_ends_with function.
30+
* Checks if a string ends with a given substring.
31+
*
32+
* @see https://www.php.net/manual/en/function.str-ends-with.php
2733
*
2834
* @param string $haystack - Source string.
2935
* @param string $needle - Target string.
3036
*
31-
* @return bool
37+
* @return bool - True if $haystack ends with $needle, false otherwise.
3238
*/
33-
function wc_graphql_ends_with( $haystack, $needle ) {
39+
function str_ends_with( $haystack, $needle ) {
3440
$length = strlen( $needle );
3541
if ( 0 === $length ) {
3642
return true;
3743
}
3844

3945
return ( substr( $haystack, -$length ) === $needle );
4046
}
41-
}
47+
}//end if
4248

4349
if ( ! function_exists( 'wc_graphql_map_tax_statements' ) ) {
4450
/**

includes/class-core-schema-filters.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,6 @@ public static function add_filters() {
9292
7
9393
);
9494

95-
add_filter(
96-
'graphql_map_input_fields_to_wp_query',
97-
[ '\WPGraphQL\WooCommerce\Connection\Products', 'map_input_fields_to_wp_query' ],
98-
10,
99-
7
100-
);
101-
10295
add_filter(
10396
'graphql_map_input_fields_to_wp_user_query',
10497
[ '\WPGraphQL\WooCommerce\Connection\Customers', 'map_input_fields_to_wp_query' ],

includes/class-type-registry.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public function init() {
6969
Type\WPInterface\Product_Attribute::register_interface();
7070
Type\WPInterface\Cart_Error::register_interface();
7171
Type\WPInterface\Payment_Token::register_interface();
72+
Type\WPInterface\Product_Union::register_interface();
7273

7374
/**
7475
* Objects.

includes/class-wp-graphql-woocommerce.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,23 @@ public static function get_enabled_product_types() {
7474
return apply_filters(
7575
'graphql_woocommerce_product_types',
7676
[
77-
'simple' => 'SimpleProduct',
78-
'variable' => 'VariableProduct',
79-
'external' => 'ExternalProduct',
80-
'grouped' => 'GroupProduct',
81-
'variation' => 'ProductVariation',
77+
'simple' => 'SimpleProduct',
78+
'variable' => 'VariableProduct',
79+
'external' => 'ExternalProduct',
80+
'grouped' => 'GroupProduct',
8281
]
8382
);
8483
}
8584

85+
/**
86+
* Returns WooCommerce product variation types to be exposed to the GraphQL schema.
87+
*
88+
* @return array
89+
*/
90+
public static function get_enabled_product_variation_types() {
91+
return apply_filters( 'graphql_woocommerce_product_variation_types', [ 'variation' => 'ProductVariation' ] );
92+
}
93+
8694
/**
8795
* Returns GraphQL Product Type name for product types not supported by the GraphQL schema.
8896
*
@@ -235,6 +243,7 @@ private function includes() {
235243
require $include_directory_path . 'type/interface/class-product-attribute.php';
236244
require $include_directory_path . 'type/interface/class-product.php';
237245
require $include_directory_path . 'type/interface/class-payment-token.php';
246+
require $include_directory_path . 'type/interface/class-product-union.php';
238247

239248
// Include object type class files.
240249
require $include_directory_path . 'type/object/class-cart-error-types.php';

0 commit comments

Comments
 (0)