@@ -86,10 +86,12 @@ public function addFilterLinks( array $var ): array {
86
86
$ latteParams = [
87
87
'link ' => add_query_arg (
88
88
[
89
- 'post_status ' => false ,
89
+ 'post_type ' => 'shop_order ' ,
90
+ 'filter_action ' => 'packetery_filter_link ' ,
90
91
'packetery_to_submit ' => '1 ' ,
91
92
'packetery_to_print ' => false ,
92
- ]
93
+ ],
94
+ admin_url ( 'edit.php ' )
93
95
),
94
96
'title ' => __ ( 'packetaOrdersToSubmit ' , 'packetery ' ),
95
97
'orderCount ' => count ( $ orders ),
@@ -106,10 +108,12 @@ public function addFilterLinks( array $var ): array {
106
108
$ latteParams = [
107
109
'link ' => add_query_arg (
108
110
[
109
- 'post_status ' => false ,
111
+ 'post_type ' => 'shop_order ' ,
112
+ 'filter_action ' => 'packetery_filter_link ' ,
110
113
'packetery_to_submit ' => false ,
111
114
'packetery_to_print ' => '1 ' ,
112
- ]
115
+ ],
116
+ admin_url ( 'edit.php ' )
113
117
),
114
118
'title ' => __ ( 'packetaOrdersToPrint ' , 'packetery ' ),
115
119
'orderCount ' => count ( $ orders ),
@@ -124,16 +128,27 @@ public function addFilterLinks( array $var ): array {
124
128
* Adds select to order grid.
125
129
*/
126
130
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
+
127
141
$ this ->latteEngine ->render (
128
142
PACKETERY_PLUGIN_DIR . '/template/order/type-select.latte ' ,
129
143
[
130
144
'packeteryOrderType ' => $ this ->httpRequest ->getQuery ( 'packetery_order_type ' ),
145
+ 'linkFilters ' => $ linkFilters ,
131
146
]
132
147
);
133
148
}
134
149
135
150
/**
136
- * Adds query vars to order list request .
151
+ * Adds query vars to request query vars .
137
152
*
138
153
* @param array $queryVars Query vars.
139
154
*
@@ -143,7 +158,31 @@ public function addQueryVarsToRequest( array $queryVars ): array {
143
158
global $ typenow ;
144
159
145
160
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
147
186
}
148
187
149
188
return $ queryVars ;
@@ -159,7 +198,7 @@ public function addQueryVarsToRequest( array $queryVars ): array {
159
198
*/
160
199
public function addQueryVars ( array $ queryVars , array $ get ): array {
161
200
if ( ! empty ( $ get [ Entity::META_CARRIER_ID ] ) ) {
162
- $ queryVars [' meta_query ' ] = [
201
+ $ queryVars [] = [
163
202
[
164
203
'key ' => Entity::META_CARRIER_ID ,
165
204
'value ' => $ get [ Entity::META_CARRIER_ID ],
@@ -169,41 +208,35 @@ public function addQueryVars( array $queryVars, array $get ): array {
169
208
}
170
209
171
210
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 ' ,
183
220
];
184
221
}
185
222
186
223
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 ' ,
197
232
];
198
233
}
199
234
200
235
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 ' ] ? '= ' : '!= ' ),
207
240
];
208
241
}
209
242
0 commit comments