Files
wp-graphql-woocommerce/includes/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
*
2019-10-25 19:13:36 -04:00
* @package WPGraphQL\WooCommerce\Model
2019-03-31 00:21:31 -04:00
* @since 0.0.1
*/
2019-10-25 19:13:36 -04:00
namespace WPGraphQL\WooCommerce\Model;
2019-03-31 00:21:31 -04:00
use GraphQLRelay\Relay;
2020-02-13 23:00:55 -06:00
use WC_Order_Refund;
2019-03-31 00:21:31 -04:00
/**
2020-02-13 23:00:55 -06:00
* Class Refund.
2019-03-31 00:21:31 -04:00
*/
2019-04-11 22:42:21 -04:00
class Refund extends Crud_CPT {
2020-02-13 23:00:55 -06:00
2019-04-11 22:42:21 -04:00
/**
2020-02-13 23:00:55 -06:00
* Defines get_restricted_cap.
2019-04-11 22:42:21 -04:00
*/
use Shop_Manager_Caps;
2019-03-31 00:21:31 -04:00
/**
2020-02-13 23:00:55 -06:00
* Refund constructor.
2019-03-31 00:21:31 -04:00
*
* @param int $id - shop_order_refund post-type ID.
*/
public function __construct( $id ) {
2020-02-13 23:00:55 -06:00
$this->data = new WC_Order_Refund( $id );
2019-12-03 16:26:10 -05:00
$allowed_restricted_fields = array(
2019-03-31 00:21:31 -04:00
'isRestricted',
'isPrivate',
'isPublic',
'id',
2019-04-06 12:39:55 -04:00
'refundId',
2019-12-03 16:26:10 -05:00
);
2019-03-31 00:21:31 -04:00
2019-04-11 22:42:21 -04:00
parent::__construct( $allowed_restricted_fields, 'shop_order_refund', $id );
2019-03-31 00:21:31 -04:00
}
/**
2020-02-13 23:00:55 -06:00
* Initializes the Refund field resolvers.
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() {
2019-04-17 14:18:35 -04:00
return ! empty( $this->data->get_id() ) ? Relay::toGlobalId( 'shop_order_refund', $this->data->get_id() ) : null;
2019-03-31 00:21:31 -04:00
},
2019-04-02 22:19:58 -04:00
'refundId' => function() {
2019-04-17 14:18:35 -04:00
return ! empty( $this->data->get_id() ) ? $this->data->get_id() : null;
2019-03-31 00:21:31 -04:00
},
2019-04-02 22:19:58 -04:00
'title' => function() {
2019-04-17 14:18:35 -04:00
return ! empty( $this->data->get_post_title() ) ? $this->data->get_post_title() : null;
2019-04-02 22:19:58 -04:00
},
'amount' => function() {
2019-04-17 14:18:35 -04:00
return ! empty( $this->data->get_amount() ) ? $this->data->get_amount() : null;
2019-04-02 22:19:58 -04:00
},
'reason' => function() {
2019-04-17 14:18:35 -04:00
return ! empty( $this->data->get_reason() ) ? $this->data->get_reason() : null;
2019-04-02 22:19:58 -04:00
},
'refunded_by_id' => array(
'callback' => function() {
2019-04-17 14:18:35 -04:00
return ! empty( $this->data->get_refunded_by() ) ? $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();
}
}