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

wp-graphql / wp-graphql-woocommerce / 13569823583

27 Feb 2025 03:22PM UTC coverage: 83.617% (-0.07%) from 83.69%
13569823583

push

github

web-flow
fix: Better support for private and password protected products implemented (#925)

25 of 67 new or added lines in 5 files covered. (37.31%)

1 existing line in 1 file now uncovered.

12428 of 14863 relevant lines covered (83.62%)

72.2 hits per line

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

91.54
/includes/model/class-product.php
1
<?php
2
/**
3
 * Model - Product
4
 *
5
 * Resolves product crud object model
6
 *
7
 * @package WPGraphQL\WooCommerce\Model
8
 * @since 0.0.1
9
 */
10

11
namespace WPGraphQL\WooCommerce\Model;
12

13
use GraphQLRelay\Relay;
14

15
/**
16
 * Class Product
17
 *
18
 * @property \WC_Product   $wc_data
19
 * @property \WP_Post_Type $post_type_object
20
 *
21
 * @property int           $ID
22
 * @property string        $id
23
 * @property string        $type
24
 * @property string        $slug
25
 * @property string        $name
26
 * @property string        $date
27
 * @property string        $modified
28
 * @property string        $status
29
 * @property bool          $featured
30
 * @property string        $description
31
 * @property string        $descriptionRaw
32
 * @property string        $shortDescription
33
 * @property string        $shortDescriptionRaw
34
 * @property string        $sku
35
 * @property string        $dateOnSaleFrom
36
 * @property string        $dateOnSaleTo
37
 * @property bool          $reviewsAllowed
38
 * @property string        $purchaseNote
39
 * @property int           $menuOrder
40
 * @property float         $averageRating
41
 * @property int           $reviewCount
42
 * @property bool          $onSale
43
 * @property bool          $purchasable
44
 * @property string        $catalogVisibility
45
 * @property int           $totalSales
46
 *
47
 * @property array         $upsell_ids
48
 * @property array         $attributes
49
 * @property array         $default_attributes
50
 * @property int           $image_id
51
 * @property int[]         $gallery_image_ids
52
 * @property int[]         $category_ids
53
 * @property int[]         $tag_ids
54
 * @property int           $parent_id
55
 *
56
 * @property bool          $manageStock
57
 * @property int           $stockQuantity
58
 * @property string        $backorders
59
 * @property bool          $backordersAllowed
60
 * @property bool          $soldIndividually
61
 * @property float         $weight
62
 * @property float         $length
63
 * @property float         $width
64
 * @property float         $height
65
 * @property int           $shippingClassId
66
 * @property bool          $shippingRequired
67
 * @property bool          $shippingTaxable
68
 * @property array         $cross_sell_ids
69
 * @property string        $stockStatus
70
 *
71
 * @property bool          $virtual
72
 * @property int           $downloadExpiry
73
 * @property bool          $downloadable
74
 * @property int           $downloadLimit
75
 * @property array         $downloads
76
 *
77
 * @property string        $price
78
 * @property float|float[] $priceRaw
79
 * @property string        $regularPrice
80
 * @property float|float[] $regularPriceRaw
81
 * @property string        $salePrice
82
 * @property float|float[] $salePriceRaw
83
 * @property string        $taxStatus
84
 * @property string        $taxClass
85
 *
86
 * @property string        $externalUrl
87
 * @property string        $buttonText
88
 *
89
 * @property string        $addToCartText
90
 * @property string        $addToCartDescription
91
 * @property int[]         $grouped_ids
92
 *
93
 * @property int[]         $variation_ids
94
 *
95
 * @package WPGraphQL\WooCommerce\Model
96
 */
97
class Product extends WC_Post {
98
        /**
99
         * Stores the product type: external, grouped, simple, variable.
100
         *
101
         * @var string
102
         */
103
        protected $product_type;
104

105
        /**
106
         * Stores product factory.
107
         *
108
         * @var \WC_Product_Factory|null
109
         */
110
        protected static $product_factory = null;
111

112
        /**
113
         * Product constructor.
114
         *
115
         * @param int|\WC_Data $id - product post-type ID.
116
         *
117
         * @throws \Exception  Failed to retrieve product data source.
118
         */
119
        public function __construct( $id ) {
120
                // Get WC_Product object.
121
                $data = \wc_get_product( $id );
61✔
122

123
                // Check if product is valid.
124
                if ( ! is_object( $data ) ) {
61✔
125
                        throw new \Exception( __( 'Failed to retrieve product data source', 'wp-graphql-woocommerce' ) );
×
126
                }
127

128
                parent::__construct( $data );
61✔
129
        }
130

131
        /**
132
         * {@inheritDoc}
133
         */
134
        protected static function get_allowed_restricted_fields( $allowed_restricted_fields = [] ) {
NEW
135
                return array_merge(
×
NEW
136
                        parent::get_allowed_restricted_fields(),
×
NEW
137
                        [ 'type' ]
×
NEW
138
                );
×
139
        }
140

141
        /**
142
         * Returns the product type.
143
         *
144
         * @return string
145
         */
146
        public function get_type() {
147
                return $this->wc_data->get_type();
61✔
148
        }
149

150
        /**
151
         * Returns string of variation price range.
152
         *
153
         * @param string  $pricing_type - Range selected pricing type.
154
         * @param boolean $raw          - Whether to return raw value.
155
         *
156
         * @return string|null
157
         */
158
        private function get_variation_price( $pricing_type = '', $raw = false ) {
159
                /**
160
                 * Variable product data source.
161
                 *
162
                 * @var \WC_Product_Variable $data
163
                 */
164
                $data = $this->wc_data;
1✔
165

166
                $prices = $data->get_variation_prices( true );
1✔
167

168
                if ( empty( $prices['price'] ) || ( 'sale' === $pricing_type && ! $this->wc_data->is_on_sale() ) ) {
1✔
169
                        return null;
1✔
170
                }
171

172
                switch ( $pricing_type ) {
173
                        case 'sale':
1✔
174
                                $prices = array_values( array_diff( $prices['sale_price'], $prices['regular_price'] ) );
×
175
                                break;
×
176
                        case 'regular':
1✔
177
                                $prices = $prices['regular_price'];
1✔
178
                                break;
1✔
179
                        default:
180
                                $prices = $prices['price'];
1✔
181
                                break;
1✔
182
                }
183

184
                sort( $prices, SORT_NUMERIC );
1✔
185
                graphql_debug( implode( ', ', $prices ) );
1✔
186

187
                if ( $raw ) {
1✔
188
                        return implode( ', ', $prices );
×
189
                }
190

191
                return wc_graphql_price_range( current( $prices ), end( $prices ) );
1✔
192
        }
193

194
        /**
195
         * Initializes the Product field resolvers
196
         *
197
         * @access protected
198
         */
199
        protected function init() {
200
                if ( empty( $this->fields ) ) {
61✔
201
                        parent::init();
61✔
202

203
                        $type   = $this->wc_data->get_type();
61✔
204
                        $fields = [
61✔
205
                                'ID'                  => function () {
61✔
206
                                        return ! empty( $this->wc_data->get_id() ) ? $this->wc_data->get_id() : null;
61✔
207
                                },
61✔
208
                                'id'                  => function () {
61✔
209
                                        return ! empty( $this->ID ) ? Relay::toGlobalId( 'post', "{$this->ID}" ) : null;
61✔
210
                                },
61✔
211
                                'type'                => function () {
61✔
212
                                        return ! empty( $this->wc_data->get_type() ) ? $this->wc_data->get_type() : null;
1✔
213
                                },
61✔
214
                                'slug'                => function () {
61✔
215
                                        return ! empty( $this->wc_data->get_slug() ) ? $this->wc_data->get_slug() : null;
3✔
216
                                },
61✔
217
                                'name'                => function () {
61✔
218
                                        return ! empty( $this->wc_data->get_name() ) ? html_entity_decode( $this->wc_data->get_name() ) : null;
4✔
219
                                },
61✔
220
                                'date'                => function () {
61✔
221
                                        return ! empty( $this->wc_data ) ? $this->wc_data->get_date_created() : null;
3✔
222
                                },
61✔
223
                                'modified'            => function () {
61✔
224
                                        return ! empty( $this->wc_data ) ? $this->wc_data->get_date_modified() : null;
3✔
225
                                },
61✔
226
                                'status'              => function () {
61✔
227
                                        return ! empty( $this->wc_data->get_status() ) ? $this->wc_data->get_status() : null;
3✔
228
                                },
61✔
229
                                'featured'            => function () {
61✔
230
                                        return $this->wc_data->get_featured();
2✔
231
                                },
61✔
232
                                'description'         => function () {
61✔
233
                                        return ! empty( $this->wc_data->get_description() )
3✔
234
                                                // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
3✔
235
                                                ? apply_filters( 'the_content', $this->wc_data->get_description() )
3✔
236
                                                : null;
3✔
237
                                },
61✔
238
                                'descriptionRaw'      => function () {
61✔
239
                                        return ! empty( $this->wc_data->get_description() ) ? $this->wc_data->get_description() : null;
2✔
240
                                },
61✔
241
                                'shortDescription'    => function () {
61✔
242
                                        $short_description = ! empty( $this->wc_data->get_short_description() )
2✔
243
                                        ? apply_filters(
2✔
244
                                                // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
245
                                                'get_the_excerpt',
2✔
246
                                                $this->wc_data->get_short_description(),
2✔
247
                                                get_post( $this->wc_data->get_id() )
2✔
248
                                        )
2✔
249
                                        : null;
×
250

251
                                        // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
252
                                        return apply_filters( 'the_excerpt', $short_description );
2✔
253
                                },
61✔
254
                                'shortDescriptionRaw' => function () {
61✔
255
                                        return ! empty( $this->wc_data->get_short_description() ) ? $this->wc_data->get_short_description() : null;
2✔
256
                                },
61✔
257
                                'sku'                 => function () {
61✔
258
                                        return ! empty( $this->wc_data->get_sku() ) ? $this->wc_data->get_sku() : null;
3✔
259
                                },
61✔
260
                                'dateOnSaleFrom'      => function () {
61✔
261
                                        return ! empty( $this->wc_data->get_date_on_sale_from() ) ? $this->wc_data->get_date_on_sale_from() : null;
2✔
262
                                },
61✔
263
                                'dateOnSaleTo'        => function () {
61✔
264
                                        return ! empty( $this->wc_data->get_date_on_sale_to() ) ? $this->wc_data->get_date_on_sale_to() : null;
2✔
265
                                },
61✔
266
                                'reviewsAllowed'      => function () {
61✔
267
                                        return ! empty( $this->wc_data->get_reviews_allowed() ) ? $this->wc_data->get_reviews_allowed() : null;
3✔
268
                                },
61✔
269
                                'purchaseNote'        => function () {
61✔
270
                                        return ! empty( $this->wc_data->get_purchase_note() ) ? $this->wc_data->get_purchase_note() : null;
2✔
271
                                },
61✔
272
                                'menuOrder'           => function () {
61✔
273
                                        return $this->wc_data->get_menu_order();
3✔
274
                                },
61✔
275
                                'averageRating'       => function () {
61✔
276
                                        return $this->wc_data->get_average_rating();
4✔
277
                                },
61✔
278
                                'reviewCount'         => function () {
61✔
279
                                        return $this->wc_data->get_review_count();
4✔
280
                                },
61✔
281
                                'onSale'              => function () {
61✔
282
                                        return $this->wc_data->is_on_sale();
2✔
283
                                },
61✔
284
                                'purchasable'         => function () {
61✔
285
                                        return $this->wc_data->is_purchasable();
2✔
286
                                },
61✔
287

288
                                /**
289
                                 * Editor/Shop Manager only fields
290
                                 */
291
                                'catalogVisibility'   => [
61✔
292
                                        'callback'   => function () {
61✔
293
                                                return ! empty( $this->wc_data->get_catalog_visibility() ) ? $this->wc_data->get_catalog_visibility() : null;
2✔
294
                                        },
61✔
295
                                        'capability' => $this->post_type_object->cap->edit_posts,
61✔
296
                                ],
61✔
297
                                'totalSales'          => [
61✔
298
                                        'callback'   => function () {
61✔
299
                                                return $this->wc_data->get_total_sales();
2✔
300
                                        },
61✔
301
                                        'capability' => $this->post_type_object->cap->edit_posts,
61✔
302
                                ],
61✔
303

304
                                /**
305
                                 * Connection resolvers fields
306
                                 *
307
                                 * These field resolvers are used in connection resolvers to define WP_Query argument
308
                                 * Note: underscore naming style is used as a quick identifier
309
                                 */
310
                                'upsell_ids'          => function () {
61✔
311
                                        return ! empty( $this->wc_data->get_upsell_ids() )
1✔
312
                                                ? array_map( 'absint', $this->wc_data->get_upsell_ids() )
1✔
313
                                                : [ '0' ];
1✔
314
                                },
61✔
315
                                'attributes'          => function () {
61✔
316
                                        return ! empty( $this->wc_data->get_attributes() ) ? $this->wc_data->get_attributes() : [];
3✔
317
                                },
61✔
318
                                'default_attributes'  => function () {
61✔
319
                                        return ! empty( $this->wc_data->get_default_attributes() ) ? $this->wc_data->get_default_attributes() : [ '0' ];
1✔
320
                                },
61✔
321
                                'image_id'            => function () {
61✔
322
                                        return ! empty( $this->wc_data->get_image_id() ) ? $this->wc_data->get_image_id() : null;
2✔
323
                                },
61✔
324
                                'gallery_image_ids'   => function () {
61✔
325
                                        return ! empty( $this->wc_data->get_gallery_image_ids() ) ? $this->wc_data->get_gallery_image_ids() : [ '0' ];
2✔
326
                                },
61✔
327
                                'category_ids'        => function () {
61✔
328
                                        return ! empty( $this->wc_data->get_category_ids() ) ? $this->wc_data->get_category_ids() : [ '0' ];
×
329
                                },
61✔
330
                                'tag_ids'             => function () {
61✔
331
                                        return ! empty( $this->wc_data->get_tag_ids() ) ? $this->wc_data->get_tag_ids() : [ '0' ];
×
332
                                },
61✔
333
                                'parent_id'           => function () {
61✔
334
                                        return ! empty( $this->wc_data->get_parent_id() ) ? $this->wc_data->get_parent_id() : null;
×
335
                                },
61✔
336
                                'post'                => function () {
61✔
337
                                        return ! empty( $this->wc_data->post ) ? $this->wc_data->post : null;
×
338
                                },
61✔
339
                        ];
61✔
340

341
                        if (
342
                                apply_filters(
61✔
343
                                        "graphql_{$type}_product_model_use_pricing_and_tax_fields",
61✔
344
                                        'grouped' !== $this->wc_data->get_type()
61✔
345
                                )
61✔
346
                        ) {
347
                                $fields += [
61✔
348
                                        'price'           => function () {
61✔
349
                                                return ! empty( $this->wc_data->get_price() )
7✔
350
                                                        ? wc_graphql_price( \wc_get_price_to_display( $this->wc_data ) )
7✔
351
                                                        : null;
7✔
352
                                        },
61✔
353
                                        'priceRaw'        => function () {
61✔
354
                                                return ! empty( $this->wc_data->get_price() ) ? $this->wc_data->get_price() : null;
×
355
                                        },
61✔
356
                                        'regularPrice'    => function () {
61✔
357
                                                return ! empty( $this->wc_data->get_regular_price() )
3✔
358
                                                        ? wc_graphql_price( \wc_get_price_to_display( $this->wc_data, [ 'price' => $this->wc_data->get_regular_price() ] ) )
3✔
359
                                                        : null;
3✔
360
                                        },
61✔
361
                                        'regularPriceRaw' => function () {
61✔
362
                                                return ! empty( $this->wc_data->get_regular_price() ) ? $this->wc_data->get_regular_price() : null;
×
363
                                        },
61✔
364
                                        'salePrice'       => function () {
61✔
365
                                                return ! empty( $this->wc_data->get_sale_price() )
2✔
366
                                                        ? wc_graphql_price(
×
367
                                                                \wc_get_price_to_display(
×
368
                                                                        $this->wc_data,
×
369
                                                                        [
×
370
                                                                                'price' => $this->wc_data->get_sale_price(),
×
371
                                                                        ]
×
372
                                                                )
×
373
                                                        )
×
374
                                                        : null;
2✔
375
                                        },
61✔
376
                                        'salePriceRaw'    => function () {
61✔
377
                                                return ! empty( $this->wc_data->get_sale_price() ) ? $this->wc_data->get_sale_price() : null;
×
378
                                        },
61✔
379
                                        'taxStatus'       => function () {
61✔
380
                                                return ! empty( $this->wc_data->get_tax_status() ) ? $this->wc_data->get_tax_status() : null;
2✔
381
                                        },
61✔
382
                                        'taxClass'        => function () {
61✔
383
                                                return $this->wc_data->get_tax_class();
2✔
384
                                        },
61✔
385
                                ];
61✔
386
                        }//end if
387

388
                        if (
389
                                apply_filters(
61✔
390
                                        "graphql_{$type}_product_model_use_inventory_fields",
61✔
391
                                        'simple' === $type || 'variable' === $type
61✔
392
                                )
61✔
393
                        ) {
394
                                $fields += [
58✔
395
                                        'manageStock'       => function () {
58✔
396
                                                return ! empty( $this->wc_data->get_manage_stock() ) ? $this->wc_data->get_manage_stock() : null;
2✔
397
                                        },
58✔
398
                                        'stockQuantity'     => function () {
58✔
399
                                                return ! empty( $this->wc_data->get_stock_quantity() ) ? $this->wc_data->get_stock_quantity() : null;
2✔
400
                                        },
58✔
401
                                        'backorders'        => function () {
58✔
402
                                                return ! empty( $this->wc_data->get_backorders() ) ? $this->wc_data->get_backorders() : null;
2✔
403
                                        },
58✔
404
                                        'backordersAllowed' => function () {
58✔
405
                                                return $this->wc_data->backorders_allowed();
2✔
406
                                        },
58✔
407
                                        'soldIndividually'  => function () {
58✔
408
                                                return $this->wc_data->is_sold_individually();
2✔
409
                                        },
58✔
410
                                        'lowStockAmount'    => function () {
58✔
411
                                                return ! empty( $this->wc_data->get_low_stock_amount() ) ? $this->wc_data->get_low_stock_amount() : null;
×
412
                                        },
58✔
413
                                        'weight'            => function () {
58✔
414
                                                return ! empty( $this->wc_data->get_weight() ) ? $this->wc_data->get_weight() : null;
2✔
415
                                        },
58✔
416
                                        'length'            => function () {
58✔
417
                                                return ! empty( $this->wc_data->get_length() ) ? $this->wc_data->get_length() : null;
2✔
418
                                        },
58✔
419
                                        'width'             => function () {
58✔
420
                                                return ! empty( $this->wc_data->get_width() ) ? $this->wc_data->get_width() : null;
2✔
421
                                        },
58✔
422
                                        'height'            => function () {
58✔
423
                                                return ! empty( $this->wc_data->get_height() ) ? $this->wc_data->get_height() : null;
2✔
424
                                        },
58✔
425
                                        'shippingClassId'   => function () {
58✔
426
                                                return ! empty( $this->wc_data->get_image_id() ) ? $this->wc_data->get_shipping_class_id() : null;
1✔
427
                                        },
58✔
428
                                        'shippingRequired'  => function () {
58✔
429
                                                return $this->wc_data->needs_shipping();
2✔
430
                                        },
58✔
431
                                        'shippingTaxable'   => function () {
58✔
432
                                                return $this->wc_data->is_shipping_taxable();
2✔
433
                                        },
58✔
434
                                        'cross_sell_ids'    => function () {
58✔
435
                                                return ! empty( $this->wc_data->get_cross_sell_ids() )
1✔
436
                                                        ? array_map( 'absint', $this->wc_data->get_cross_sell_ids() )
1✔
437
                                                        : [ '0' ];
1✔
438
                                        },
58✔
439
                                        'stockStatus'       => function () {
58✔
440
                                                return ! empty( $this->wc_data->get_stock_status() ) ? $this->wc_data->get_stock_status() : null;
3✔
441
                                        },
58✔
442
                                ];
58✔
443
                        }//end if
444

445
                        switch ( true ) {
446
                                case apply_filters( "graphql_{$type}_product_model_use_virtual_data_fields", 'simple' === $type ):
61✔
447
                                        $fields += [
47✔
448
                                                'virtual'        => function () {
47✔
449
                                                        return $this->wc_data->is_virtual();
2✔
450
                                                },
47✔
451
                                                'downloadExpiry' => function () {
47✔
452
                                                        return $this->wc_data->get_download_expiry();
2✔
453
                                                },
47✔
454
                                                'downloadable'   => function () {
47✔
455
                                                        return $this->wc_data->is_downloadable();
2✔
456
                                                },
47✔
457
                                                'downloadLimit'  => function () {
47✔
458
                                                        return ! empty( $this->wc_data->get_download_limit() ) ? $this->wc_data->get_download_limit() : null;
2✔
459
                                                },
47✔
460
                                                'downloads'      => function () {
47✔
461
                                                        return ! empty( $this->wc_data->get_downloads() ) ? $this->wc_data->get_downloads() : null;
1✔
462
                                                },
47✔
463
                                        ];
47✔
464
                                        break;
47✔
465
                                case apply_filters( "graphql_{$type}_product_model_use_variation_pricing_fields", 'variable' === $type ):
24✔
466
                                        $fields = [
19✔
467
                                                'price'           => function () {
19✔
468
                                                        return $this->get_variation_price();
1✔
469
                                                },
19✔
470
                                                'regularPrice'    => function () {
19✔
471
                                                        return $this->get_variation_price( 'regular' );
1✔
472
                                                },
19✔
473
                                                'salePrice'       => function () {
19✔
474
                                                        return $this->get_variation_price( 'sale' );
1✔
475
                                                },
19✔
476
                                                'variation_ids'   => function () {
19✔
477
                                                        return ! empty( $this->wc_data->get_children() )
2✔
478
                                                                ? array_map( 'absint', $this->wc_data->get_children() )
2✔
479
                                                                : [ '0' ];
2✔
480
                                                },
19✔
481
                                                'priceRaw'        => function () {
19✔
482
                                                        return $this->get_variation_price( '', true );
×
483
                                                },
19✔
484
                                                'regularPriceRaw' => function () {
19✔
485
                                                        return $this->get_variation_price( 'regular', true );
×
486
                                                },
19✔
487
                                                'salePriceRaw'    => function () {
19✔
488
                                                        return $this->get_variation_price( 'sale', true );
×
489
                                                },
19✔
490
                                        ] + $fields;
19✔
491
                                        break;
19✔
492
                                case apply_filters( "graphql_{$type}_product_model_use_external_fields", 'external' === $type ):
5✔
493
                                        $fields += [
2✔
494
                                                'externalUrl' => function () {
2✔
495
                                                        /**
496
                                                         * External product
497
                                                         *
498
                                                         * @var \WC_Product_External $data
499
                                                         */
500
                                                        $data = $this->wc_data;
1✔
501
                                                        return ! empty( $data->get_product_url() ) ? $data->get_product_url() : null;
1✔
502
                                                },
2✔
503
                                                'buttonText'  => function () {
2✔
504
                                                        /**
505
                                                         * External product
506
                                                         *
507
                                                         * @var \WC_Product_External $data
508
                                                         */
509
                                                        $data = $this->wc_data;
1✔
510
                                                        return ! empty( $data->get_button_text() ) ? $data->get_button_text() : null;
1✔
511
                                                },
2✔
512
                                        ];
2✔
513
                                        break;
2✔
514
                                case apply_filters( "graphql_{$type}_product_model_use_grouped_fields", 'grouped' === $type ):
3✔
515
                                        $fields += [
1✔
516
                                                'addToCartText'        => function () {
1✔
517
                                                        return ! empty( $this->wc_data->add_to_cart_text() ) ? $this->wc_data->add_to_cart_text() : null;
1✔
518
                                                },
1✔
519
                                                'addToCartDescription' => function () {
1✔
520
                                                        return ! empty( $this->wc_data->add_to_cart_description() )
1✔
521
                                                                ? $this->wc_data->add_to_cart_description()
1✔
522
                                                                : null;
1✔
523
                                                },
1✔
524
                                                'grouped_ids'          => function () {
1✔
525
                                                        return ! empty( $this->wc_data->get_children() )
1✔
526
                                                                ? array_map( 'absint', $this->wc_data->get_children() )
1✔
527
                                                                : [ '0' ];
1✔
528
                                                },
1✔
529
                                        ];
1✔
530
                                        break;
1✔
531
                        }//end switch
532

533
                        /**
534
                         * Defines aliased fields
535
                         *
536
                         * These fields are used primarily by WPGraphQL core Node* interfaces
537
                         * and some fields act as aliases/decorator for existing fields.
538
                         */
539
                        $fields += [
61✔
540
                                'commentCount'  => function () {
61✔
541
                                        // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
542
                                        return ! empty( $this->reviewCount ) ? $this->reviewCount : null;
1✔
543
                                },
61✔
544
                                'commentStatus' => function () {
61✔
545
                                        // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
546
                                        return isset( $this->reviewsAllowed ) && $this->reviewsAllowed ? 'open' : 'closed';
1✔
547
                                },
61✔
548
                        ];
61✔
549

550
                        $this->fields = array_merge( $this->fields, $fields );
61✔
551
                }//end if
552
        }
553
}
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