Warning: class_implements(): Class Automattic\WooCommerce\GoogleListingsAndAds\Tracking\Events\GenericEvents does not exist and could not be loaded in /htdocs/wp-content/plugins/google-listings-and-ads/src/Internal/DependencyManagement/AbstractServiceProvider.php on line 73
Warning: foreach() argument must be of type array|object, bool given in /htdocs/wp-content/plugins/google-listings-and-ads/src/Internal/DependencyManagement/AbstractServiceProvider.php on line 73
uest
*
* @return int
*
* @throws InvalidValue If the orderby value isn't valid.
*/
public function count( WP_REST_Request $request ): int {
$this->request = $request;
$args = $this->prepare_query_args();
add_filter( 'posts_where', [ $this, 'title_filter' ], 10, 2 );
$ids = $this->product_repository->find_ids( $args );
remove_filter( 'posts_where', [ $this, 'title_filter' ] );
return count( $ids );
}
/**
* Prepare the args to be used to retrieve the products, namely orderby, meta_query and type.
*
* @return array
*
* @throws InvalidValue If the orderby value isn't valid.
*/
protected function prepare_query_args(): array {
$product_types = ProductSyncer::get_supported_product_types();
$product_types = array_diff( $product_types, [ 'variation' ] );
$args = [
'type' => $product_types,
'status' => 'publish',
'orderby' => [ 'title' => 'ASC' ],
];
if ( ! empty( $this->request['ids'] ) ) {
$args['include'] = explode( ',', $this->request['ids'] );
}
if ( ! empty( $this->request['search'] ) ) {
$args['gla_search'] = $this->request['search'];
}
if ( empty( $this->request['orderby'] ) ) {
return $args;
}
switch ( $this->request['orderby'] ) {
case 'title':
$args['orderby']['title'] = $this->get_order();
break;
case 'id':
$args['orderby'] = [ 'ID' => $this->get_order() ] + $args['orderby'];
break;
case 'visible':
$args['meta_key'] = $this->prefix_meta_key( ProductMetaHandler::KEY_VISIBILITY );
$args['orderby'] = [ 'meta_value' => $this->get_order() ] + $args['orderby'];
break;
case 'status':
$args['meta_key'] = $this->prefix_meta_key( ProductMetaHandler::KEY_MC_STATUS );
$args['orderby'] = [ 'meta_value' => $this->get_order() ] + $args['orderby'];
break;
case 'total_sales':
$args['meta_key'] = self::META_KEY_TOTAL_SALES;
$args['orderby'] = [ 'meta_value_num' => $this->get_order() ] + $args['orderby'];
break;
default:
throw InvalidValue::not_in_allowed_list( 'orderby', [ 'title', 'id', 'visible', 'status', 'total_sales' ] );
}
return $args;
}
/**
* Convert the per_page and page parameters into limit and offset values.
*
* @return array Containing limit and offset values.
*/
protected function prepare_query_pagination(): array {
$limit = -1;
$offset = 0;
if ( ! empty( $this->request['per_page'] ) ) {
$limit = intval( $this->request['per_page'] );
$page = max( 1, intval( $this->request['page'] ) );
$offset = $limit * ( $page - 1 );
}
return [ $limit, $offset ];
}
/**
* Filter for the posts_where hook, adds WHERE clause to search
* for the 'search' parameter in the product titles (when present).
*
* @param string $where The WHERE clause of the query.
* @param WP_Query $wp_query The WP_Query instance (passed by reference).
*
* @return string The updated WHERE clause.
*/
public function title_filter( string $where, WP_Query $wp_query ): string {
$gla_search = $wp_query->get( 'gla_search' );
if ( $gla_search ) {
$title_search = '%' . $this->wpdb->esc_like( $gla_search ) . '%';
$where .= $this->wpdb->prepare( " AND `{$this->wpdb->posts}`.`post_title` LIKE %s", $title_search ); // phpcs:ignore WordPress.DB.PreparedSQL
}
return $where;
}
/**
* Return the ORDER BY order based on the order request parameter value.
*
* @return string
*/
protected function get_order(): string {
return strtoupper( $this->request['order'] ?? '' ) === 'DESC' ? 'DESC' : 'ASC';
}
}
Warning: class_implements(): Class Automattic\WooCommerce\GoogleListingsAndAds\DB\ProductFeedQueryHelper does not exist and could not be loaded in /htdocs/wp-content/plugins/google-listings-and-ads/src/Internal/DependencyManagement/AbstractServiceProvider.php on line 73
Warning: foreach() argument must be of type array|object, bool given in /htdocs/wp-content/plugins/google-listings-and-ads/src/Internal/DependencyManagement/AbstractServiceProvider.php on line 73
Warning: class_implements(): Class Automattic\WooCommerce\GoogleListingsAndAds\DB\Migration\Migration20211228T1640692399 does not exist and could not be loaded in /htdocs/wp-content/plugins/google-listings-and-ads/src/Exception/ValidateInterface.php on line 22
Fatal error: Uncaught TypeError: array_key_exists(): Argument #2 ($array) must be of type array, bool given in /htdocs/wp-content/plugins/google-listings-and-ads/src/Exception/ValidateInterface.php:23
Stack trace:
#0 /htdocs/wp-content/plugins/google-listings-and-ads/src/Exception/ValidateInterface.php(23): array_key_exists('Automattic\\WooC...', false)
#1 /htdocs/wp-content/plugins/google-listings-and-ads/src/Internal/DependencyManagement/DBServiceProvider.php(146): Automattic\WooCommerce\GoogleListingsAndAds\Internal\DependencyManagement\DBServiceProvider->validate_interface('Automattic\\WooC...', 'Automattic\\WooC...')
#2 /htdocs/wp-content/plugins/google-listings-and-ads/src/Internal/DependencyManagement/DBServiceProvider.php(102): Automattic\WooCommerce\GoogleListingsAndAds\Internal\DependencyManagement\DBServiceProvider->share_migration('Automattic\\WooC...', 'Automattic\\WooC...', 'Automattic\\WooC...')
#3 /htdocs/wp-content/plugins/google-listings-and-ads/vendor/league/container/src/ServiceProvider/ServiceProviderAggregate.php(102): Automattic\WooCommerce\GoogleListingsAndAds\Internal\DependencyManagement\DBServiceProvider->register()
#4 /htdocs/wp-content/plugins/google-listings-and-ads/vendor/league/container/src/Container.php(172): Automattic\WooCommerce\GoogleListingsAndAds\Vendor\League\Container\ServiceProvider\ServiceProviderAggregate->register('db_table')
#5 /htdocs/wp-content/plugins/google-listings-and-ads/vendor/league/container/src/Argument/ArgumentResolverTrait.php(45): Automattic\WooCommerce\GoogleListingsAndAds\Vendor\League\Container\Container->get('db_table')
#6 [internal function]: Automattic\WooCommerce\GoogleListingsAndAds\Vendor\League\Container\Definition\Definition->Automattic\WooCommerce\GoogleListingsAndAds\Vendor\League\Container\Argument\{closure}('db_table')
#7 /htdocs/wp-content/plugins/google-listings-and-ads/vendor/league/container/src/Argument/ArgumentResolverTrait.php(19): array_map(Object(Closure), Array)
#8 /htdocs/wp-content/plugins/google-listings-and-ads/vendor/league/container/src/Definition/Definition.php(253): Automattic\WooCommerce\GoogleListingsAndAds\Vendor\League\Container\Definition\Definition->resolveArguments(Array)
#9 /htdocs/wp-content/plugins/google-listings-and-ads/vendor/league/container/src/Definition/Definition.php(212): Automattic\WooCommerce\GoogleListingsAndAds\Vendor\League\Container\Definition\Definition->resolveClass('Automattic\\WooC...')
#10 /htdocs/wp-content/plugins/google-listings-and-ads/vendor/league/container/src/Definition/DefinitionAggregate.php(94): Automattic\WooCommerce\GoogleListingsAndAds\Vendor\League\Container\Definition\Definition->resolve(false)
#11 /htdocs/wp-content/plugins/google-listings-and-ads/vendor/league/container/src/Container.php(157): Automattic\WooCommerce\GoogleListingsAndAds\Vendor\League\Container\Definition\DefinitionAggregate->resolve('Automattic\\WooC...', false)
#12 /htdocs/wp-content/plugins/google-listings-and-ads/vendor/league/container/src/Argument/ArgumentResolverTrait.php(45): Automattic\WooCommerce\GoogleListingsAndAds\Vendor\League\Container\Container->get('Automattic\\WooC...')
#13 [internal function]: Automattic\WooCommerce\GoogleListingsAndAds\Vendor\League\Container\Definition\Definition->Automattic\WooCommerce\GoogleListingsAndAds\Vendor\League\Container\Argument\{closure}('Automattic\\WooC...')
#14 /htdocs/wp-content/plugins/google-listings-and-ads/vendor/league/container/src/Argument/ArgumentResolverTrait.php(19): array_map(Object(Closure), Array)
#15 /htdocs/wp-content/plugins/google-listings-and-ads/vendor/league/container/src/Definition/Definition.php(253): Automattic\WooCommerce\GoogleListingsAndAds\Vendor\League\Container\Definition\Definition->resolveArguments(Array)
#16 /htdocs/wp-content/plugins/google-listings-and-ads/vendor/league/container/src/Definition/Definition.php(212): Automattic\WooCommerce\GoogleListingsAndAds\Vendor\League\Container\Definition\Definition->resolveClass('Automattic\\WooC...')
#17 /htdocs/wp-content/plugins/google-listings-and-ads/vendor/league/container/src/Definition/DefinitionAggregate.php(106): Automattic\WooCommerce\GoogleListingsAndAds\Vendor\League\Container\Definition\Definition->resolve(false)
#18 /htdocs/wp-content/plugins/google-listings-and-ads/vendor/league/container/src/Container.php(162): Automattic\WooCommerce\GoogleListingsAndAds\Vendor\League\Container\Definition\DefinitionAggregate->resolveTagged('Automattic\\WooC...', false)
#19 /htdocs/wp-content/plugins/google-listings-and-ads/vendor/league/container/src/Argument/ArgumentResolverTrait.php(45): Automattic\WooCommerce\GoogleListingsAndAds\Vendor\League\Container\Container->get('Automattic\\WooC...')
#20 [internal function]: Automattic\WooCommerce\GoogleListingsAndAds\Vendor\League\Container\Definition\Definition->Automattic\WooCommerce\GoogleListingsAndAds\Vendor\League\Container\Argument\{closure}('Automattic\\WooC...')
#21 /htdocs/wp-content/plugins/google-listings-and-ads/vendor/league/container/src/Argument/ArgumentResolverTrait.php(19): array_map(Object(Closure), Array)
#22 /htdocs/wp-content/plugins/google-listings-and-ads/vendor/league/container/src/Definition/Definition.php(237): Automattic\WooCommerce\GoogleListingsAndAds\Vendor\League\Container\Definition\Definition->resolveArguments(Array)
#23 /htdocs/wp-content/plugins/google-listings-and-ads/vendor/league/container/src/Definition/Definition.php(198): Automattic\WooCommerce\GoogleListingsAndAds\Vendor\League\Container\Definition\Definition->resolveCallable(Object(Closure))
#24 /htdocs/wp-content/plugins/google-listings-and-ads/vendor/league/container/src/Definition/DefinitionAggregate.php(106): Automattic\WooCommerce\GoogleListingsAndAds\Vendor\League\Container\Definition\Definition->resolve(false)
#25 /htdocs/wp-content/plugins/google-listings-and-ads/vendor/league/container/src/Container.php(162): Automattic\WooCommerce\GoogleListingsAndAds\Vendor\League\Container\Definition\DefinitionAggregate->resolveTagged('Automattic\\WooC...', false)
#26 /htdocs/wp-content/plugins/google-listings-and-ads/vendor/league/container/src/Container.php(178): Automattic\WooCommerce\GoogleListingsAndAds\Vendor\League\Container\Container->get('Automattic\\WooC...', false)
#27 /htdocs/wp-content/plugins/google-listings-and-ads/src/Container.php(90): Automattic\WooCommerce\GoogleListingsAndAds\Vendor\League\Container\Container->get('Automattic\\WooC...')
#28 /htdocs/wp-content/plugins/google-listings-and-ads/src/Infrastructure/GoogleListingsAndAdsPlugin.php(130): Automattic\WooCommerce\GoogleListingsAndAds\Container->get('Automattic\\WooC...')
#29 /htdocs/wp-content/plugins/google-listings-and-ads/src/Infrastructure/GoogleListingsAndAdsPlugin.php(91): Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure\GoogleListingsAndAdsPlugin->maybe_register_services()
#30 /htdocs/wp-includes/class-wp-hook.php(324): Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure\GoogleListingsAndAdsPlugin->Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure\{closure}('')
#31 /htdocs/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array)
#32 /htdocs/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#33 /htdocs/wp-settings.php(578): do_action('plugins_loaded')
#34 /htdocs/wp-config.php(85): require_once('/htdocs/wp-sett...')
#35 /htdocs/wp-load.php(50): require_once('/htdocs/wp-conf...')
#36 /htdocs/wp-blog-header.php(13): require_once('/htdocs/wp-load...')
#37 /htdocs/index.php(17): require('/htdocs/wp-blog...')
#38 {main}
thrown in /htdocs/wp-content/plugins/google-listings-and-ads/src/Exception/ValidateInterface.php on line 23