• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wp-graphql / wp-graphql-woocommerce / 10274605810

06 Aug 2024 10:07PM UTC coverage: 84.595% (-0.5%) from 85.048%
10274605810

push

github

web-flow
fix: product connection resolution refactored to better work with the ProductQuery class (#880)

* fix: product connection resolution refactored to better work with the ProductQuery class

* chore: Linter and PHPStan compliance met

* devops: New product connection tests implemented and passing

* fix: products connection pricing filters fixed

* devops: CartTransactionQueueCest skipped until failing PHP version removed from CI matrix

69 of 81 new or added lines in 12 files covered. (85.19%)

138 existing lines in 7 files now uncovered.

12416 of 14677 relevant lines covered (84.59%)

71.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/includes/data/class-db-hooks.php
1
<?php
2
/**
3
 * Register hooks for the filtering DB queries.
4
 *
5
 * @package WPGraphQL\WooCommerce\Data
6
 * @since 0.14.0
7
 */
8

9
namespace WPGraphQL\WooCommerce\Data;
10

11
use Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableDataStore;
12

13
/**
14
 * Class DB_Hooks
15
 */
16
class DB_Hooks {
17
        /**
18
         * DB_Hooks constructor.
19
         */
20
        public function __construct() {
21
                add_filter( 'woocommerce_orders_table_query_clauses', [ $this, 'add_cursor' ], 10, 3 );
×
22
        }
23

24
        /**
25
         * Add the cursor to the WHERE clause of the query.
26
         *
27
         * @param string[]                                                            $clauses {
28
         *                                                        Associative array of the clauses for the query.
29
         *
30
         *     @type string $fields  The SELECT clause of the query.
31
         *     @type string $join    The JOIN clause of the query.
32
         *     @type string $where   The WHERE clause of the query.
33
         *     @type string $groupby The GROUP BY clause of the query.
34
         *     @type string $orderby The ORDER BY clause of the query.
35
         *     @type string $limits  The LIMIT clause of the query.
36
         * }
37
         * @param \Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableQuery $query The OrdersTableQuery instance (passed by reference).
38
         * @param array                                                               $args  Query args.
39
         *
40
         * @return string[]
41
         */
42
        public function add_cursor( $clauses, $query, $args ) {
UNCOV
43
                if ( true !== is_graphql_request() ) {
×
UNCOV
44
                        return $clauses;
×
45
                }
46

47
                /** @var \Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableDataStore $order_datastore */
UNCOV
48
                $order_datastore = wc_get_container()->get( OrdersTableDataStore::class );
×
UNCOV
49
                $tables          = $order_datastore::get_all_table_names_with_id();
×
50

51
                // apply the after cursor to the query.
UNCOV
52
                if ( ! empty( $args['graphql_after_cursor'] ) ) {
×
UNCOV
53
                        $after_cursor      = new Cursor\COT_Cursor( $args, $query, 'after' );
×
UNCOV
54
                        $clauses['where'] .= $after_cursor->get_where();
×
55
                }
56

57
                // apply the before cursor to the query.
UNCOV
58
                if ( ! empty( $args['graphql_before_cursor'] ) ) {
×
UNCOV
59
                        $before_cursor     = new Cursor\COT_Cursor( $args, $query, 'before' );
×
UNCOV
60
                        $clauses['where'] .= $before_cursor->get_where();
×
61
                }
62

63
                // If the cursor "graphql_cursor_compare" arg is not in the query,
64
                // default to using ID DESC as the stabilizer.
UNCOV
65
                $orderby = ! empty( $clauses['orderby'] ) && is_string( $clauses['orderby'] )
×
UNCOV
66
                        ? $clauses['orderby'] . ','
×
UNCOV
67
                        : '';
×
68

UNCOV
69
                if ( ! isset( $args['graphql_cursor_compare'] ) ) {
×
UNCOV
70
                        $clauses['orderby'] = "{$orderby} {$tables['orders']}.id DESC ";
×
71
                } else {
72
                        // Check the cursor compare order.
UNCOV
73
                        $order = '>' === $args['graphql_cursor_compare'] ? 'ASC' : 'DESC';
×
74

UNCOV
75
                        $clauses['orderby'] = "{$orderby} {$tables['orders']}.id {$order} ";
×
76
                }
77

UNCOV
78
                return $clauses;
×
79
        }
80
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc