-
-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/Product type #7
Merged
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d0b49a2
initial commit
kidunot89 2858535
Product type implemented
kidunot89 1a7c884
Coupon, Product, and WCTerm connections implemented
kidunot89 74f40e9
product attribute types and connections
kidunot89 b92d255
Product<->MediaItem connection implemented
kidunot89 65cd43a
enumerations added
kidunot89 463fed4
enumerations added
kidunot89 c0c211e
productBy argument slug resolver fixed
kidunot89 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -150,19 +150,14 @@ install_db() { | |
|
||
# create database | ||
RESULT=`mysql -u $DB_USER --password="$DB_PASS" --skip-column-names -e "SHOW DATABASES LIKE '$DB_NAME'"$EXTRA` | ||
if [ "$RESULT" != $DB_NAME ]; then | ||
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA | ||
fi | ||
|
||
RESULT_2=`mysql -u $DB_USER --password="$DB_PASS" --skip-column-names -e "SHOW DATABASES LIKE '$DB_SERVE_NAME'"$EXTRA` | ||
if [ "$RESULT_2" != $DB_SERVE_NAME ]; then | ||
mysqladmin create $DB_SERVE_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA | ||
fi | ||
if [ "$RESULT" != $DB_NAME ]; then | ||
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA | ||
fi | ||
} | ||
|
||
configure_wordpress() { | ||
cd $WP_CORE_DIR | ||
wp config create --dbname="$DB_SERVE_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST" --skip-check --force=true | ||
wp config create --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST" --skip-check --force=true | ||
wp core install --url=wp.test --title="WPGraphQL WooCommerce Tests" --admin_user=admin --admin_password=password [email protected] | ||
wp rewrite structure '/%year%/%monthnum%/%postname%/' | ||
} | ||
|
@@ -172,17 +167,21 @@ setup_woocommerce() { | |
wp plugin install wordpress-importer --activate | ||
echo "Installing & Activating WooCommerce" | ||
wp plugin install woocommerce --activate | ||
wp import $WP_CORE_DIR/wp-content/plugins/woocommerce/sample-data/sample_products.xml --authors=skip | ||
wp import $WP_CORE_DIR/wp-content/plugins/woocommerce/sample-data/sample_products.xml --authors=$PLUGIN_DIR/bin/usermap.csv --path=$WP_CORE_DIR | ||
} | ||
|
||
setup_wpgraphql() { | ||
echo "Cloning WPGraphQL" | ||
git clone https://github.com/wp-graphql/wp-graphql.git $WP_CORE_DIR/wp-content/plugins/wp-graphql | ||
if [ ! -d $WP_CORE_DIR/wp-content/plugins/wp-graphql ]; then | ||
echo "Cloning WPGraphQL" | ||
git clone https://github.com/wp-graphql/wp-graphql.git $WP_CORE_DIR/wp-content/plugins/wp-graphql | ||
fi | ||
echo "Activating WPGraphQL" | ||
wp plugin activate wp-graphql | ||
|
||
echo "Cloning WPGraphQL-JWT-Authentication" | ||
git clone https://github.com/wp-graphql/wp-graphql-jwt-authentication.git $WP_CORE_DIR/wp-content/plugins/wp-graphql-jwt-authentication | ||
if [ ! -d $WP_CORE_DIR/wp-content/plugins/wp-graphql-jwt-authentication ]; then | ||
echo "Cloning WPGraphQL-JWT-Authentication" | ||
git clone https://github.com/wp-graphql/wp-graphql-jwt-authentication.git $WP_CORE_DIR/wp-content/plugins/wp-graphql-jwt-authentication | ||
fi | ||
echo "Activating WPGraphQL-JWT-Authentication" | ||
wp plugin activate wp-graphql-jwt-authentication | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
old_user_login,new_user_login | ||
ryanr14,admin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
paths: | ||
tests: tests | ||
output: tests/_output | ||
data: tests/_data | ||
support: tests/_support | ||
envs: tests/_envs | ||
actor_suffix: Tester | ||
extensions: | ||
enabled: | ||
- Codeception\Extension\RunFailed | ||
commands: | ||
- Codeception\Command\GenerateWPUnit | ||
- Codeception\Command\GenerateWPRestApi | ||
- Codeception\Command\GenerateWPRestController | ||
- Codeception\Command\GenerateWPRestPostTypeController | ||
- Codeception\Command\GenerateWPAjax | ||
- Codeception\Command\GenerateWPCanonical | ||
- Codeception\Command\GenerateWPXMLRPC | ||
params: | ||
- .env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace WPGraphQL\Extensions\WooCommerce\Connection; | ||
|
||
use WPGraphQL\Extensions\WooCommerce\Data\Factory; | ||
|
||
/** | ||
* Class ProductCategories | ||
* | ||
* This class organizes the registration of connections to ProductCategories | ||
* | ||
* @package WPGraphQL\Connection | ||
*/ | ||
class ProductCategories { | ||
|
||
/** | ||
* Registers the various connections from other Types to Coupons | ||
*/ | ||
public static function register_connections() { | ||
/** | ||
* Type connections | ||
*/ | ||
register_graphql_connection( self::get_connection_config() ); | ||
register_graphql_connection( self::get_connection_config( [ | ||
'fromType' => 'Coupon', | ||
'fromFieldName' => 'productCategories', | ||
] ) ); | ||
register_graphql_connection( self::get_connection_config( [ | ||
'fromType' => 'Coupon', | ||
'fromFieldName' => 'excludedProductCategories', | ||
] ) ); | ||
} | ||
|
||
/** | ||
* Given an array of $args, this returns the connection config, merging the provided args | ||
* with the defaults | ||
* | ||
* @access public | ||
* @param array $args | ||
* | ||
* @return array | ||
*/ | ||
public static function get_connection_config( $args = [] ) { | ||
$defaults = [ | ||
'fromType' => 'Product', | ||
'toType' => 'ProductCategory', | ||
'fromFieldName' => 'categories', | ||
'connectionArgs' => [], | ||
'resolve' => function ( $root, $args, $context, $info ) { | ||
return Factory::resolve_product_category_connection( $root, $args, $context, $info ); | ||
}, | ||
]; | ||
|
||
return array_merge( $defaults, $args ); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace WPGraphQL\Extensions\WooCommerce\Connection; | ||
|
||
use WPGraphQL\Extensions\WooCommerce\Data\Factory; | ||
|
||
/** | ||
* Class ProductTags | ||
* | ||
* This class organizes the registration of connections to ProductTags | ||
* | ||
* @package WPGraphQL\Connection | ||
*/ | ||
class ProductTags { | ||
|
||
/** | ||
* Registers the various connections from other Types to Coupons | ||
*/ | ||
public static function register_connections() { | ||
/** | ||
* Type connections | ||
*/ | ||
register_graphql_connection( self::get_connection_config() ); | ||
} | ||
|
||
/** | ||
* Given an array of $args, this returns the connection config, merging the provided args | ||
* with the defaults | ||
* | ||
* @access public | ||
* @param array $args | ||
* | ||
* @return array | ||
*/ | ||
public static function get_connection_config( $args = [] ) { | ||
$defaults = [ | ||
'fromType' => 'Product', | ||
'toType' => 'ProductTag', | ||
'fromFieldName' => 'tags', | ||
'connectionArgs' => [], | ||
'resolve' => function ( $root, $args, $context, $info ) { | ||
return Factory::resolve_product_tag_connection( $root, $args, $context, $info ); | ||
}, | ||
]; | ||
|
||
return array_merge( $defaults, $args ); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
|
||
namespace WPGraphQL\Extensions\WooCommerce\Connection; | ||
|
||
use WPGraphQL\Extensions\WooCommerce\Data\Factory; | ||
|
||
/** | ||
* Class Products | ||
* | ||
* This class organizes the registration of connections to Coupons | ||
* | ||
* @package WPGraphQL\Connection | ||
*/ | ||
class Products { | ||
/** | ||
* Registers the various connections from other Types to Coupons | ||
*/ | ||
public static function register_connections() { | ||
/** | ||
* Root connections | ||
*/ | ||
register_graphql_connection( self::get_connection_config() ); | ||
|
||
/** | ||
* Taxonomy connections | ||
*/ | ||
register_graphql_connection( self::get_connection_config( [ | ||
'fromType' => 'productTag' | ||
] ) ); | ||
register_graphql_connection( self::get_connection_config( [ | ||
'fromType' => 'productCategory' | ||
] ) ); | ||
|
||
/** | ||
* Type connections | ||
*/ | ||
register_graphql_connection( self::get_connection_config( [ | ||
'fromType' => 'Product', | ||
'fromFieldName' => 'upsell' | ||
] ) ); | ||
register_graphql_connection( self::get_connection_config( [ | ||
'fromType' => 'Product', | ||
'fromFieldName' => 'crossSell' | ||
] ) ); | ||
register_graphql_connection( self::get_connection_config( [ | ||
'fromType' => 'Product', | ||
'fromFieldName' => 'variations' | ||
] ) ); | ||
register_graphql_connection( self::get_connection_config( [ | ||
'fromType' => 'Coupon', | ||
'fromFieldName' => 'products' | ||
] ) ); | ||
register_graphql_connection( self::get_connection_config( [ | ||
'fromType' => 'Coupon', | ||
'fromFieldName' => 'excludedProducts' | ||
] ) ); | ||
} | ||
|
||
/** | ||
* Given an array of $args, this returns the connection config, merging the provided args | ||
* with the defaults | ||
* | ||
* @access public | ||
* @param array $args | ||
* | ||
* @return array | ||
*/ | ||
public static function get_connection_config( $args = [] ) { | ||
$defaults = [ | ||
'fromType' => 'RootQuery', | ||
'toType' => 'Product', | ||
'fromFieldName' => 'products', | ||
'connectionArgs' => self::get_connection_args(), | ||
'resolve' => function ( $root, $args, $context, $info ) { | ||
return Factory::resolve_product_connection( $root, $args, $context, $info ); | ||
}, | ||
]; | ||
|
||
return array_merge( $defaults, $args ); | ||
} | ||
|
||
/** | ||
* This returns the connection args for the Product connection | ||
* | ||
* @access public | ||
* @return array | ||
*/ | ||
public static function get_connection_args() { | ||
return [ | ||
'slug' => [ | ||
'type' => 'String', | ||
'description' => __( 'Product slug', 'wp-graphql-woocommerce' ), | ||
] | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kidunot89 Is the idea to create a product implementation for each type of products?
WC_Product_Simple
,WC_Product_Variation
, etc?If yes, can we do something to verify the
WC_Product
and classes that extendWC_Abstract_Legacy_Product
?That would allow
WC_Product_Subscription_Variation
,WC_Product_Subscription
, and other product types to work without having to create their own product implementation.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolve_product
is only used in the root queriesproduct
andproductBy
, however I will add the ability to filter theresolver
of theProduct
type, if this does not work for other Woo extensions