Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions includes/model/class-product-variation.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,19 @@
'shipping_class_id' => function () {
return ! empty( $this->wc_data->get_shipping_class_id() ) ? $this->wc_data->get_shipping_class_id() : null;
},
'shippingClassId' => function () {
return ! empty( $this->wc_data->get_shipping_class_id() ) ? $this->wc_data->get_shipping_class_id() : null;
},
Comment on lines +234 to +236
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary, why can't we continue to used the snake case shipping_class_id

'shippingClass' => function () {
$shipping_class_id = $this->wc_data->get_shipping_class_id();
$shipping_class_term = get_term( $shipping_class_id, 'product_shipping_class' );

if ( ! is_wp_error( $shipping_class_term ) && is_a( $shipping_class_term, 'WP_Term' ) ) {

Check failure on line 241 in includes/model/class-product-variation.php

View workflow job for this annotation

GitHub Actions / Testing WooGraphQL code quality w/ PHPStan

Parameter #1 $object_or_class of function is_a expects object, WP_Term|null given.
$shipping_class = $shipping_class_term;
}

return $shipping_class ?? null;
},
'image_id' => function () {
return ! empty( $this->wc_data->get_image_id() ) ? $this->wc_data->get_image_id() : null;
},
Expand Down
2 changes: 1 addition & 1 deletion includes/model/class-product.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ protected function init() {
return ! empty( $this->wc_data->get_height() ) ? $this->wc_data->get_height() : null;
},
'shippingClassId' => function () {
return ! empty( $this->wc_data->get_image_id() ) ? $this->wc_data->get_shipping_class_id() : null;
return ! empty( $this->wc_data->get_shipping_class_id() ) ? $this->wc_data->get_shipping_class_id() : null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

},
'shippingRequired' => function () {
return $this->wc_data->needs_shipping();
Expand Down
2 changes: 1 addition & 1 deletion includes/type/interface/class-product-variation.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public static function get_fields() {
'description' => __( 'Product variation purchase_note', 'wp-graphql-woocommerce' ),
],
'shippingClass' => [
'type' => 'String',
'type' => 'ShippingClass',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type ShippingClass does not exist.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That means this needs to be provided with a resolver that resolves to the TermNode. The resolver should looks something like this.

'resolve'     => static function ( $source, array $args, $context  ) {
        $id = $source->shipping_class_id;
        if ( $id ) {
	        return $context->get_loader( "term" )->load_deferred( $id );
        }

        return null;
},

'description' => __( 'Product variation shipping class', 'wp-graphql-woocommerce' ),
],
'catalogVisibility' => [
Expand Down
Loading