Skip to content

Commit 3bd3ede

Browse files
fix: interface conflicts with WooGraphQL v0.21.1+ (#120)
* Fix WooGraphQL Product Type Expectations * chore: phpcbf * dev: add b/c with WooGraphQL < 0.21.1 * fix: add `ProductVariation` to woo product types * chore: update changelog * ci: bump woographql testing version --------- Co-authored-by: Rob Belfort <[email protected]>
1 parent ff44b44 commit 3bd3ede

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## [Unreleased]
44

5+
- fix: Fix type conflicts on Product interfaces in WooGraphQL 0.21.1+. Props @robbiebel 🙌
56
- chore: bump PHPStan to v2.0.x
67
- chore: Test compatibility with WordPress 6.8 and WPGraphQL 2.3.
78
- chore: Update Composer dev-dependencies and lint.

bin/_lib.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,19 @@ install_woographql() {
9898

9999
echo "Installing WooCommerce..."
100100
if ! $(wp plugin is-installed woocommerce); then
101-
wp plugin install woocommerce --activate
101+
wp plugin install woocommerce --activate --allow-root
102102
fi
103103

104104
if ! $(wp plugin is-installed wp-graphql-woocommerce); then
105-
wp plugin install https://github.com/wp-graphql/wp-graphql-woocommerce/releases/download/v0.21.0/wp-graphql-woocommerce.zip --activate
105+
wp plugin install https://github.com/wp-graphql/wp-graphql-woocommerce/archive/refs/heads/master.zip --allow-root
106+
cd $WP_CORE_DIR/wp-content/plugins/wp-graphql-woocommerce
107+
108+
if [ ! -d vendor ]; then
109+
composer install --no-dev
110+
fi
111+
112+
wp plugin activate wp-graphql-woocommerce --allow-root
113+
106114
fi
107115
}
108116

src/Extensions/WPGraphQLWooCommerce/Type/WPObject/SeoObjects.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,46 @@ public static function init(): void {
3535
public static function register(): void {
3636
// Set SEO field types for product children.
3737
$product_types = WP_GraphQL_WooCommerce::get_enabled_product_types();
38+
/**
39+
* @todo: remove this when we don't need to support WooGraphQL< 0.21.1
40+
* @see https://github.com/AxeWP/wp-graphql-rank-math/pull/115#issuecomment-2660900767
41+
*/
42+
if ( defined( 'WPGRAPHQL_WOOCOMMERCE_VERSION' ) && version_compare( WPGRAPHQL_WOOCOMMERCE_VERSION, '0.21.1', '>=' ) ) {
43+
$product_types = array_merge(
44+
$product_types,
45+
[
46+
'DownloadableProduct',
47+
'InventoriedProduct',
48+
'ProductUnion',
49+
'ProductWithAttributes',
50+
'ProductWithDimensions',
51+
'ProductWithPricing',
52+
'ProductWithVariations',
53+
'ProductVariation',
54+
]
55+
);
56+
}
3857

3958
foreach ( $product_types as $graphql_type_name ) {
4059
Utils::overload_graphql_field_type( $graphql_type_name, 'seo', 'RankMathProductObjectSeo' );
4160
}
4261

62+
/**
63+
* @todo: remove this when we don't need to support WooGraphQL< 0.21.1
64+
* @see https://github.com/AxeWP/wp-graphql-rank-math/pull/115#issuecomment-2660900767
65+
*/
66+
if ( defined( 'WPGRAPHQL_WOOCOMMERCE_VERSION' ) && version_compare( WPGRAPHQL_WOOCOMMERCE_VERSION, '0.21.1', '<' ) ) {
67+
self::register_product_variation_types();
68+
}
69+
}
70+
71+
/**
72+
* Registers the SEO types for product variations.
73+
*
74+
* @todo: remove this when we don't need to support WooGraphQL< 0.21.1
75+
* @see https://github.com/AxeWP/wp-graphql-rank-math/pull/115#issuecomment-2660900767
76+
*/
77+
private static function register_product_variation_types(): void {
4378
// Register the Product Variation SEO type and apply it to the Product Variation and children.
4479
$type_name_for_product_variation = 'RankMathProductVariationObjectSeo';
4580

0 commit comments

Comments
 (0)