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

wp-graphql / wp-graphql-woocommerce / 11714183904

07 Nov 2024 12:23AM UTC coverage: 83.665% (-0.8%) from 84.451%
11714183904

push

github

web-flow
devops: Name officially changed to "WPGraphQL for WooCommerce" (#900)

* devops: Name officially changed to "WPGraphQL for WooCommerce"

* devops: GA workflow environment updated

* devops: GA workflow environment updated

* devops: composer-git-hooks downgraded to "2.8.5"

* devops: Unstable session manager tests skipped

* chore: cleanup applied

* devops: Docker configurations updated

* devops: Docker configurations updated

* devops: Docker configurations updated

* devops: Docker configurations updated

* devops: Docker configurations updated

2 of 8 new or added lines in 5 files covered. (25.0%)

268 existing lines in 20 files now uncovered.

12431 of 14858 relevant lines covered (83.67%)

71.79 hits per line

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

92.66
/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 );
60✔
122

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

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

131
        /**
132
         * Returns the product type.
133
         *
134
         * @return string
135
         */
136
        public function get_type() {
137
                return $this->wc_data->get_type();
60✔
138
        }
139

140
        /**
141
         * Returns string of variation price range.
142
         *
143
         * @param string  $pricing_type - Range selected pricing type.
144
         * @param boolean $raw          - Whether to return raw value.
145
         *
146
         * @return string|null
147
         */
148
        private function get_variation_price( $pricing_type = '', $raw = false ) {
149
                /**
150
                 * Variable product data source.
151
                 *
152
                 * @var \WC_Product_Variable $data
153
                 */
154
                $data = $this->wc_data;
1✔
155

156
                $prices = $data->get_variation_prices( true );
1✔
157

158
                if ( empty( $prices['price'] ) || ( 'sale' === $pricing_type && ! $this->wc_data->is_on_sale() ) ) {
1✔
159
                        return null;
1✔
160
                }
161

162
                switch ( $pricing_type ) {
163
                        case 'sale':
1✔
164
                                $prices = array_values( array_diff( $prices['sale_price'], $prices['regular_price'] ) );
×
165
                                break;
×
166
                        case 'regular':
1✔
167
                                $prices = $prices['regular_price'];
1✔
168
                                break;
1✔
169
                        default:
170
                                $prices = $prices['price'];
1✔
171
                                break;
1✔
172
                }
173

174
                sort( $prices, SORT_NUMERIC );
1✔
175
                graphql_debug( implode( ', ', $prices ) );
1✔
176

177
                if ( $raw ) {
1✔
178
                        return implode( ', ', $prices );
×
179
                }
180

181
                return wc_graphql_price_range( current( $prices ), end( $prices ) );
1✔
182
        }
183

184
        /**
185
         * Initializes the Product field resolvers
186
         *
187
         * @access protected
188
         */
189
        protected function init() {
190
                if ( empty( $this->fields ) ) {
60✔
191
                        parent::init();
60✔
192

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

241
                                        // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
242
                                        return apply_filters( 'the_excerpt', $short_description );
2✔
243
                                },
60✔
244
                                'shortDescriptionRaw' => function () {
60✔
245
                                        return ! empty( $this->wc_data->get_short_description() ) ? $this->wc_data->get_short_description() : null;
2✔
246
                                },
60✔
247
                                'sku'                 => function () {
60✔
248
                                        return ! empty( $this->wc_data->get_sku() ) ? $this->wc_data->get_sku() : null;
3✔
249
                                },
60✔
250
                                'dateOnSaleFrom'      => function () {
60✔
251
                                        return ! empty( $this->wc_data->get_date_on_sale_from() ) ? $this->wc_data->get_date_on_sale_from() : null;
2✔
252
                                },
60✔
253
                                'dateOnSaleTo'        => function () {
60✔
254
                                        return ! empty( $this->wc_data->get_date_on_sale_to() ) ? $this->wc_data->get_date_on_sale_to() : null;
2✔
255
                                },
60✔
256
                                'reviewsAllowed'      => function () {
60✔
257
                                        return ! empty( $this->wc_data->get_reviews_allowed() ) ? $this->wc_data->get_reviews_allowed() : null;
3✔
258
                                },
60✔
259
                                'purchaseNote'        => function () {
60✔
260
                                        return ! empty( $this->wc_data->get_purchase_note() ) ? $this->wc_data->get_purchase_note() : null;
2✔
261
                                },
60✔
262
                                'menuOrder'           => function () {
60✔
263
                                        return $this->wc_data->get_menu_order();
2✔
264
                                },
60✔
265
                                'averageRating'       => function () {
60✔
266
                                        return $this->wc_data->get_average_rating();
4✔
267
                                },
60✔
268
                                'reviewCount'         => function () {
60✔
269
                                        return $this->wc_data->get_review_count();
4✔
270
                                },
60✔
271
                                'onSale'              => function () {
60✔
272
                                        return $this->wc_data->is_on_sale();
2✔
273
                                },
60✔
274
                                'purchasable'         => function () {
60✔
275
                                        return $this->wc_data->is_purchasable();
2✔
276
                                },
60✔
277

278
                                /**
279
                                 * Editor/Shop Manager only fields
280
                                 */
281
                                'catalogVisibility'   => [
60✔
282
                                        'callback'   => function () {
60✔
283
                                                return ! empty( $this->wc_data->get_catalog_visibility() ) ? $this->wc_data->get_catalog_visibility() : null;
2✔
284
                                        },
60✔
285
                                        'capability' => $this->post_type_object->cap->edit_posts,
60✔
286
                                ],
60✔
287
                                'totalSales'          => [
60✔
288
                                        'callback'   => function () {
60✔
289
                                                return $this->wc_data->get_total_sales();
2✔
290
                                        },
60✔
291
                                        'capability' => $this->post_type_object->cap->edit_posts,
60✔
292
                                ],
60✔
293

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

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

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

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

523
                        /**
524
                         * Defines aliased fields
525
                         *
526
                         * These fields are used primarily by WPGraphQL core Node* interfaces
527
                         * and some fields act as aliases/decorator for existing fields.
528
                         */
529
                        $fields += [
60✔
530
                                'commentCount'  => function () {
60✔
531
                                        // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
532
                                        return ! empty( $this->reviewCount ) ? $this->reviewCount : null;
1✔
533
                                },
60✔
534
                                'commentStatus' => function () {
60✔
535
                                        // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
536
                                        return isset( $this->reviewsAllowed ) && $this->reviewsAllowed ? 'open' : 'closed';
1✔
537
                                },
60✔
538
                        ];
60✔
539

540
                        $this->fields = array_merge( $this->fields, $fields );
60✔
541
                }//end if
542
        }
543
}
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