Skip to content

Commit 6baf963

Browse files
authored
Merge pull request #83 from kidunot89/feature/more-tests
ProductToTerm connection and TermToProduct connections tests added.
2 parents 7b0fe1b + e13ddce commit 6baf963

14 files changed

+833
-308
lines changed

includes/class-actions.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
use WPGraphQL\Extensions\WooCommerce\Type\WPObject\Product_Variation_Type;
3737
use WPGraphQL\Extensions\WooCommerce\Type\WPObject\Product_Attribute_Type;
3838
use WPGraphQL\Extensions\WooCommerce\Type\WPObject\Product_Download_Type;
39-
use WPGraphQL\Extensions\WooCommerce\Type\WPObject\Product_Rating_Counter_Type;
4039
use WPGraphQL\Extensions\WooCommerce\Type\WPObject\Customer_Type;
4140
use WPGraphQL\Extensions\WooCommerce\Type\WPObject\Customer_Address_Type;
4241
use WPGraphQL\Extensions\WooCommerce\Type\WPObject\Tax_Rate_Type;
@@ -121,7 +120,6 @@ public static function graphql_register_types() {
121120
Refund_Type::register();
122121
Product_Attribute_Type::register();
123122
Product_Download_Type::register();
124-
Product_Rating_Counter_Type::register();
125123
Customer_Type::register();
126124
Customer_Address_Type::register();
127125
Tax_Rate_Type::register();

includes/model/class-product.php

Lines changed: 80 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -131,51 +131,51 @@ private function get_variation_price( $pricing_type = '', $raw = false ) {
131131
protected function init() {
132132
if ( empty( $this->fields ) ) {
133133
$this->fields = array(
134-
'ID' => function() {
134+
'ID' => function() {
135135
return $this->data->get_id();
136136
},
137-
'id' => function() {
137+
'id' => function() {
138138
return ! empty( $this->data->get_id() )
139139
? Relay::toGlobalId( 'product', $this->data->get_id() )
140140
: null;
141141
},
142-
'productId' => function() {
142+
'productId' => function() {
143143
return ! empty( $this->data->get_id() ) ? $this->data->get_id() : null;
144144
},
145-
'type' => function() {
145+
'type' => function() {
146146
return ! empty( $this->data->get_type() ) ? $this->data->get_type() : null;
147147
},
148-
'slug' => function() {
148+
'slug' => function() {
149149
return ! empty( $this->data->get_slug() ) ? $this->data->get_slug() : null;
150150
},
151-
'name' => function() {
151+
'name' => function() {
152152
return ! empty( $this->data->get_name() ) ? $this->data->get_name() : null;
153153
},
154-
'date' => function() {
154+
'date' => function() {
155155
return ! empty( $this->data ) ? $this->data->get_date_created() : null;
156156
},
157-
'modified' => function() {
157+
'modified' => function() {
158158
return ! empty( $this->data ) ? $this->data->get_date_modified() : null;
159159
},
160-
'status' => function() {
160+
'status' => function() {
161161
return ! empty( $this->data->get_status() ) ? $this->data->get_status() : null;
162162
},
163-
'featured' => function() {
163+
'featured' => function() {
164164
return ! is_null( $this->data->get_featured() ) ? $this->data->get_featured() : null;
165165
},
166-
'catalogVisibility' => function() {
166+
'catalogVisibility' => function() {
167167
return ! empty( $this->data->get_catalog_visibility() ) ? $this->data->get_catalog_visibility() : null;
168168
},
169-
'description' => function() {
169+
'description' => function() {
170170
return ! empty( $this->data->get_description() ) ? $this->data->get_description() : null;
171171
},
172-
'shortDescription' => function() {
172+
'shortDescription' => function() {
173173
return ! empty( $this->data->get_short_description() ) ? $this->data->get_short_description() : null;
174174
},
175-
'sku' => function() {
175+
'sku' => function() {
176176
return ! empty( $this->data->get_sku() ) ? $this->data->get_sku() : null;
177177
},
178-
'price' => function() {
178+
'price' => function() {
179179
if ( 'variable' === $this->data->get_type() ) {
180180
return $this->get_variation_price();
181181
}
@@ -184,7 +184,7 @@ protected function init() {
184184
? \wc_graphql_price( $this->data->get_price() )
185185
: null;
186186
},
187-
'priceRaw' => array(
187+
'priceRaw' => array(
188188
'callback' => function() {
189189
if ( 'variable' === $this->data->get_type() ) {
190190
return $this->get_variation_price( '', true );
@@ -194,7 +194,7 @@ protected function init() {
194194
},
195195
'capability' => $this->post_type_object->cap->edit_posts,
196196
),
197-
'regularPrice' => function() {
197+
'regularPrice' => function() {
198198
if ( 'variable' === $this->data->get_type() ) {
199199
return $this->get_variation_price( 'regular' );
200200
}
@@ -203,7 +203,7 @@ protected function init() {
203203
? \wc_graphql_price( $this->data->get_regular_price() )
204204
: null;
205205
},
206-
'regularPriceRaw' => array(
206+
'regularPriceRaw' => array(
207207
'callback' => function() {
208208
if ( 'variable' === $this->data->get_type() ) {
209209
return $this->get_variation_price( 'regular', true );
@@ -213,7 +213,7 @@ protected function init() {
213213
},
214214
'capability' => $this->post_type_object->cap->edit_posts,
215215
),
216-
'salePrice' => function() {
216+
'salePrice' => function() {
217217
if ( 'variable' === $this->data->get_type() ) {
218218
return $this->get_variation_price( 'sale' );
219219
}
@@ -222,7 +222,7 @@ protected function init() {
222222
? \wc_graphql_price( $this->data->get_sale_price() )
223223
: null;
224224
},
225-
'salePriceRaw' => array(
225+
'salePriceRaw' => array(
226226
'callback' => function() {
227227
if ( 'variable' === $this->data->get_type() ) {
228228
return $this->get_variation_price( 'sale', true );
@@ -232,115 +232,118 @@ protected function init() {
232232
},
233233
'capability' => $this->post_type_object->cap->edit_posts,
234234
),
235-
'dateOnSaleFrom' => function() {
235+
'dateOnSaleFrom' => function() {
236236
return ! empty( $this->data->get_date_on_sale_from() ) ? $this->data->get_date_on_sale_from() : null;
237237
},
238-
'dateOnSaleTo' => function() {
238+
'dateOnSaleTo' => function() {
239239
return ! empty( $this->data->get_date_on_sale_to() ) ? $this->data->get_date_on_sale_to() : null;
240240
},
241-
'totalSales' => function() {
241+
'totalSales' => function() {
242242
return ! is_null( $this->data->get_total_sales() ) ? $this->data->get_total_sales() : null;
243243
},
244-
'taxStatus' => function() {
244+
'taxStatus' => function() {
245245
return ! empty( $this->data->get_tax_status() ) ? $this->data->get_tax_status() : null;
246246
},
247-
'taxClass' => function() {
247+
'taxClass' => function() {
248248
return ! empty( $this->data->get_tax_class() ) ? $this->data->get_tax_class() : 'standard';
249249
},
250-
'manageStock' => function() {
250+
'manageStock' => function() {
251251
return ! is_null( $this->data->get_manage_stock() ) ? $this->data->get_manage_stock() : null;
252252
},
253-
'stockQuantity' => function() {
253+
'stockQuantity' => function() {
254254
return ! empty( $this->data->get_stock_quantity() ) ? $this->data->get_stock_quantity() : null;
255255
},
256-
'stockStatus' => function() {
256+
'stockStatus' => function() {
257257
return ! empty( $this->data->get_stock_status() ) ? $this->data->get_stock_status() : null;
258258
},
259-
'backorders' => function() {
259+
'backorders' => function() {
260260
return ! empty( $this->data->get_backorders() ) ? $this->data->get_backorders() : null;
261261
},
262-
'soldIndividually' => function() {
262+
'soldIndividually' => function() {
263263
return ! is_null( $this->data->is_sold_individually() ) ? $this->data->is_sold_individually() : null;
264264
},
265-
'weight' => function() {
265+
'weight' => function() {
266266
return ! is_null( $this->data->get_weight() ) ? $this->data->get_weight() : null;
267267
},
268-
'length' => function() {
268+
'length' => function() {
269269
return ! is_null( $this->data->get_length() ) ? $this->data->get_length() : null;
270270
},
271-
'width' => function() {
271+
'width' => function() {
272272
return ! is_null( $this->data->get_width() ) ? $this->data->get_width() : null;
273273
},
274-
'height' => function() {
274+
'height' => function() {
275275
return ! is_null( $this->data->get_height() ) ? $this->data->get_height() : null;
276276
},
277-
'reviewsAllowed' => function() {
277+
'reviewsAllowed' => function() {
278278
return ! empty( $this->data->get_reviews_allowed() ) ? $this->data->get_reviews_allowed() : null;
279279
},
280-
'purchaseNote' => function() {
280+
'purchaseNote' => function() {
281281
return ! empty( $this->data->get_purchase_note() ) ? $this->data->get_purchase_note() : null;
282282
},
283-
'menuOrder' => function() {
283+
'menuOrder' => function() {
284284
return ! is_null( $this->data->get_menu_order() ) ? $this->data->get_menu_order() : null;
285285
},
286-
'virtual' => function() {
286+
'virtual' => function() {
287287
return ! is_null( $this->data->is_virtual() ) ? $this->data->is_virtual() : null;
288288
},
289-
'downloadExpiry' => function() {
289+
'downloadExpiry' => function() {
290290
return ! is_null( $this->data->get_download_expiry() ) ? $this->data->get_download_expiry() : null;
291291
},
292-
'downloadable' => function() {
292+
'downloadable' => function() {
293293
return ! is_null( $this->data->is_downloadable() ) ? $this->data->is_downloadable() : null;
294294
},
295-
'downloadLimit' => function() {
295+
'downloadLimit' => function() {
296296
return ! is_null( $this->data->get_download_limit() ) ? $this->data->get_download_limit() : null;
297297
},
298-
'ratingCount' => function() {
299-
return ! is_null( $this->data->get_rating_counts() ) ? $this->data->get_rating_counts() : null;
300-
},
301-
'averageRating' => function() {
298+
'averageRating' => function() {
302299
return ! is_null( $this->data->get_average_rating() ) ? $this->data->get_average_rating() : null;
303300
},
304-
'reviewCount' => function() {
301+
'reviewCount' => function() {
305302
return ! is_null( $this->data->get_review_count() ) ? $this->data->get_review_count() : null;
306303
},
307-
'parentId' => function() {
308-
return ! empty( $this->data->get_parent_id() ) ? $this->data->get_parent_id() : null;
309-
},
310-
'imageId' => function () {
311-
return ! empty( $this->data->get_image_id() ) ? $this->data->get_image_id() : null;
312-
},
313-
'shippingClassId' => function () {
304+
'shippingClassId' => function () {
314305
return ! empty( $this->data->get_image_id() ) ? $this->data->get_shipping_class_id() : null;
315306
},
316-
'downloads' => function() {
307+
'downloads' => function() {
317308
return ! empty( $this->data->get_downloads() ) ? $this->data->get_downloads() : null;
318309
},
319-
'onSale' => function () {
310+
'onSale' => function () {
320311
return ! is_null( $this->data->is_on_sale() ) ? $this->data->is_on_sale() : null;
321312
},
322-
'purchasable' => function () {
313+
'purchasable' => function () {
323314
return ! is_null( $this->data->is_purchasable() ) ? $this->data->is_purchasable() : null;
324315
},
325-
'externalUrl' => function() {
316+
'externalUrl' => function() {
326317
if ( 'external' === $this->data->get_type() ) {
327318
return ! empty( $this->data->get_product_url() ) ? $this->data->get_product_url() : null;
328319
}
329320
return null;
330321
},
331-
'buttonText' => function() {
322+
'buttonText' => function() {
332323
if ( 'external' === $this->data->get_type() ) {
333324
return ! empty( $this->data->get_button_text() ) ? $this->data->get_button_text() : null;
334325
}
335326
return null;
336327
},
337-
'backordersAllowed' => function() {
328+
'addToCartText' => function() {
329+
if ( 'grouped' === $this->data->get_type() || 'external' === $this->data->get_type() ) {
330+
return ! empty( $this->data->add_to_cart_text() ) ? $this->data->add_to_cart_text() : null;
331+
}
332+
return null;
333+
},
334+
'addToCartDescription' => function() {
335+
if ( 'grouped' === $this->data->get_type() || 'external' === $this->data->get_type() ) {
336+
return ! empty( $this->data->add_to_cart_description() ) ? $this->data->add_to_cart_description() : null;
337+
}
338+
return null;
339+
},
340+
'backordersAllowed' => function() {
338341
return ! empty( $this->data->backorders_allowed() ) ? $this->data->backorders_allowed() : null;
339342
},
340-
'shippingRequired' => function() {
343+
'shippingRequired' => function() {
341344
return ! is_null( $this->data->needs_shipping() ) ? $this->data->needs_shipping() : null;
342345
},
343-
'shippingTaxable' => function() {
346+
'shippingTaxable' => function() {
344347
return ! is_null( $this->data->is_shipping_taxable() ) ? $this->data->is_shipping_taxable() : null;
345348
},
346349
/**
@@ -349,11 +352,11 @@ protected function init() {
349352
* These field resolvers are used in connection resolvers to define WP_Query argument
350353
* Note: underscore naming style is used as a quick identifier
351354
*/
352-
'related_ids' => function() {
355+
'related_ids' => function() {
353356
$related_ids = array_map( 'absint', array_values( wc_get_related_products( $this->data->get_id() ) ) );
354357
return ! empty( $related_ids ) ? $related_ids : array( '0' );
355358
},
356-
'upsell_ids' => function() {
359+
'upsell_ids' => function() {
357360
if ( ! empty( $this->data ) ) {
358361
switch ( $this->data->get_type() ) {
359362
case 'external':
@@ -367,7 +370,7 @@ protected function init() {
367370

368371
return array( '0' );
369372
},
370-
'cross_sell_ids' => function() {
373+
'cross_sell_ids' => function() {
371374
if ( ! empty( $this->data ) ) {
372375
switch ( $this->data->get_type() ) {
373376
case 'external':
@@ -381,35 +384,41 @@ protected function init() {
381384

382385
return array( '0' );
383386
},
384-
'grouped_ids' => function() {
387+
'grouped_ids' => function() {
385388
if ( ! empty( $this->data ) && 'grouped' === $this->data->get_type() ) {
386389
$grouped = array_map( 'absint', $this->data->get_children() );
387390
return ! empty( $grouped ) ? $grouped : array( '0' );
388391
}
389392
return array( '0' );
390393
},
391-
'variation_ids' => function() {
394+
'variation_ids' => function() {
392395
if ( ! empty( $this->data ) && 'variable' === $this->data->get_type() ) {
393396
$variations = array_map( 'absint', $this->data->get_children() );
394397
return ! empty( $variations ) ? $variations : array( '0' );
395398
}
396399
return array( '0' );
397400
},
398-
'attributes' => function() {
401+
'attributes' => function() {
399402
return ! empty( $this->data->get_attributes() ) ? array_values( $this->data->get_attributes() ) : array( '0' );
400403
},
401-
'default_attributes' => function() {
404+
'default_attributes' => function() {
402405
return ! empty( $this->data->get_default_attributes() ) ? $this->data->get_default_attributes() : array( '0' );
403406
},
404-
'gallery_image_ids' => function() {
407+
'image_id' => function () {
408+
return ! empty( $this->data->get_image_id() ) ? $this->data->get_image_id() : null;
409+
},
410+
'gallery_image_ids' => function() {
405411
return ! empty( $this->data->get_gallery_image_ids() ) ? $this->data->get_gallery_image_ids() : array( '0' );
406412
},
407-
'category_ids' => function() {
413+
'category_ids' => function() {
408414
return ! empty( $this->data->get_category_ids() ) ? $this->data->get_category_ids() : array( '0' );
409415
},
410-
'tag_ids' => function() {
416+
'tag_ids' => function() {
411417
return ! empty( $this->data->get_tag_ids() ) ? $this->data->get_tag_ids() : array( '0' );
412418
},
419+
'parent_id' => function() {
420+
return ! empty( $this->data->get_parent_id() ) ? $this->data->get_parent_id() : null;
421+
},
413422
);
414423
}
415424

includes/type/object/class-product-download-type.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static function register() {
2828
'description' => __( 'A product object', 'wp-graphql-woocommerce' ),
2929
'fields' => array(
3030
'downloadId' => array(
31-
'type' => array( 'non_null' => 'Int' ),
31+
'type' => array( 'non_null' => 'String' ),
3232
'description' => __( 'Product download ID', 'wp-graphql-woocommerce' ),
3333
'resolve' => function ( $download ) {
3434
return ! empty( $download ) ? $download->get_id() : null;

0 commit comments

Comments
 (0)