diff --git a/includes/model/class-product.php b/includes/model/class-product.php index 508e4557..f070de08 100644 --- a/includes/model/class-product.php +++ b/includes/model/class-product.php @@ -135,9 +135,7 @@ class Product extends Crud_CPT { 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; @@ -179,12 +177,12 @@ class Product extends Crud_CPT { ), '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( @@ -226,6 +224,10 @@ class Product extends Crud_CPT { '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 * diff --git a/includes/type/interface/class-product.php b/includes/type/interface/class-product.php index c1885998..c8daea7e 100644 --- a/includes/type/interface/class-product.php +++ b/includes/type/interface/class-product.php @@ -270,6 +270,10 @@ class Product { 'type' => 'Boolean', 'description' => __( 'Can product be purchased?', 'wp-graphql-woocommerce' ), ), + 'link' => array( + 'type' => 'String', + 'description' => __( 'The permalink of the post', 'wp-graphql' ), + ), ); } } diff --git a/tests/_support/Helper/crud-helpers/product.php b/tests/_support/Helper/crud-helpers/product.php index c5e9a4ca..94acac2d 100644 --- a/tests/_support/Helper/crud-helpers/product.php +++ b/tests/_support/Helper/crud-helpers/product.php @@ -366,6 +366,7 @@ class ProductHelper extends WCG_Helper { 'purchasable' => $data->is_purchasable(), 'shippingRequired' => $data->needs_shipping(), 'shippingTaxable' => $data->is_shipping_taxable(), + 'link' => get_permalink( $data->get_id() ), ); } diff --git a/tests/wpunit/ProductQueriesTest.php b/tests/wpunit/ProductQueriesTest.php index c019e40d..ee8579fd 100644 --- a/tests/wpunit/ProductQueriesTest.php +++ b/tests/wpunit/ProductQueriesTest.php @@ -101,6 +101,7 @@ class ProductQueriesTest extends \Codeception\TestCase\WPTestCase { purchasable shippingRequired shippingTaxable + link } } }