mirror of
https://github.com/wp-graphql/wp-graphql-woocommerce.git
synced 2026-08-14 12:53:44 +02:00
* fix: address WordPress.org plugin review feedback - Prefix the session transaction queue transient with the plugin's graphql_woocommerce_ namespace instead of the generic "woo_" word, to avoid collisions (Plugin Directory: prefix data storage). - Declare the WooCommerce dependency via the "Requires Plugins: woocommerce" plugin header. - Bump README.txt "Tested up to" to 7.0. - Ship composer.json in the distributed plugin (drop it, and composer.lock, from composer archive excludes) so the build is reproducible/reviewable. * chore: rename plugin to "GraphQL for eCommerce" for trademark compliance The WordPress.org plugin review flagged the display name/slug for beginning with the "WPGraphQL" trademark (and the "WooGraphQL" portmanteau of the WooCommerce mark), which can imply official affiliation. - Display name (plugin header + readme title) -> "GraphQL for eCommerce". - Slug/text domain -> "graphql-for-ecommerce" (header, all i18n string literals, and the PHPCS WordPress.WP.I18n text_domain config). - Update user-facing notices/errors that named the old plugin. "WooGraphQL" remains the project's informal nickname (repo, docs, community), just not in the WordPress.org directory's official name/slug. Internal file names and GitHub URLs are unchanged. * fix: keep test-only dev deps out of the committed composer.json The committed manifest mirrors develop (lint/stan dev deps only); CI adds the test suite deps at runtime via `composer installTestEnv`. A previous commit captured the installTestEnv-modified composer.json, desyncing it from composer.lock and breaking `composer install` in CI. * chore: regenerate composer.lock (refresh dev dependencies) Regenerate the lock from the manifest so it is in sync (fixes the CI `composer install` failure) and refresh dependencies in the process — firebase/php-jwt v7.0.4 -> v7.1.0 plus 11 others, with vendor-prefixed re-strauss'd to match. Full wpunit suite passes against the updated deps (305 tests, 835 assertions). * chore: rename text domain in createdVia/attribution strings from #1018 #1018 (createdVia + order attribution) merged into develop after the rename commit was authored, so its new i18n strings still used the old 'wp-graphql-woocommerce' text domain. Update them to 'graphql-for-ecommerce' to match the rename.
118 lines
3.6 KiB
PHP
118 lines
3.6 KiB
PHP
<?php
|
|
/**
|
|
* Connection type - Comments
|
|
*
|
|
* Registers connections to comments from woocommerce post-types
|
|
*
|
|
* @package WPGraphQL\WooCommerce\Connection
|
|
* @since 0.3.2
|
|
*/
|
|
|
|
namespace WPGraphQL\WooCommerce\Connection;
|
|
|
|
use GraphQL\Type\Definition\ResolveInfo;
|
|
use WPGraphQL\AppContext;
|
|
use WPGraphQL\Type\Connection\Comments as Comments_Core;
|
|
|
|
/**
|
|
* Class - Comments
|
|
*/
|
|
class Comments extends Comments_Core {
|
|
/**
|
|
* Registers connection.
|
|
*/
|
|
public static function register_connections() {
|
|
// From Products.
|
|
register_graphql_connection(
|
|
self::get_connection_config(
|
|
[
|
|
'fromType' => 'Product',
|
|
'toType' => 'Comment',
|
|
'fromFieldName' => 'reviews',
|
|
'connectionFields' => [
|
|
'averageRating' => [
|
|
'type' => 'Float',
|
|
'description' => static function () {
|
|
return __( 'Average review rating for this product.', 'graphql-for-ecommerce' );
|
|
},
|
|
'resolve' => static function ( $source ) {
|
|
if ( empty( $source['edges'] ) ) {
|
|
return 0;
|
|
}
|
|
$product = $source['edges'][0]['source'];
|
|
return $product->averageRating; // @codingStandardsIgnoreLine
|
|
},
|
|
],
|
|
],
|
|
'edgeFields' => [
|
|
'rating' => [
|
|
'type' => 'Float',
|
|
'description' => static function () {
|
|
return __( 'Review rating', 'graphql-for-ecommerce' );
|
|
},
|
|
'resolve' => static function ( $source ) {
|
|
$review = $source['node'];
|
|
// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
|
|
$rating = get_comment_meta( $review->commentId, 'rating', true );
|
|
return $rating ? $rating : 0;
|
|
},
|
|
],
|
|
],
|
|
'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) {
|
|
$resolver = new \WPGraphQL\Data\Connection\CommentConnectionResolver( $source, $args, $context, $info );
|
|
|
|
$resolver->set_query_arg( 'post_type', 'product' );
|
|
$resolver->set_query_arg( 'post_id', $source->ID );
|
|
|
|
return $resolver->get_connection();
|
|
},
|
|
]
|
|
)
|
|
);
|
|
|
|
// From Orders.
|
|
register_graphql_connection(
|
|
self::get_connection_config(
|
|
[
|
|
'fromType' => 'Order',
|
|
'toType' => 'OrderNote',
|
|
'fromFieldName' => 'orderNotes',
|
|
'edgeFields' => [
|
|
'isCustomerNote' => [
|
|
'type' => 'Boolean',
|
|
'description' => static function () {
|
|
return __( 'Is this a customer note?', 'graphql-for-ecommerce' );
|
|
},
|
|
'resolve' => static function ( $source ) {
|
|
$note = $source['node'];
|
|
// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
|
|
return get_comment_meta( $note->commentId, 'is_customer_note', true );
|
|
},
|
|
],
|
|
],
|
|
'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) {
|
|
$resolver = new \WPGraphQL\Data\Connection\CommentConnectionResolver( $source, $args, $context, $info );
|
|
|
|
$resolver->set_query_arg( 'post_id', $source->ID );
|
|
$resolver->set_query_arg( 'approve', 'approve' );
|
|
$resolver->set_query_arg( 'type', '' );
|
|
|
|
if ( ! current_user_can( 'edit_shop_orders', $source->ID ) ) {
|
|
$resolver->set_query_arg( 'meta_key', 'is_customer_note' );
|
|
$resolver->set_query_arg( 'meta_value', true );
|
|
}
|
|
|
|
remove_filter( 'comments_clauses', [ 'WC_Comments', 'exclude_order_comments' ] );
|
|
|
|
$connection = $resolver->get_connection();
|
|
|
|
add_filter( 'comments_clauses', [ 'WC_Comments', 'exclude_order_comments' ] );
|
|
|
|
return $connection;
|
|
},
|
|
]
|
|
)
|
|
);
|
|
}
|
|
}
|