Skip to content

Commit

Permalink
fix: Bug fixed in Product_Connection_Resolver::add_tax_query (#820)
Browse files Browse the repository at this point in the history
* fix: Bug fixed in Product_Connection_Resolver::add_tax_query

* fix: some product connection resolver hooks restored
  • Loading branch information
kidunot89 authored Dec 22, 2023
1 parent e962366 commit 753a0fa
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 35 deletions.
1 change: 1 addition & 0 deletions bin/_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ setup_plugin() {
cd $WP_CORE_DIR

# Activate the plugin, it's dependencies should be activated already.
wp plugin activate woocommerce wp-graphql
wp plugin activate wp-graphql-woocommerce

# Flush the permalinks
Expand Down
1 change: 0 additions & 1 deletion codeception.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ modules:
domain: '%WORDPRESS_DOMAIN%'
adminEmail: '%ADMIN_EMAIL%'
title: 'WooGraphQL Tests'
theme: 'twentytwentyone'
plugins:
- woocommerce/woocommerce.php
- woocommerce-gateway-stripe/woocommerce-gateway-stripe.php
Expand Down
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 14 additions & 11 deletions includes/data/connection/class-product-connection-resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,16 +252,19 @@ public function get_ids_from_query() {
* @return array
*/
public function ordering_meta() {
return [
'_price',
'_regular_price',
'_sale_price',
'_wc_rating_count',
'_wc_average_rating',
'_sale_price_dates_from',
'_sale_price_dates_to',
'total_sales',
];
return apply_filters(
'graphql_woocommerce_products_add_sort_fields',
[
'_price',
'_regular_price',
'_sale_price',
'_wc_rating_count',
'_wc_average_rating',
'_sale_price_dates_from',
'_sale_price_dates_to',
'total_sales',
]
);
}

/**
Expand Down Expand Up @@ -660,7 +663,7 @@ public function add_meta_query( $value ) {
* @return \WPGraphQL\WooCommerce\Data\Connection\Product_Connection_Resolver
*/
public function add_tax_query( $value ) {
if ( ! empty( $this->query_args['tax_query'] ) ) {
if ( empty( $this->query_args['tax_query'] ) ) {
$this->query_args['tax_query'] = $value; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query
} else {
$this->query_args['tax_query'][] = $value;
Expand Down
30 changes: 17 additions & 13 deletions tests/wpunit/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<?php

use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController;
use Automattic\WooCommerce\Internal\DataStores\Orders\DataSynchronizer;
use Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableDataStore;
use Automattic\WooCommerce\Internal\Features\FeaturesController;

/**
* Remove the "extensions" payload from GraphQL results
* so that tests can make assertions without worrying about what's in the extensions payload
Expand All @@ -23,10 +18,10 @@ static function ( $response ) {
* Helper method to drop custom tables if present.
*/
function delete_order_custom_tables() {
$features_controller = wc_get_container()->get( Featurescontroller::class );
$features_controller = wc_get_container()->get( \Automattic\WooCommerce\Internal\Features\FeaturesController::class );
$features_controller->change_feature_enable( 'custom_order_tables', true );
$synchronizer = wc_get_container()
->get( DataSynchronizer::class );
->get( \Automattic\WooCommerce\Internal\DataStores\Orders\DataSynchronizer::class );
if ( $synchronizer->check_orders_table_exists() ) {
$synchronizer->delete_database_tables();
}
Expand All @@ -39,24 +34,33 @@ function delete_order_custom_tables() {
* @return void
*/
function toggle_cot( bool $enabled ) {
$features_controller = wc_get_container()->get( Featurescontroller::class );
$features_controller = wc_get_container()->get( \Automattic\WooCommerce\Internal\Features\FeaturesController::class );
$features_controller->change_feature_enable( 'custom_order_tables', $enabled );

update_option( CustomOrdersTableController::CUSTOM_ORDERS_TABLE_USAGE_ENABLED_OPTION, wc_bool_to_string( $enabled ) );
update_option(
\Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController::CUSTOM_ORDERS_TABLE_USAGE_ENABLED_OPTION,
wc_bool_to_string( $enabled )
);

// Confirm things are really correct.
$wc_data_store = WC_Data_Store::load( 'order' );
assert( is_a( $wc_data_store->get_current_class_name(), OrdersTableDataStore::class, true ) === $enabled );
assert(
is_a(
$wc_data_store->get_current_class_name(),
\Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableDataStore::class,
true
) === $enabled
);
}

/**
* Helper method to create custom tables if not present.
*/
function create_order_custom_table_if_not_exist() {
$features_controller = wc_get_container()->get( Featurescontroller::class );
$features_controller = wc_get_container()->get( \Automattic\WooCommerce\Internal\Features\FeaturesController::class );
$features_controller->change_feature_enable( 'custom_order_tables', true );

$synchronizer = wc_get_container()->get( DataSynchronizer::class );
$synchronizer = wc_get_container()->get( \Automattic\WooCommerce\Internal\DataStores\Orders\DataSynchronizer::class );
if ( ! $synchronizer->check_orders_table_exists() ) {
$synchronizer->create_database_tables();
}
Expand All @@ -75,5 +79,5 @@ function initialize_hpos() {

if ( defined( 'HPOS' ) ) {
\codecept_debug( 'HPOS activated!!!' );
initialize_hpos();
//add_action( 'woocommerce_init', 'initialize_hpos' );
}
9 changes: 5 additions & 4 deletions vendor-prefixed/firebase/php-jwt/src/JWT.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,14 @@ public static function encode(
string $keyId = null,
array $head = null
): string {
$header = ['typ' => 'JWT', 'alg' => $alg];
$header = ['typ' => 'JWT'];
if (isset($head) && \is_array($head)) {
$header = \array_merge($header, $head);
}
$header['alg'] = $alg;
if ($keyId !== null) {
$header['kid'] = $keyId;
}
if (isset($head) && \is_array($head)) {
$header = \array_merge($head, $header);
}
$segments = [];
$segments[] = static::urlsafeB64Encode((string) static::jsonEncode($header));
$segments[] = static::urlsafeB64Encode((string) static::jsonEncode($payload));
Expand Down

0 comments on commit 753a0fa

Please sign in to comment.