Files
wp-graphql-woocommerce/src/model/class-refund.php
T

80 lines
1.8 KiB
PHP
Raw Normal View History

2019-03-31 00:21:31 -04:00
<?php
/**
* Model - Refund
*
* Resolves refund crud object model
*
* @package WPGraphQL\Extensions\WooCommerce\Model
* @since 0.0.1
*/
namespace WPGraphQL\Extensions\WooCommerce\Model;
use GraphQLRelay\Relay;
use WPGraphQL\Data\DataSource;
use WPGraphQL\Model\Model;
/**
* Class Refund
*/
class Refund extends Model {
/**
* Refund constructor
*
* @param int $id - shop_order_refund post-type ID.
*
* @access public
* @return void
*/
public function __construct( $id ) {
$this->data = new \WC_Order_Refund( $id );
2019-03-31 00:21:31 -04:00
$allowed_restricted_fields = [
'isRestricted',
'isPrivate',
'isPublic',
'id',
2019-04-06 12:39:55 -04:00
'refundId',
2019-03-31 00:21:31 -04:00
];
parent::__construct( 'list_users', $allowed_restricted_fields, $id );
2019-03-31 00:21:31 -04:00
}
/**
* Initializes the Refund field resolvers
*
* @access protected
2019-03-31 00:21:31 -04:00
*/
protected function init() {
2019-03-31 00:21:31 -04:00
if ( empty( $this->fields ) ) {
$this->fields = array(
2019-04-02 22:19:58 -04:00
'ID' => function() {
return $this->data->get_id();
2019-03-31 00:21:31 -04:00
},
2019-04-02 22:19:58 -04:00
'id' => function() {
return ! empty( $this->data ) ? Relay::toGlobalId( 'shop_order', $this->data->get_id() ) : null;
2019-03-31 00:21:31 -04:00
},
2019-04-02 22:19:58 -04:00
'refundId' => function() {
return ! empty( $this->data ) ? $this->data->get_id() : null;
2019-03-31 00:21:31 -04:00
},
2019-04-02 22:19:58 -04:00
'title' => function() {
return ! empty( $this->data ) ? $this->data->get_post_title() : null;
2019-04-02 22:19:58 -04:00
},
'amount' => function() {
return ! empty( $this->data ) ? $this->data->get_amount() : null;
2019-04-02 22:19:58 -04:00
},
'reason' => function() {
return ! empty( $this->data ) ? $this->data->get_reason() : null;
2019-04-02 22:19:58 -04:00
},
'refunded_by_id' => array(
'callback' => function() {
return ! empty( $this->data ) ? $this->data->get_refunded_by() : null;
2019-04-02 22:19:58 -04:00
},
'capability' => 'list_users',
),
2019-03-31 00:21:31 -04:00
);
}
parent::prepare_fields();
}
}