Skip to content

Commit 5c63eb0

Browse files
FJiskraFilip Jiskra
andauthored
PES-564: order grid fix (#134)
* PES-564: order grid fix * PES-564: order grid fix - request usage * PES-564: order grid fix - Honza CR * PES-564: order grid fix - readme update Co-authored-by: Filip Jiskra <[email protected]>
1 parent 957f674 commit 5c63eb0

File tree

4 files changed

+73
-36
lines changed

4 files changed

+73
-36
lines changed

packetery/readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ Please contact us at [email protected] .
7474
= 1.0.7 =
7575
* Fixed: the label print page displays a message to the user if no suitable orders are selected
7676
* Fixed: Some environments caused error due PHPDocs being removed by OPCache.
77+
* Fixed: Order list filters can now be combined.
7778

7879
= 1.0.6 =
7980
* Updated: carrier settings page errors highlighted

packetery/src/Packetery/Module/Order/GridExtender.php

Lines changed: 67 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,12 @@ public function addFilterLinks( array $var ): array {
8686
$latteParams = [
8787
'link' => add_query_arg(
8888
[
89-
'post_status' => false,
89+
'post_type' => 'shop_order',
90+
'filter_action' => 'packetery_filter_link',
9091
'packetery_to_submit' => '1',
9192
'packetery_to_print' => false,
92-
]
93+
],
94+
admin_url( 'edit.php' )
9395
),
9496
'title' => __( 'packetaOrdersToSubmit', 'packetery' ),
9597
'orderCount' => count( $orders ),
@@ -106,10 +108,12 @@ public function addFilterLinks( array $var ): array {
106108
$latteParams = [
107109
'link' => add_query_arg(
108110
[
109-
'post_status' => false,
111+
'post_type' => 'shop_order',
112+
'filter_action' => 'packetery_filter_link',
110113
'packetery_to_submit' => false,
111114
'packetery_to_print' => '1',
112-
]
115+
],
116+
admin_url( 'edit.php' )
113117
),
114118
'title' => __( 'packetaOrdersToPrint', 'packetery' ),
115119
'orderCount' => count( $orders ),
@@ -124,16 +128,27 @@ public function addFilterLinks( array $var ): array {
124128
* Adds select to order grid.
125129
*/
126130
public function renderOrderTypeSelect(): void {
131+
$linkFilters = [];
132+
133+
if ( null !== $this->httpRequest->getQuery( 'packetery_to_submit' ) ) {
134+
$linkFilters['packetery_to_submit'] = '1';
135+
}
136+
137+
if ( null !== $this->httpRequest->getQuery( 'packetery_to_print' ) ) {
138+
$linkFilters['packetery_to_print'] = '1';
139+
}
140+
127141
$this->latteEngine->render(
128142
PACKETERY_PLUGIN_DIR . '/template/order/type-select.latte',
129143
[
130144
'packeteryOrderType' => $this->httpRequest->getQuery( 'packetery_order_type' ),
145+
'linkFilters' => $linkFilters,
131146
]
132147
);
133148
}
134149

135150
/**
136-
* Adds query vars to order list request.
151+
* Adds query vars to request query vars.
137152
*
138153
* @param array $queryVars Query vars.
139154
*
@@ -143,7 +158,31 @@ public function addQueryVarsToRequest( array $queryVars ): array {
143158
global $typenow;
144159

145160
if ( in_array( $typenow, wc_get_order_types( 'order-meta-boxes' ), true ) ) {
146-
$queryVars = $this->addQueryVars( $queryVars, $this->httpRequest->getQuery() );
161+
$metaVars = $this->addQueryVars( ( $queryVars['meta_query'] ?? [] ), $this->httpRequest->getQuery() );
162+
if ( $metaVars ) {
163+
// @codingStandardsIgnoreStart
164+
$queryVars['meta_query'] = $metaVars;
165+
// @codingStandardsIgnoreEnd
166+
}
167+
}
168+
169+
return $queryVars;
170+
}
171+
172+
/**
173+
* Transforms custom query var. There are two custom variables: "packetery_to_submit" and "packetery_to_print".
174+
*
175+
* @param array $queryVars Query vars.
176+
* @param array $get Input values.
177+
*
178+
* @return array
179+
*/
180+
public function handleCustomQueryVar( array $queryVars, array $get ): array {
181+
$metaQuery = $this->addQueryVars( ( $queryVars['meta_query'] ?? [] ), $get );
182+
if ( $metaQuery ) {
183+
// @codingStandardsIgnoreStart
184+
$queryVars['meta_query'] = $metaQuery;
185+
// @codingStandardsIgnoreEnd
147186
}
148187

149188
return $queryVars;
@@ -159,7 +198,7 @@ public function addQueryVarsToRequest( array $queryVars ): array {
159198
*/
160199
public function addQueryVars( array $queryVars, array $get ): array {
161200
if ( ! empty( $get[ Entity::META_CARRIER_ID ] ) ) {
162-
$queryVars['meta_query'] = [
201+
$queryVars[] = [
163202
[
164203
'key' => Entity::META_CARRIER_ID,
165204
'value' => $get[ Entity::META_CARRIER_ID ],
@@ -169,41 +208,35 @@ public function addQueryVars( array $queryVars, array $get ): array {
169208
}
170209

171210
if ( ! empty( $get['packetery_to_submit'] ) ) {
172-
$queryVars['meta_query'] = [
173-
'relation' => 'AND',
174-
[
175-
'key' => Entity::META_CARRIER_ID,
176-
'value' => '',
177-
'compare' => '!=',
178-
],
179-
[
180-
'key' => Entity::META_IS_EXPORTED,
181-
'compare' => 'NOT EXISTS',
182-
],
211+
$queryVars[] = [
212+
'key' => Entity::META_CARRIER_ID,
213+
'value' => '',
214+
'compare' => '!=',
215+
];
216+
217+
$queryVars[] = [
218+
'key' => Entity::META_IS_EXPORTED,
219+
'compare' => 'NOT EXISTS',
183220
];
184221
}
185222

186223
if ( ! empty( $get['packetery_to_print'] ) ) {
187-
$queryVars['meta_query'] = [
188-
'relation' => 'AND',
189-
[
190-
'key' => Entity::META_PACKET_ID,
191-
'compare' => 'EXISTS',
192-
],
193-
[
194-
'key' => Entity::META_IS_LABEL_PRINTED,
195-
'compare' => 'NOT EXISTS',
196-
],
224+
$queryVars[] = [
225+
'key' => Entity::META_PACKET_ID,
226+
'compare' => 'EXISTS',
227+
];
228+
229+
$queryVars[] = [
230+
'key' => Entity::META_IS_LABEL_PRINTED,
231+
'compare' => 'NOT EXISTS',
197232
];
198233
}
199234

200235
if ( ! empty( $get['packetery_order_type'] ) ) {
201-
$queryVars['meta_query'] = [
202-
[
203-
'key' => Entity::META_CARRIER_ID,
204-
'value' => Repository::INTERNAL_PICKUP_POINTS_ID,
205-
'compare' => ( Repository::INTERNAL_PICKUP_POINTS_ID === $get['packetery_order_type'] ? '=' : '!=' ),
206-
],
236+
$queryVars[] = [
237+
'key' => Entity::META_CARRIER_ID,
238+
'value' => Repository::INTERNAL_PICKUP_POINTS_ID,
239+
'compare' => ( Repository::INTERNAL_PICKUP_POINTS_ID === $get['packetery_order_type'] ? '=' : '!=' ),
207240
];
208241
}
209242

packetery/src/Packetery/Module/Plugin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,10 @@ static function () {
240240

241241
add_filter( 'views_edit-shop_order', [ $this->gridExtender, 'addFilterLinks' ] );
242242
add_action( 'restrict_manage_posts', [ $this->gridExtender, 'renderOrderTypeSelect' ] );
243-
add_filter( 'request', [ $this->gridExtender, 'addQueryVarsToRequest' ] );
243+
add_filter( 'request', [ $this->gridExtender, 'addQueryVarsToRequest' ], PHP_INT_MAX );
244244
add_filter( 'manage_edit-shop_order_columns', [ $this->gridExtender, 'addOrderListColumns' ] );
245245
add_action( 'manage_shop_order_posts_custom_column', [ $this->gridExtender, 'fillCustomOrderListColumns' ] );
246-
add_filter( 'woocommerce_order_data_store_cpt_get_orders_query', [ $this->gridExtender, 'addQueryVars' ], 10, 2 );
246+
add_filter( 'woocommerce_order_data_store_cpt_get_orders_query', [ $this->gridExtender, 'handleCustomQueryVar' ], 10, 2 );
247247

248248
add_action( 'admin_menu', array( $this, 'add_menu_pages' ) );
249249
add_action( 'admin_head', array( $this->labelPrint, 'hideFromMenus' ) );

packetery/template/order/type-select.latte

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
<option value="packeta"{if $packeteryOrderType === Packetery\Module\Carrier\Repository::INTERNAL_PICKUP_POINTS_ID}
55
selected="selected"{/if}>{__( 'packetaPickupPointPackets', 'packetery' )}</option>
66
</select>
7+
{foreach $linkFilters as $name => $value}
8+
<input type="hidden" name="{$name}" value="{$value}">
9+
{/foreach}

0 commit comments

Comments
 (0)