← All changes
|
includes/API/V2/Proxy/Orders_Proxy_Behavior.php
+4
-51
1.10.13
→
1.10.18
View file →
| @@ -6,10 +6,8 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | namespace WCPOS\WooCommercePOS\API\V2\Proxy; |
| 9 | 9 | |
| 10 | -use Automattic\WooCommerce\Utilities\OrderUtil; | |
| 11 | -use WCPOS\WooCommercePOS\API\Order_Search; | |
| 12 | 10 | use WCPOS\WooCommercePOS\Sync\Collection_Rules; |
| 13 | 11 | use WCPOS\WooCommercePOS\Sync\Order_Serializer; |
| 14 | 12 | use WP_REST_Request; |
| 15 | 13 | |
| @@ -17,20 +15,14 @@ | ||
| 17 | 15 | * Applies the order Collection Rules plan and v2 order wire shape. |
| 18 | 16 | */ |
| 19 | 17 | final class Orders_Proxy_Behavior extends Scoped_Proxy_Behavior { |
| 20 | 18 | /** |
| 21 | - * Search text removed from the forwarded request. | |
| 22 | - * | |
| 23 | - * @var string | |
| 24 | - */ | |
| 25 | - private $search = ''; | |
| 26 | - | |
| 27 | - /** | |
| 28 | 19 | * Proxy request keys claimed by the order Collection Rules plan. |
| 29 | 20 | */ |
| 30 | 21 | private const PARAM_MAP = array( |
| 31 | 22 | 'orderby' => 'orderby', |
| 32 | 23 | 'order' => 'order', |
| 24 | + 'search' => 'search', | |
| 33 | 25 | 'pos_cashier' => 'pos_cashier', |
| 34 | 26 | 'pos_store' => 'pos_store', |
| 35 | 27 | 'created_via' => 'created_via', |
| 36 | 28 | 'include' => array( |
| @@ -60,54 +52,15 @@ | ||
| 60 | 52 | * |
| 61 | 53 | * @return array |
| 62 | 54 | */ |
| 63 | 55 | public function forwarded_params( array $params, WP_REST_Request $request ): array { |
| 64 | - $this->plan = Collection_Rules::for_request( 'orders', $request, self::PARAM_MAP ); | |
| 56 | + $plan_request = clone $request; | |
| 57 | + $plan_request->set_param( 'search', $params['search'] ?? null ); | |
| 58 | + $this->plan = Collection_Rules::for_request( 'orders', $plan_request, self::PARAM_MAP ); | |
| 65 | 59 | $params = $this->plan->forwarded_params( $params ); |
| 66 | - // Claim only a string with at least one term. Anything else (an array from | |
| 67 | - // `search[]=`, whitespace only) stays on the forward so wc/v3's own schema | |
| 68 | - // validation answers it, as it did before. | |
| 69 | - $search = $params['search'] ?? null; | |
| 70 | - if ( is_string( $search ) && array() !== Order_Search::terms( $search ) ) { | |
| 71 | - $this->search = $search; | |
| 72 | - unset( $params['search'] ); | |
| 73 | - } | |
| 74 | 60 | $params['dp'] = '6'; |
| 75 | 61 | |
| 76 | 62 | return $params; |
| 77 | - } | |
| 78 | - | |
| 79 | - /** | |
| 80 | - * Install the storage-specific POS order search filter. | |
| 81 | - * | |
| 82 | - * @return array<int, array{0: string, 1: callable, 2: int}> | |
| 83 | - */ | |
| 84 | - protected function install(): array { | |
| 85 | - if ( '' === $this->search ) { | |
| 86 | - return array(); | |
| 87 | - } | |
| 88 | - | |
| 89 | - $search = $this->search; | |
| 90 | - // The class arrived after the declared WooCommerce minimum (5.3); without it the | |
| 91 | - // store is on post storage. Same guard as Collection_Rules::detect_storage(). | |
| 92 | - if ( class_exists( OrderUtil::class ) && OrderUtil::custom_orders_table_usage_is_enabled() ) { | |
| 93 | - $filter = static function ( $clauses, $query ) use ( $search ) { | |
| 94 | - $clauses['where'] .= ' AND ' . Order_Search::hpos_where( $search, $query ); | |
| 95 | - return $clauses; | |
| 96 | - }; | |
| 97 | - add_filter( 'woocommerce_orders_table_query_clauses', $filter, 10, 2 ); | |
| 98 | - return array( array( 'woocommerce_orders_table_query_clauses', $filter, 10 ) ); | |
| 99 | - } | |
| 100 | - | |
| 101 | - $filter = static function ( $where, $query ) use ( $search ) { | |
| 102 | - $post_type = is_object( $query ) ? ( $query->query_vars['post_type'] ?? null ) : null; | |
| 103 | - if ( 'shop_order' !== $post_type && ( ! is_array( $post_type ) || ! in_array( 'shop_order', $post_type, true ) ) ) { | |
| 104 | - return $where; | |
| 105 | - } | |
| 106 | - return $where . ' AND ' . Order_Search::posts_where( $search ); | |
| 107 | - }; | |
| 108 | - add_filter( 'posts_where', $filter, 10, 2 ); | |
| 109 | - return array( array( 'posts_where', $filter, 10 ) ); | |
| 110 | 63 | } |
| 111 | 64 | |
| 112 | 65 | /** |
| 113 | 66 | * Run the forward inside the Collection Rules plan for this request. |