• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wp-graphql / wp-graphql-woocommerce / 9122745284

17 May 2024 04:03AM UTC coverage: 85.048% (+0.4%) from 84.647%
9122745284

push

github

web-flow
feat: Queries and mutations for shipping zones, tax classes, and tax rates. (#856)

* fix: General bugfixes and improvements

* devops: New mutations and types tested and compliance with Linter and PHPStan

* chore: hooks added to the mutation resolvers

* feat: permission checks added

* chore: Linter and compliance met

* chore: Linter and compliance met

1252 of 1399 new or added lines in 39 files covered. (89.49%)

9 existing lines in 2 files now uncovered.

12423 of 14607 relevant lines covered (85.05%)

70.56 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.12
/includes/type/object/class-shipping-zone-type.php
1
<?php
2
/**
3
 * WPObject Type - Shipping_Zone_Type
4
 *
5
 * Registers ShippingZone WPObject type and queries
6
 *
7
 * @package WPGraphQL\WooCommerce\Type\WPObject
8
 * @since   TBD
9
 */
10

11
namespace WPGraphQL\WooCommerce\Type\WPObject;
12

13
use GraphQL\Type\Definition\ResolveInfo;
14
use WPGraphQL\AppContext;
15
use WPGraphQL\WooCommerce\Data\Connection\Shipping_Method_Connection_Resolver;
16

17
/**
18
 * Class Shipping_Zone_Type
19
 */
20
class Shipping_Zone_Type {
21
        /**
22
         * Registers shipping zone type
23
         *
24
         * @return void
25
         */
26
        public static function register() {
27
                register_graphql_object_type(
138✔
28
                        'ShippingZone',
138✔
29
                        [
138✔
30
                                'description' => __( 'A Shipping zone object', 'wp-graphql-woocommerce' ),
138✔
31
                                'interfaces'  => [ 'Node' ],
138✔
32
                                'fields'      => [
138✔
33
                                        'id'         => [
138✔
34
                                                'type'        => [ 'non_null' => 'ID' ],
138✔
35
                                                'description' => __( 'The globally unique identifier for the tax rate.', 'wp-graphql-woocommerce' ),
138✔
36
                                        ],
138✔
37
                                        'databaseId' => [
138✔
38
                                                'type'        => 'Int',
138✔
39
                                                'description' => __( 'The ID of the customer in the database', 'wp-graphql-woocommerce' ),
138✔
40
                                        ],
138✔
41
                                        'name'       => [
138✔
42
                                                'type'        => 'String',
138✔
43
                                                'description' => __( 'Shipping zone name.', 'wp-graphql-woocommerce' ),
138✔
44
                                        ],
138✔
45
                                        'order'      => [
138✔
46
                                                'type'        => 'Int',
138✔
47
                                                'description' => __( 'Shipping zone order.', 'wp-graphql-woocommerce' ),
138✔
48
                                        ],
138✔
49
                                        'locations'  => [
138✔
50
                                                'type'        => [ 'list_of' => 'ShippingLocation' ],
138✔
51
                                                'description' => __( 'Shipping zone locations.', 'wp-graphql-woocommerce' ),
138✔
52
                                        ],
138✔
53
                                ],
138✔
54
                                'connections' => [
138✔
55
                                        'methods' => [
138✔
56
                                                'toType'     => 'ShippingMethod',
138✔
57
                                                'edgeFields' => [
138✔
58
                                                        'id'         => [
138✔
59
                                                                'type'        => [ 'non_null' => 'ID' ],
138✔
60
                                                                'description' => __( 'The globally unique identifier for the shipping method.', 'wp-graphql-woocommerce' ),
138✔
61
                                                                'resolve'     => static function ( $edge ) {
138✔
62
                                                                        if ( isset( $edge['node'] ) ) {
3✔
63
                                                                                $shipping_method = $edge['node']->as_WC_Data();
3✔
64
                                                                                $instance_id     = $shipping_method->instance_id;
3✔
65

66
                                                                                return ! empty( $instance_id ) ? \GraphQLRelay\Relay::toGlobalId( 'shipping_zone_method', $instance_id ) : null;
3✔
67
                                                                        }
NEW
68
                                                                        return null;
×
69
                                                                },
138✔
70
                                                        ],
138✔
71
                                                        'instanceId' => [
138✔
72
                                                                'type'        => 'Int',
138✔
73
                                                                'description' => __( 'Shipping method instance ID.', 'wp-graphql-woocommerce' ),
138✔
74
                                                                'resolve'     => static function ( $edge ) {
138✔
75
                                                                        if ( isset( $edge['node'] ) ) {
3✔
76
                                                                                $shipping_method = $edge['node']->as_WC_Data();
3✔
77
                                                                                return $shipping_method->instance_id ?? null;
3✔
78
                                                                        }
NEW
79
                                                                        return null;
×
80
                                                                },
138✔
81
                                                        ],
138✔
82
                                                        'order'      => [
138✔
83
                                                                'type'        => 'Int',
138✔
84
                                                                'description' => __( 'The order of the shipping method.', 'wp-graphql-woocommerce' ),
138✔
85
                                                                'resolve'     => static function ( $edge ) {
138✔
86
                                                                        if ( isset( $edge['node'] ) ) {
4✔
87
                                                                                $shipping_method = $edge['node']->as_WC_Data();
4✔
88
                                                                                return $shipping_method->method_order ?? null;
4✔
89
                                                                        }
NEW
90
                                                                        return null;
×
91
                                                                },
138✔
92
                                                        ],
138✔
93
                                                        'enabled'    => [
138✔
94
                                                                'type'        => 'Boolean',
138✔
95
                                                                'description' => __( 'Whether the shipping method is enabled.', 'wp-graphql-woocommerce' ),
138✔
96
                                                                'resolve'     => static function ( $edge ) {
138✔
97
                                                                        if ( isset( $edge['node'] ) ) {
4✔
98
                                                                                /** @var \WC_Shipping_Method $shipping_method */
99
                                                                                $shipping_method = $edge['node']->as_WC_Data();
4✔
100
                                                                                return $shipping_method->is_enabled();
4✔
101
                                                                        }
NEW
102
                                                                        return false;
×
103
                                                                },
138✔
104
                                                        ],
138✔
105
                                                        'settings'   => [
138✔
106
                                                                'type'        => [ 'list_of' => 'WCSetting' ],
138✔
107
                                                                'description' => __( 'Shipping method settings.', 'wp-graphql-woocommerce' ),
138✔
108
                                                                'resolve'     => static function ( $edge ) {
138✔
109
                                                                        $settings = [];
3✔
110
                                                                        if ( isset( $edge['node'] ) ) {
3✔
111
                                                                                $shipping_method   = $edge['node']->as_WC_Data();
3✔
112
                                                                                $instance_settings = $shipping_method->instance_settings;
3✔
113
                                                                                $fields            = $shipping_method->instance_form_fields;
3✔
114
                                                                                foreach ( $fields as $key => $field ) {
3✔
115
                                                                                        $default_value = ! empty( $field['default'] ) ? $field['default'] : null;
3✔
116
                                                                                        $value         = ! empty( $instance_settings[ $key ] ) ? $instance_settings[ $key ] : $default_value;
3✔
117
                                                                                        $settings[]    = array_merge(
3✔
118
                                                                                                $field,
3✔
119
                                                                                                [
3✔
120
                                                                                                        'id' => $key,
3✔
121
                                                                                                        'value' => $value,
3✔
122
                                                                                                ]
3✔
123
                                                                                        );
3✔
124
                                                                                }
125
                                                                        }
126
                                                                        return $settings;
3✔
127
                                                                },
138✔
128
                                                        ],
138✔
129
                                                ],
138✔
130
                                                'resolve'    => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) {
138✔
131
                                                        $resolver = new Shipping_Method_Connection_Resolver( $source, $args, $context, $info );
4✔
132

133
                                                        return $resolver->get_connection();
4✔
134
                                                },
138✔
135
                                        ],
138✔
136
                                ],
138✔
137
                        ]
138✔
138
                );
138✔
139
        }
140
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc