Skip to content

Commit

Permalink
Merge pull request #1 from kidunot89/feature/product-link
Browse files Browse the repository at this point in the history
"link" field added to "Product" interface.
  • Loading branch information
kidunot89 authored Nov 5, 2019
2 parents 56138c9 + d7f16c9 commit cb25f3e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
20 changes: 11 additions & 9 deletions includes/model/class-product.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,7 @@ protected function init() {
return $this->data->get_id();
},
'id' => function() {
return ! empty( $this->data->get_id() )
? Relay::toGlobalId( 'product', $this->data->get_id() )
: null;
return ! empty( $this->data->get_id() ) ? Relay::toGlobalId( 'product', $this->data->get_id() ) : null;
},
'productId' => function() {
return ! empty( $this->data->get_id() ) ? $this->data->get_id() : null;
Expand Down Expand Up @@ -179,12 +177,12 @@ protected function init() {
),
'shortDescription' => function() {
$short_description = ! empty( $this->data->get_short_description() )
? apply_filters(
'get_the_excerpt',
$this->data->get_short_description(),
get_post( $this->data->get_id() )
)
: null;
? apply_filters(
'get_the_excerpt',
$this->data->get_short_description(),
get_post( $this->data->get_id() )
)
: null;
return apply_filters( 'the_excerpt', $short_description );
},
'shortDescriptionRaw' => array(
Expand Down Expand Up @@ -226,6 +224,10 @@ protected function init() {
'purchasable' => function () {
return ! is_null( $this->data->is_purchasable() ) ? $this->data->is_purchasable() : null;
},
'link' => function () {
$link = get_permalink( $this->data->ID );
return ! empty( $link ) ? $link : null;
},
/**
* Connection resolvers fields
*
Expand Down
4 changes: 4 additions & 0 deletions includes/type/interface/class-product.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ public static function get_fields() {
'type' => 'Boolean',
'description' => __( 'Can product be purchased?', 'wp-graphql-woocommerce' ),
),
'link' => array(
'type' => 'String',
'description' => __( 'The permalink of the post', 'wp-graphql' ),
),
);
}
}
1 change: 1 addition & 0 deletions tests/_support/Helper/crud-helpers/product.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ public function print_query( $id, $raw = false ) {
'purchasable' => $data->is_purchasable(),
'shippingRequired' => $data->needs_shipping(),
'shippingTaxable' => $data->is_shipping_taxable(),
'link' => get_permalink( $data->get_id() ),
);
}

Expand Down
1 change: 1 addition & 0 deletions tests/wpunit/ProductQueriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public function testSimpleProductQuery() {
purchasable
shippingRequired
shippingTaxable
link
}
}
}
Expand Down

0 comments on commit cb25f3e

Please sign in to comment.