diff --git a/CHANGELOG.md b/CHANGELOG.md index 70b6cc0..7121eec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## [Unreleased] +- fix: Fix type conflicts on Product interfaces in WooGraphQL 0.21.1+. Props @robbiebel 🙌 - chore: bump PHPStan to v2.0.x - chore: Test compatibility with WordPress 6.8 and WPGraphQL 2.3. - chore: Update Composer dev-dependencies and lint. diff --git a/bin/_lib.sh b/bin/_lib.sh index b8a0095..f222231 100644 --- a/bin/_lib.sh +++ b/bin/_lib.sh @@ -98,11 +98,19 @@ install_woographql() { echo "Installing WooCommerce..." if ! $(wp plugin is-installed woocommerce); then - wp plugin install woocommerce --activate + wp plugin install woocommerce --activate --allow-root fi if ! $(wp plugin is-installed wp-graphql-woocommerce); then - wp plugin install https://github.com/wp-graphql/wp-graphql-woocommerce/releases/download/v0.21.0/wp-graphql-woocommerce.zip --activate + wp plugin install https://github.com/wp-graphql/wp-graphql-woocommerce/archive/refs/heads/master.zip --allow-root + cd $WP_CORE_DIR/wp-content/plugins/wp-graphql-woocommerce + + if [ ! -d vendor ]; then + composer install --no-dev + fi + + wp plugin activate wp-graphql-woocommerce --allow-root + fi } diff --git a/src/Extensions/WPGraphQLWooCommerce/Type/WPObject/SeoObjects.php b/src/Extensions/WPGraphQLWooCommerce/Type/WPObject/SeoObjects.php index 30d3643..4ea84be 100644 --- a/src/Extensions/WPGraphQLWooCommerce/Type/WPObject/SeoObjects.php +++ b/src/Extensions/WPGraphQLWooCommerce/Type/WPObject/SeoObjects.php @@ -35,11 +35,46 @@ public static function init(): void { public static function register(): void { // Set SEO field types for product children. $product_types = WP_GraphQL_WooCommerce::get_enabled_product_types(); + /** + * @todo: remove this when we don't need to support WooGraphQL< 0.21.1 + * @see https://github.com/AxeWP/wp-graphql-rank-math/pull/115#issuecomment-2660900767 + */ + if ( defined( 'WPGRAPHQL_WOOCOMMERCE_VERSION' ) && version_compare( WPGRAPHQL_WOOCOMMERCE_VERSION, '0.21.1', '>=' ) ) { + $product_types = array_merge( + $product_types, + [ + 'DownloadableProduct', + 'InventoriedProduct', + 'ProductUnion', + 'ProductWithAttributes', + 'ProductWithDimensions', + 'ProductWithPricing', + 'ProductWithVariations', + 'ProductVariation', + ] + ); + } foreach ( $product_types as $graphql_type_name ) { Utils::overload_graphql_field_type( $graphql_type_name, 'seo', 'RankMathProductObjectSeo' ); } + /** + * @todo: remove this when we don't need to support WooGraphQL< 0.21.1 + * @see https://github.com/AxeWP/wp-graphql-rank-math/pull/115#issuecomment-2660900767 + */ + if ( defined( 'WPGRAPHQL_WOOCOMMERCE_VERSION' ) && version_compare( WPGRAPHQL_WOOCOMMERCE_VERSION, '0.21.1', '<' ) ) { + self::register_product_variation_types(); + } + } + + /** + * Registers the SEO types for product variations. + * + * @todo: remove this when we don't need to support WooGraphQL< 0.21.1 + * @see https://github.com/AxeWP/wp-graphql-rank-math/pull/115#issuecomment-2660900767 + */ + private static function register_product_variation_types(): void { // Register the Product Variation SEO type and apply it to the Product Variation and children. $type_name_for_product_variation = 'RankMathProductVariationObjectSeo';