Merge pull request #1 from kidunot89/feature/product-link

"link" field added to "Product" interface.
This commit is contained in:
Geoffrey K Taylor
2019-11-04 22:51:41 -05:00
committed by GitHub
4 changed files with 17 additions and 9 deletions
+11 -9
View File
@@ -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
*
@@ -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' ),
),
);
}
}
@@ -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() ),
);
}
+1
View File
@@ -101,6 +101,7 @@ class ProductQueriesTest extends \Codeception\TestCase\WPTestCase {
purchasable
shippingRequired
shippingTaxable
link
}
}
}