Skip to content
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

Orders autosuggest: Report status and WooCommerce class attribute #3323

Merged
merged 4 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions includes/classes/Feature/WooCommerce/WooCommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

namespace ElasticPress\Feature\WooCommerce;

use ElasticPress\Feature as Feature;
use ElasticPress\FeatureRequirementsStatus as FeatureRequirementsStatus;
use ElasticPress\Indexables as Indexables;
use ElasticPress\Feature;
use ElasticPress\FeatureRequirementsStatus;
use ElasticPress\Indexables;
use ElasticPress\IndexHelper;
use ElasticPress\Utils as Utils;
use ElasticPress\Utils;

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
Expand All @@ -22,6 +22,14 @@
* WooCommerce feature class
*/
class WooCommerce extends Feature {
/**
* If enabled, receive the Orders object instance
*
* @since 4.5.0
* @var null|Orders
*/
public $orders = null;

/**
* Initialize feature setting it's config
*
Expand Down Expand Up @@ -836,6 +844,7 @@ public function setup() {
if ( ! function_exists( 'WC' ) ) {
return;
}

add_action( 'ep_formatted_args', [ $this, 'price_filter' ], 10, 3 );
add_filter( 'ep_sync_insert_permissions_bypass', [ $this, 'bypass_order_permissions_check' ], 10, 2 );
add_filter( 'ep_integrate_search_queries', [ $this, 'blacklist_coupons' ], 10, 2 );
Expand Down
81 changes: 80 additions & 1 deletion includes/classes/StatusReport/ElasticPressIo.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function get_groups() : array {
$groups = [
$this->get_autosuggest_group(),
$this->get_instant_results_group(),
$this->get_orders_search_group(),
];

return array_values( array_filter( $groups ) );
Expand Down Expand Up @@ -143,10 +144,55 @@ protected function get_instant_results_group() : array {
];
}

/**
* Process the ElasticPress.io Orders Search templates.
*
* @since 4.5.0
* @return array
*/
protected function get_orders_search_group() : array {
$woocommerce_feature = \ElasticPress\Features::factory()->get_registered_feature( 'woocommerce' );

if ( ! $woocommerce_feature->is_active() ) {
return [];
}

if ( ! $woocommerce_feature->orders ) {
return [];
}

$title = __( 'Orders Search Template', 'elasticpress' );
$fields = [];

if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
$sites = Utils\get_sites();

foreach ( $sites as $site ) {
if ( ! Utils\is_site_indexable( $site['blog_id'] ) ) {
continue;
}

switch_to_blog( $site['blog_id'] );

$field = $this->get_orders_search_field();
$fields = array_merge( $fields, $field );

restore_current_blog();
}
} else {
$fields = $this->get_orders_search_field();
}

return [
'title' => $title,
'fields' => $fields,
];
}

/**
* Process the ElasticPress.io Instant Results template.
*
* @return array|null
* @return array
*/
protected function get_instant_results_field() : array {
$index = Indexables::factory()->get( 'post' )->get_index_name();
Expand Down Expand Up @@ -174,4 +220,37 @@ protected function get_instant_results_field() : array {
],
];
}

/**
* Process the ElasticPress.io Orders Search template.
*
* @since 4.5.0
* @return array
*/
protected function get_orders_search_field() : array {
$index = Indexables::factory()->get( 'post' )->get_index_name();

if ( ! $index ) {
return [];
}

$woocommerce_feature = \ElasticPress\Features::factory()->get_registered_feature( 'woocommerce' );
$template = $woocommerce_feature->orders->get_search_template();

if ( is_wp_error( $template ) ) {
return [
$index => [
'label' => $index,
'value' => $template->get_error_message(),
],
];
}

return [
$index => [
'label' => $index,
'value' => $template,
],
];
}
}