Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
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 @@ protected function init() {
'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 ) && $shipping_class_term instanceof \WP_Term ) {
$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
6 changes: 5 additions & 1 deletion includes/type/interface/class-product-variation.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,12 @@ public static function get_fields() {
'type' => 'String',
'description' => __( 'Product variation purchase_note', 'wp-graphql-woocommerce' ),
],
'shippingClassId' => [
'type' => 'Int',
'description' => __( 'Product variation shipping class ID', '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