mirror of
https://github.com/wp-graphql/wp-graphql-woocommerce.git
synced 2026-08-14 12:53:44 +02:00
Merge pull request #158 from kidunot89/feature/wp-graphql-acf-integration
Fixes WPGraphQL ACF integration
This commit is contained in:
@@ -22,7 +22,6 @@ branches:
|
||||
cache:
|
||||
apt: true
|
||||
directories:
|
||||
- vendor
|
||||
- $HOME/.composer/cache
|
||||
|
||||
matrix:
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* Adds filters that modify WPGraphQL ACF schema.
|
||||
*
|
||||
* @package \WPGraphQL\Extensions\WooCommerce
|
||||
* @since 0.2.2
|
||||
*/
|
||||
|
||||
namespace WPGraphQL\Extensions\WooCommerce;
|
||||
|
||||
/**
|
||||
* Class ACF_Schema_Filters
|
||||
*/
|
||||
class ACF_Schema_Filters {
|
||||
|
||||
/**
|
||||
* Register filters
|
||||
*/
|
||||
public static function add_filters() {
|
||||
// Registers WooCommerce CPTs && taxonomies.
|
||||
add_filter( 'graphql_acf_get_root_id', array( __CLASS__, 'resolve_crud_root_id' ), 10, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve post object ID from CRUD object Model.
|
||||
*
|
||||
* @param integer|null $id Post object database ID.
|
||||
* @param mixed $root Root resolver.
|
||||
*
|
||||
* @return integer|null
|
||||
*/
|
||||
public static function resolve_crud_root_id( $id, $root ) {
|
||||
switch ( true ) {
|
||||
case $root instanceof \WPGraphQL\Extensions\WooCommerce\Model\CRUD_CPT:
|
||||
$id = absint( $root->ID );
|
||||
break;
|
||||
}
|
||||
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,11 @@ class Core_Schema_Filters {
|
||||
* Register filters
|
||||
*/
|
||||
public static function add_filters() {
|
||||
// Registers WooCommerce CPTs.
|
||||
add_filter( 'register_post_type_args', array( __CLASS__, 'register_post_types' ), 10, 2 );
|
||||
add_filter( 'graphql_post_entities_allowed_post_types', array( __CLASS__, 'skip_type_registry' ), 10 );
|
||||
add_filter( 'graphql_union_resolve_type', array( __CLASS__, 'graphql_union_resolve_type' ), 10, 3 );
|
||||
|
||||
// Registers WooCommerce taxonomies.
|
||||
add_filter( 'register_taxonomy_args', array( __CLASS__, 'register_taxonomy_args' ), 10, 2 );
|
||||
|
||||
@@ -102,10 +107,72 @@ class Core_Schema_Filters {
|
||||
return self::$customer_loader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers WooCommerce post-types to be used in GraphQL schema
|
||||
*
|
||||
* @param array $args - allowed post-types.
|
||||
* @param string $post_type - name of taxonomy being checked.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function register_post_types( $args, $post_type ) {
|
||||
if ( 'product' === $post_type ) {
|
||||
$args['show_in_graphql'] = true;
|
||||
$args['graphql_single_name'] = 'Product';
|
||||
$args['graphql_plural_name'] = 'Products';
|
||||
$args['skip_graphql_type_registry'] = true;
|
||||
}
|
||||
if ( 'product_variation' === $post_type ) {
|
||||
$args['show_in_graphql'] = true;
|
||||
$args['graphql_single_name'] = 'ProductVariation';
|
||||
$args['graphql_plural_name'] = 'ProductVariations';
|
||||
$args['skip_graphql_type_registry'] = true;
|
||||
}
|
||||
if ( 'shop_coupon' === $post_type ) {
|
||||
$args['show_in_graphql'] = true;
|
||||
$args['graphql_single_name'] = 'Coupon';
|
||||
$args['graphql_plural_name'] = 'Coupons';
|
||||
$args['skip_graphql_type_registry'] = true;
|
||||
}
|
||||
if ( 'shop_order' === $post_type ) {
|
||||
$args['show_in_graphql'] = true;
|
||||
$args['graphql_single_name'] = 'Order';
|
||||
$args['graphql_plural_name'] = 'Orders';
|
||||
$args['skip_graphql_type_registry'] = true;
|
||||
}
|
||||
if ( 'shop_order_refund' === $post_type ) {
|
||||
$args['show_in_graphql'] = true;
|
||||
$args['graphql_single_name'] = 'Refund';
|
||||
$args['graphql_plural_name'] = 'Refunds';
|
||||
$args['skip_graphql_type_registry'] = true;
|
||||
}
|
||||
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters "allowed_post_types" and removed Woocommerce CPTs.
|
||||
*
|
||||
* @param array $post_types Post types registered in GraphQL schema.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function skip_type_registry( $post_types ) {
|
||||
return array_diff(
|
||||
$post_types,
|
||||
get_post_types(
|
||||
[
|
||||
'show_in_graphql' => true,
|
||||
'skip_graphql_type_registry' => true,
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers WooCommerce taxonomies to be used in GraphQL schema
|
||||
*
|
||||
* @param array $args - allowed post-types.
|
||||
* @param array $args - allowed taxonomies.
|
||||
* @param string $taxonomy - name of taxonomy being checked.
|
||||
*
|
||||
* @return array
|
||||
|
||||
@@ -149,6 +149,9 @@ if ( ! class_exists( 'WP_GraphQL_WooCommerce' ) ) :
|
||||
// Register WPGraphQL core filters.
|
||||
\WPGraphQL\Extensions\WooCommerce\Core_Schema_Filters::add_filters();
|
||||
|
||||
// Register WPGraphQL ACF filters.
|
||||
\WPGraphQL\Extensions\WooCommerce\ACF_Schema_Filters::add_filters();
|
||||
|
||||
// Register WPGraphQL JWT Authentication filters.
|
||||
\WPGraphQL\Extensions\WooCommerce\JWT_Auth_Schema_Filters::add_filters();
|
||||
|
||||
|
||||
@@ -487,7 +487,7 @@ class Product_Connection_Resolver extends AbstractConnectionResolver {
|
||||
|
||||
// Handle visibility.
|
||||
$post_type_obj = get_post_type_object( $this->post_type );
|
||||
if ( ! empty( $where_args['visibility'] ) && current_user_can( $post_type_obj->cap->read_private_posts ) ) {
|
||||
if ( ! empty( $where_args['visibility'] ) ) {
|
||||
switch ( $where_args['visibility'] ) {
|
||||
case 'search':
|
||||
$tax_query[] = array(
|
||||
|
||||
@@ -30,7 +30,7 @@ class Coupon_Type {
|
||||
'Coupon',
|
||||
array(
|
||||
'description' => __( 'A coupon object', 'wp-graphql-woocommerce' ),
|
||||
'interfaces' => array('Node'),
|
||||
'interfaces' => array( 'Node' ),
|
||||
'fields' => array(
|
||||
'id' => array(
|
||||
'type' => array( 'non_null' => 'ID' ),
|
||||
|
||||
@@ -31,7 +31,7 @@ class Customer_Type {
|
||||
'Customer',
|
||||
array(
|
||||
'description' => __( 'A customer object', 'wp-graphql-woocommerce' ),
|
||||
'interfaces' => array('Node'),
|
||||
'interfaces' => array( 'Node' ),
|
||||
'fields' => array(
|
||||
'id' => array(
|
||||
'type' => array( 'non_null' => 'ID' ),
|
||||
|
||||
@@ -30,7 +30,7 @@ class Order_Type {
|
||||
'Order',
|
||||
array(
|
||||
'description' => __( 'A order object', 'wp-graphql-woocommerce' ),
|
||||
'interfaces' => array('Node'),
|
||||
'interfaces' => array( 'Node' ),
|
||||
'fields' => array(
|
||||
'id' => array(
|
||||
'type' => array( 'non_null' => 'ID' ),
|
||||
|
||||
@@ -31,7 +31,7 @@ class Product_Type {
|
||||
'Product',
|
||||
array(
|
||||
'description' => __( 'A product object', 'wp-graphql-woocommerce' ),
|
||||
'interfaces' => array('Node'),
|
||||
'interfaces' => array( 'Node' ),
|
||||
'fields' => array(
|
||||
'id' => array(
|
||||
'type' => array( 'non_null' => 'ID' ),
|
||||
|
||||
@@ -31,7 +31,7 @@ class Product_Variation_Type {
|
||||
'ProductVariation',
|
||||
array(
|
||||
'description' => __( 'A product variation object', 'wp-graphql-woocommerce' ),
|
||||
'interfaces' => array('Node'),
|
||||
'interfaces' => array( 'Node' ),
|
||||
'fields' => array(
|
||||
'id' => array(
|
||||
'type' => array( 'non_null' => 'ID' ),
|
||||
|
||||
@@ -30,7 +30,7 @@ class Refund_Type {
|
||||
'Refund',
|
||||
array(
|
||||
'description' => __( 'A refund object', 'wp-graphql-woocommerce' ),
|
||||
'interfaces' => array('Node'),
|
||||
'interfaces' => array( 'Node' ),
|
||||
'fields' => array(
|
||||
'id' => array(
|
||||
'type' => array( 'non_null' => 'ID' ),
|
||||
|
||||
@@ -30,7 +30,7 @@ class Shipping_Method_Type {
|
||||
'ShippingMethod',
|
||||
array(
|
||||
'description' => __( 'A shipping method object', 'wp-graphql-woocommercer' ),
|
||||
'interfaces' => array('Node'),
|
||||
'interfaces' => array( 'Node' ),
|
||||
'fields' => array(
|
||||
'id' => array(
|
||||
'type' => array( 'non_null' => 'ID' ),
|
||||
|
||||
+1
@@ -6,6 +6,7 @@ $vendorDir = dirname(dirname(__FILE__));
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
'WPGraphQL\\Extensions\\WooCommerce\\ACF_Schema_Filters' => $baseDir . '/includes/class-acf-schema-filters.php',
|
||||
'WPGraphQL\\Extensions\\WooCommerce\\Connection\\Cart_Items' => $baseDir . '/includes/connection/class-cart-items.php',
|
||||
'WPGraphQL\\Extensions\\WooCommerce\\Connection\\Coupons' => $baseDir . '/includes/connection/class-coupons.php',
|
||||
'WPGraphQL\\Extensions\\WooCommerce\\Connection\\Customers' => $baseDir . '/includes/connection/class-customers.php',
|
||||
|
||||
Vendored
+1
@@ -25,6 +25,7 @@ class ComposerStaticInit71eeabde6fbf0f089c103ca7b0ed7868
|
||||
);
|
||||
|
||||
public static $classMap = array (
|
||||
'WPGraphQL\\Extensions\\WooCommerce\\ACF_Schema_Filters' => __DIR__ . '/../..' . '/includes/class-acf-schema-filters.php',
|
||||
'WPGraphQL\\Extensions\\WooCommerce\\Connection\\Cart_Items' => __DIR__ . '/../..' . '/includes/connection/class-cart-items.php',
|
||||
'WPGraphQL\\Extensions\\WooCommerce\\Connection\\Coupons' => __DIR__ . '/../..' . '/includes/connection/class-coupons.php',
|
||||
'WPGraphQL\\Extensions\\WooCommerce\\Connection\\Customers' => __DIR__ . '/../..' . '/includes/connection/class-customers.php',
|
||||
|
||||
@@ -94,7 +94,7 @@ function wp_graphql_woocommerce_init() {
|
||||
<?php
|
||||
printf(
|
||||
/* translators: dependency not ready error message */
|
||||
esc_html__( '%1$s must be active for wp-graphql-woocommerce to work', 'wp-graphql-woocommerce' ),
|
||||
esc_html__( '%1$s must be active for "WPGraphQL WooCommerce (WooGraphQL)" to work', 'wp-graphql-woocommerce' ),
|
||||
esc_html( $dep )
|
||||
);
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user