Skip to content

Commit

Permalink
fix: General bugfixes and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
kidunot89 committed May 16, 2024
1 parent 8ba35cd commit e73eb7c
Show file tree
Hide file tree
Showing 44 changed files with 3,707 additions and 48 deletions.
4 changes: 4 additions & 0 deletions includes/class-core-schema-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,15 @@ public static function graphql_data_loaders( $loaders, $context ) {
$downloadable_item_loader = new WC_Db_Loader( $context, 'DOWNLOADABLE_ITEM' );
$loaders['downloadable_item'] = &$downloadable_item_loader;
$tax_rate_loader = new WC_Db_Loader( $context, 'TAX_RATE' );
$loaders['tax_class'] = &$tax_class_loader;
$tax_class_loader = new WC_Db_Loader( $context, 'TAX_CLASS' );
$loaders['tax_rate'] = &$tax_rate_loader;
$order_item_loader = new WC_Db_Loader( $context, 'ORDER_ITEM' );
$loaders['order_item'] = &$order_item_loader;
$shipping_item_loader = new WC_Db_Loader( $context, 'SHIPPING_METHOD' );
$loaders['shipping_method'] = &$shipping_item_loader;
$shipping_zone_loader = new WC_Db_Loader( $context, 'SHIPPING_ZONE' );
$loaders['shipping_zone'] = &$shipping_zone_loader;
return $loaders;
}

Expand Down
22 changes: 22 additions & 0 deletions includes/class-type-registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public function init() {
Type\WPEnum\Product_Attribute_Enum::register();
Type\WPEnum\Attribute_Operator_Enum::register();
Type\WPEnum\Currency_Enum::register();
Type\WPEnum\Shipping_Location_Type_Enum::register();
Type\WPEnum\WC_Setting_Type_Enum::register();

/**
* InputObjects.
Expand All @@ -66,6 +68,7 @@ public function init() {
Type\WPInputObject\Collection_Stats_Query_Input::register();
Type\WPInputObject\Collection_Stats_Where_Args::register();
Type\WPInputObject\Product_Attribute_Filter_Input::register();
Type\WPInputObject\Shipping_Location_Input::register();

/**
* Interfaces.
Expand Down Expand Up @@ -111,6 +114,10 @@ public function init() {
Type\WPObject\Payment_Token_Types::register();
Type\WPObject\Country_State_Type::register();
Type\WPObject\Collection_Stats_Type::register();
Type\WPObject\Shipping_Zone_Type::register();
Type\WPObject\Shipping_Location_Type::register();
Type\WPObject\Tax_Class_Type::register();
Type\WPObject\WC_Setting_Type::register();

/**
* Object fields.
Expand Down Expand Up @@ -144,6 +151,8 @@ public function init() {
Connection\Tax_Rates::register_connections();
Connection\Shipping_Methods::register_connections();
Connection\Payment_Gateways::register_connections();
Connection\Shipping_Zones::register_connections();
Connection\Tax_Classes::register_connections();

/**
* Mutations.
Expand Down Expand Up @@ -174,6 +183,19 @@ public function init() {
Mutation\Coupon_Delete::register_mutation();
Mutation\Payment_Method_Delete::register_mutation();
Mutation\Payment_Method_Set_Default::register_mutation();
Mutation\Shipping_Zone_Create::register_mutation();
Mutation\Shipping_Zone_Delete::register_mutation();
Mutation\Shipping_Zone_Locations_Clear::register_mutation();
Mutation\Shipping_Zone_Locations_Update::register_mutation();
Mutation\Shipping_Zone_Method_Add::register_mutation();
Mutation\Shipping_Zone_Method_Remove::register_mutation();
Mutation\Shipping_Zone_Method_Update::register_mutation();
Mutation\Shipping_Zone_Update::register_mutation();
Mutation\Tax_Class_Create::register_mutation();
Mutation\Tax_Class_Delete::register_mutation();
Mutation\Tax_Rate_Create::register_mutation();
Mutation\Tax_Rate_Delete::register_mutation();
Mutation\Tax_Rate_Update::register_mutation();
Mutation\Update_Session::register_mutation();
}
}
27 changes: 26 additions & 1 deletion includes/class-wp-graphql-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ private function includes() {
require $include_directory_path . 'model/class-order.php';
require $include_directory_path . 'model/class-order-item.php';
require $include_directory_path . 'model/class-shipping-method.php';
require $include_directory_path . 'model/class-shipping-zone.php';
require $include_directory_path . 'model/class-tax-rate.php';

// Include data loaders class files.
Expand All @@ -190,13 +191,15 @@ private function includes() {
require $include_directory_path . 'data/connection/class-order-item-connection-resolver.php';
require $include_directory_path . 'data/connection/class-payment-gateway-connection-resolver.php';
require $include_directory_path . 'data/connection/class-product-attribute-connection-resolver.php';
require $include_directory_path . 'data/connection/class-product-connection-resolver.php';
require $include_directory_path . 'data/connection/class-shipping-method-connection-resolver.php';
require $include_directory_path . 'data/connection/class-shipping-zone-connection-resolver.php';
require $include_directory_path . 'data/connection/class-tax-class-connection-resolver.php';
require $include_directory_path . 'data/connection/class-tax-rate-connection-resolver.php';
require $include_directory_path . 'data/connection/class-variation-attribute-connection-resolver.php';

// Include deprecated resolver trait/class files.
require $include_directory_path . 'data/connection/class-coupon-connection-resolver.php';
require $include_directory_path . 'data/connection/class-product-connection-resolver.php';
require $include_directory_path . 'data/connection/class-customer-connection-resolver.php';

// Include mutation processor class files.
Expand Down Expand Up @@ -239,6 +242,8 @@ private function includes() {
require $include_directory_path . 'type/enum/class-attribute-operator-enum.php';
require $include_directory_path . 'type/enum/class-product-attribute-enum.php';
require $include_directory_path . 'type/enum/class-currency-enum.php';
require $include_directory_path . 'type/enum/class-shipping-location-type-enum.php';
require $include_directory_path . 'type/enum/class-wc-setting-type-enum.php';

// Include interface type class files.
require $include_directory_path . 'type/interface/class-attribute.php';
Expand Down Expand Up @@ -282,6 +287,10 @@ private function includes() {
require $include_directory_path . 'type/object/class-payment-token-types.php';
require $include_directory_path . 'type/object/class-country-state-type.php';
require $include_directory_path . 'type/object/class-collection-stats-type.php';
require $include_directory_path . 'type/object/class-shipping-location-type.php';
require $include_directory_path . 'type/object/class-shipping-zone-type.php';
require $include_directory_path . 'type/object/class-tax-class-type.php';
require $include_directory_path . 'type/object/class-wc-setting-type.php';

// Include input type class files.
require $include_directory_path . 'type/input/class-cart-item-input.php';
Expand All @@ -300,6 +309,7 @@ private function includes() {
require $include_directory_path . 'type/input/class-collection-stats-query-input.php';
require $include_directory_path . 'type/input/class-collection-stats-where-args.php';
require $include_directory_path . 'type/input/class-product-attribute-filter-input.php';
require $include_directory_path . 'type/input/class-shipping-location-input.php';

// Include mutation type class files.
require $include_directory_path . 'mutation/class-cart-add-fee.php';
Expand Down Expand Up @@ -328,6 +338,19 @@ private function includes() {
require $include_directory_path . 'mutation/class-review-update.php';
require $include_directory_path . 'mutation/class-payment-method-delete.php';
require $include_directory_path . 'mutation/class-payment-method-set-default.php';
require $include_directory_path . 'mutation/class-shipping-zone-create.php';
require $include_directory_path . 'mutation/class-shipping-zone-delete.php';
require $include_directory_path . 'mutation/class-shipping-zone-locations-clear.php';
require $include_directory_path . 'mutation/class-shipping-zone-locations-update.php';
require $include_directory_path . 'mutation/class-shipping-zone-method-add.php';
require $include_directory_path . 'mutation/class-shipping-zone-method-remove.php';
require $include_directory_path . 'mutation/class-shipping-zone-method-update.php';
require $include_directory_path . 'mutation/class-shipping-zone-update.php';
require $include_directory_path . 'mutation/class-tax-class-create.php';
require $include_directory_path . 'mutation/class-tax-class-delete.php';
require $include_directory_path . 'mutation/class-tax-rate-create.php';
require $include_directory_path . 'mutation/class-tax-rate-delete.php';
require $include_directory_path . 'mutation/class-tax-rate-update.php';
require $include_directory_path . 'mutation/class-update-session.php';

// Include connection class/function files.
Expand All @@ -341,6 +364,8 @@ private function includes() {
require $include_directory_path . 'connection/class-product-attributes.php';
require $include_directory_path . 'connection/class-products.php';
require $include_directory_path . 'connection/class-shipping-methods.php';
require $include_directory_path . 'connection/class-shipping-zones.php';
require $include_directory_path . 'connection/class-tax-classes.php';
require $include_directory_path . 'connection/class-tax-rates.php';
require $include_directory_path . 'connection/class-wc-terms.php';

Expand Down
63 changes: 63 additions & 0 deletions includes/connection/class-shipping-zones.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* Connection - Shipping_Zones
*
* Registers connections to ShippingZone
*
* @package WPGraphQL\WooCommerce\Connection
* @since TBD
*/

namespace WPGraphQL\WooCommerce\Connection;

use GraphQL\Type\Definition\ResolveInfo;
use WPGraphQL\AppContext;
use WPGraphQL\WooCommerce\Data\Connection\Shipping_Zone_Connection_Resolver;

/**
* Class - Shipping_Zones
*/
class Shipping_Zones {
/**
* Registers the various connections from other Types to ShippingZone
*
* @return void
*/
public static function register_connections() {
// From RootQuery.
register_graphql_connection( self::get_connection_config() );
}

/**
* Given an array of $args, this returns the connection config, merging the provided args
* with the defaults.
*
* @param array $args - Connection configuration.
* @return array
*/
public static function get_connection_config( $args = [] ): array {
return array_merge(
[
'fromType' => 'RootQuery',
'toType' => 'ShippingZone',
'fromFieldName' => 'shippingZones',
'connectionArgs' => [],
'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) {
$resolver = new Shipping_Zone_Connection_Resolver( $source, $args, $context, $info );

return $resolver->get_connection();
},
],
$args
);
}

/**
* Returns array of where args.
*
* @return array
*/
public static function get_connection_args(): array {
return [];
}
}
63 changes: 63 additions & 0 deletions includes/connection/class-tax-classes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* Connection - Tax_Classes
*
* Registers connections to TaxClass
*
* @package WPGraphQL\WooCommerce\Connection
* @since TBD
*/

namespace WPGraphQL\WooCommerce\Connection;

use GraphQL\Type\Definition\ResolveInfo;
use WPGraphQL\AppContext;
use WPGraphQL\WooCommerce\Data\Connection\Tax_Class_Connection_Resolver;

/**
* Class - TaxClass
*/
class Tax_Classes {
/**
* Registers the various connections from other Types to TaxClass
*
* @return void
*/
public static function register_connections() {
// From RootQuery.
register_graphql_connection( self::get_connection_config() );
}

/**
* Given an array of $args, this returns the connection config, merging the provided args
* with the defaults.
*
* @param array $args - Connection configuration.
* @return array
*/
public static function get_connection_config( $args = [] ): array {
return array_merge(
[
'fromType' => 'RootQuery',
'toType' => 'TaxClass',
'fromFieldName' => 'taxClasses',
'connectionArgs' => [],
'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) {
$resolver = new Tax_Class_Connection_Resolver( $source, $args, $context, $info );

return $resolver->get_connection();
},
],
$args
);
}

/**
* Returns array of where args.
*
* @return array
*/
public static function get_connection_args(): array {
return [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace WPGraphQL\WooCommerce\Data\Connection;

use WPGraphQL\Data\Connection\AbstractConnectionResolver;
use WPGraphQL\WooCommerce\Model\Shipping_Zone;

/**
* Class Shipping_Method_Connection_Resolver
Expand Down Expand Up @@ -50,27 +51,25 @@ public function get_query_args() {
* @return array|mixed|string[]
*/
public function get_query() {
// TODO: Implement get_query() method.
$wc_shipping = \WC_Shipping::instance();
$methods = $wc_shipping->get_shipping_methods();
if ( $this->source instanceof Shipping_Zone ) {
$methods = $this->source->methods;

Check failure on line 55 in includes/data/connection/class-shipping-method-connection-resolver.php

View workflow job for this annotation

GitHub Actions / Testing WooGraphQL code quality w/ PHPStan

Access to an undefined property WPGraphQL\WooCommerce\Model\Shipping_Zone::$methods.
} else {
$wc_shipping = \WC_Shipping::instance();
$methods = $wc_shipping->get_shipping_methods();
}

// Get shipping method IDs.
$methods = array_map(
static function ( $item ) {
return $item->id;
},
array_values( $methods )
);
$methods = wp_list_pluck( array_values( $methods ), 'id' );

return $methods;
}

/**
* Return an array of items from the query
*
* @return array|mixed
* @return array
*/
public function get_ids() {
public function get_ids_from_query() {
return ! empty( $this->query ) ? $this->query : [];
}

Expand Down
Loading

0 comments on commit e73eb7c

Please sign in to comment.