mirror of
https://github.com/wp-graphql/wp-graphql-woocommerce.git
synced 2026-08-14 12:53:44 +02:00
* chore: setup PHPStan * chore: General code cleanup for PHPStan * chore: PHPStan to level 2 * chore: PHPStan to level 2 * fix: Syntax error fixed. * devops: PHPStan level 2 reached. * devops: PHPStan level 3 passed * devops: PHPStan level 4 passed * chore: fix bad typehints from jwt-auth [phpstan] * chore: simplify conditional logic in WC_Terms::register_connections() * chore: add stubs for WP type properties. * fix: check for valid WC_Order_Item before caching order. * chore: lint * devops: PHPStan level 6 passed. * chore: Linter compliance met. * chore: simplify logic and check for valid term. * fix: ensure valid types (partial) * chore: [phpcs] allow inline type annotations * devops: PHPStan level 8 reached. * devops: More stability fixes. * fix: general bugfixes and improvements * devops: Code Quality GA script added. * devops: Linter compliance met & 2 "phpstan-ignore" statements set. * devops: PHPStan config and CI script fixed. * fix: "cartItem" query resolution refactored * devops: GA scripts updated. * chore: Simple copy changes --------- Co-authored-by: Geoff Taylor <geoff@axistaylor.com>
86 lines
1.9 KiB
PHP
86 lines
1.9 KiB
PHP
<?php
|
|
/**
|
|
* Model - Shipping_Method
|
|
*
|
|
* Resolves shipping method object model
|
|
*
|
|
* @package WPGraphQL\WooCommerce\Model
|
|
* @since 0.0.2
|
|
*/
|
|
|
|
namespace WPGraphQL\WooCommerce\Model;
|
|
|
|
use GraphQLRelay\Relay;
|
|
use WPGraphQL\Model\Model;
|
|
|
|
/**
|
|
* Class Shipping_Method
|
|
*
|
|
* @property \WC_Shipping_Method $data
|
|
*
|
|
* @property int $ID
|
|
* @property string $id
|
|
* @property int $databaseId
|
|
* @property string $title
|
|
* @property string $description
|
|
*
|
|
* @package WPGraphQL\WooCommerce\Model
|
|
*/
|
|
class Shipping_Method extends Model {
|
|
|
|
/**
|
|
* Shipping_Method constructor
|
|
*
|
|
* @param \WC_Shipping_Method $method - Shipping method object.
|
|
*/
|
|
public function __construct( $method ) {
|
|
$this->data = $method;
|
|
$allowed_restricted_fields = [
|
|
'isRestricted',
|
|
'isPrivate',
|
|
'isPublic',
|
|
'id',
|
|
'databaseId',
|
|
];
|
|
|
|
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
|
|
$restricted_cap = apply_filters( 'shipping_method_restricted_cap', '' );
|
|
|
|
parent::__construct( $restricted_cap, $allowed_restricted_fields, null );
|
|
}
|
|
|
|
/**
|
|
* Determines if the order item should be considered private.
|
|
*
|
|
* @return bool
|
|
*/
|
|
protected function is_private() {
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Initializes the Order field resolvers.
|
|
*/
|
|
protected function init() {
|
|
if ( empty( $this->fields ) ) {
|
|
$this->fields = [
|
|
'ID' => function() {
|
|
return $this->data->id;
|
|
},
|
|
'id' => function() {
|
|
return ! empty( $this->data->id ) ? Relay::toGlobalId( 'shipping_method', $this->data->id ) : null;
|
|
},
|
|
'databaseId' => function() {
|
|
return ! empty( $this->ID ) ? $this->ID : null;
|
|
},
|
|
'title' => function() {
|
|
return ! empty( $this->data->method_title ) ? $this->data->method_title : null;
|
|
},
|
|
'description' => function() {
|
|
return ! empty( $this->data->method_description ) ? $this->data->method_description : null;
|
|
},
|
|
];
|
|
}
|
|
}
|
|
}
|