PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 3.4.2
ShopBuilder – WooCommerce Builder For Elementor v3.4.2
3.4.2 3.4.1 3.4.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 All 63 releases
← All changes | app/Models/QueryArgs.php +24 -185 2.1.23.4.2 View file →
@@ -45,12 +45,8 @@
45 45 public function buildArgs( array $meta, string $type = 'product', bool $isCarousel = false ) {
46 46 $this->meta = $meta;
47 47
48 48 if ( 'product' === $type ) {
49 - // Post Type.
50 - $this->getPostType();
51 -
52 - // Building Args.
53 49 $this
54 50 ->post_params()
55 51 ->order_params()
56 52 ->pagination_params( $isCarousel )
@@ -55,15 +51,8 @@
55 51 ->order_params()
56 52 ->pagination_params( $isCarousel )
57 53 ->tax_params();
58 54
59 - } elseif ( 'wc_product' === $type ) {
60 - $this
61 - ->wc_post_params()
62 - ->wc_order_params()
63 - ->wc_pagination_params( $isCarousel )
64 - ->wc_tax_params();
65 -
66 55 } else {
67 56 $this
68 57 ->get_tax_type()
69 58 ->cat_params()
@@ -75,18 +64,8 @@
75 64
76 65 /**
77 66 * Post type.
78 67 *
79 - * @return void
80 - */
81 - private function getPostType() {
82 - $this->args['post_type'] = [ rtsb()->post_type ];
83 - $this->args['post_status'] = 'draft';
84 - }
85 -
86 - /**
87 - * Post type.
88 - *
89 68 * @return QueryArgs
90 69 */
91 70 private function get_tax_type() {
92 71 $this->args['taxonomy'] = [ 'product_cat' ];
@@ -96,48 +75,13 @@
96 75 return $this;
97 76 }
98 77
99 78 /**
100 - * Post parameters.
79 + * WC Post parameters.
101 80 *
102 81 * @return QueryArgs
103 82 */
104 83 private function post_params() {
105 - $post_in = isset( $this->meta['post_in'] ) ? sanitize_text_field( implode( ', ', $this->meta['post_in'] ) ) : null;
106 - $post_not_in = isset( $this->meta['post_not_in'] ) ? sanitize_text_field( implode( ', ', $this->meta['post_not_in'] ) ) : null;
107 - $author_in = isset( $this->meta['author_in'] ) ? sanitize_text_field( implode( ', ', $this->meta['author_in'] ) ) : null;
108 - $limit = ( ( empty( $this->meta['limit'] ) || '-1' === $this->meta['limit'] ) ? 10000000 : absint( $this->meta['limit'] ) );
109 - $offset = ! empty( $this->meta['offset'] ) ? absint( $this->meta['offset'] ) : 0;
110 -
111 - if ( $post_in ) {
112 - $post_in = explode( ',', $post_in );
113 - $this->args['post__in'] = $post_in;
114 - }
115 -
116 - if ( $post_not_in ) {
117 - $post_not_in = explode( ',', $post_not_in );
118 - $this->args['post__not_in'] = $post_not_in;
119 - }
120 -
121 - if ( $author_in ) {
122 - $author_in = explode( ',', $author_in );
123 - $this->args['author__in'] = $author_in;
124 - }
125 -
126 - $this->args['posts_per_page'] = $limit;
127 -
128 - if ( $offset ) {
129 - $this->args['offset'] = $offset;
130 - }
131 -
132 - return $this;
133 - }
134 - /**
135 - * WC Post parameters.
136 - *
137 - * @return QueryArgs
138 - */
139 - private function wc_post_params() {
140 84 $post_in = isset( $this->meta['post_in'] ) ? sanitize_text_field( implode( ',', $this->meta['post_in'] ) ) : null;
141 85 $post_not_in = isset( $this->meta['post_not_in'] ) ? sanitize_text_field( implode( ', ', $this->meta['post_not_in'] ) ) : null;
142 86 $author_in = isset( $this->meta['author_in'] ) ? sanitize_text_field( implode( ',', $this->meta['author_in'] ) ) : null;
143 87 $limit = ( ( empty( $this->meta['limit'] ) || '-1' === $this->meta['limit'] ) ? 10000000 : absint( $this->meta['limit'] ) );
@@ -149,9 +93,9 @@
149 93 }
150 94
151 95 if ( $post_not_in ) {
152 96 $post_not_in = explode( ',', $post_not_in );
153 - $this->args['exclude'] = $post_not_in;
97 + $this->args['exclude'] = $post_not_in; // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude
154 98 }
155 99
156 100 if ( $author_in ) {
157 101 $this->args['author'] = $author_in;
@@ -190,9 +134,9 @@
190 134 }
191 135
192 136 if ( $cats_not_in ) {
193 137 $cats_not_in = array_filter( explode( ',', $cats_not_in ) );
194 - $this->args['exclude'] = $cats_not_in;
138 + $this->args['exclude'] = $cats_not_in; // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude
195 139 }
196 140
197 141 $this->args['number'] = $limit;
198 142 $this->args['hide_empty'] = $this->meta['show_empty'] ? 0 : 1;
@@ -226,9 +170,9 @@
226 170 return $this;
227 171 }
228 172
229 173 /**
230 - * Order & Orderby parameters.
174 + * WC Order & Orderby parameters.
231 175 *
232 176 * @return QueryArgs
233 177 */
234 178 private function order_params() {
@@ -240,32 +184,17 @@
240 184 }
241 185
242 186 if ( $order_by ) {
243 187 $this->args['orderby'] = $order_by;
244 - }
245 188
246 - return $this;
247 - }
248 -
249 - /**
250 - * WC Order & Orderby parameters.
251 - *
252 - * @return QueryArgs
253 - */
254 - private function wc_order_params() {
255 - $order_by = ( isset( $this->meta['order_by'] ) ? esc_html( $this->meta['order_by'] ) : null );
256 - $order = ( isset( $this->meta['order'] ) ? esc_html( $this->meta['order'] ) : null );
257 -
258 - if ( $order ) {
259 - $this->args['order'] = $order;
260 - }
261 -
262 - if ( $order_by ) {
263 - $this->args['orderby'] = $order_by;
264 -
265 189 if ( 'menu_order' === $order_by ) {
266 190 $this->args['orderby'] = 'menu_order title';
267 191 }
192 +
193 + if ( 'price' === $order_by ) {
194 + $this->args['orderby'] = 'meta_value_num';
195 + $this->args['meta_key'] = '_price'; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
196 + }
268 197 }
269 198
270 199 return $this;
271 200 }
@@ -305,50 +234,8 @@
305 234 $pagination = ! empty( $this->meta['pagination'] );
306 235 $limit = ( ( empty( $this->meta['limit'] ) || '-1' === $this->meta['limit'] ) ? 10000000 : absint( $this->meta['limit'] ) );
307 236
308 237 if ( $pagination ) {
309 - $posts_per_page = ( ! empty( $this->meta['posts_per_page'] ) ? absint( $this->meta['posts_per_page'] ) : $limit );
310 -
311 - if ( $posts_per_page > $limit ) {
312 - $posts_per_page = $limit;
313 - }
314 -
315 - $this->args['posts_per_page'] = $posts_per_page;
316 -
317 - if ( is_front_page() ) {
318 - $paged = ( get_query_var( 'page' ) ) ? get_query_var( 'page' ) : 1;
319 - } else {
320 - $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
321 - }
322 -
323 - $offset = $posts_per_page * ( (int) $paged - 1 );
324 - $this->args['paged'] = $paged;
325 -
326 - if ( absint( $this->args['posts_per_page'] ) > $limit - $offset ) {
327 - $this->args['posts_per_page'] = $limit - $offset;
328 - $this->args['offset'] = $offset;
329 - }
330 - }
331 -
332 - if ( $isCarousel ) {
333 - $this->args['posts_per_page'] = $limit;
334 - }
335 -
336 - return $this;
337 - }
338 -
339 - /**
340 - * Pagination parameters.
341 - *
342 - * @param bool $isCarousel Layout type.
343 - *
344 - * @return QueryArgs
345 - */
346 - private function wc_pagination_params( $isCarousel ) {
347 - $pagination = ! empty( $this->meta['pagination'] );
348 - $limit = ( ( empty( $this->meta['limit'] ) || '-1' === $this->meta['limit'] ) ? 10000000 : absint( $this->meta['limit'] ) );
349 -
350 - if ( $pagination ) {
351 238 unset( $this->args['offset'] );
352 239
353 240 $posts_per_page = ( ! empty( $this->meta['posts_per_page'] ) ? absint( $this->meta['posts_per_page'] ) : $limit );
354 241
@@ -358,13 +245,17 @@
358 245
359 246 $this->args['paginate'] = true;
360 247 $this->args['limit'] = $posts_per_page;
361 248
362 - if ( is_front_page() ) {
363 - $paged = ( get_query_var( 'page' ) ) ? get_query_var( 'page' ) : 1;
364 - } else {
365 - $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
249 + // Prefer `paged` (archive pagination), fall back to `page` (paginated singular posts).
250 + // Handles the case where the shop/archive is set as the front page.
251 + $paged = get_query_var( 'paged' );
252 + if ( ! $paged ) {
253 + $paged = get_query_var( 'page' );
366 254 }
255 + if ( ! $paged ) {
256 + $paged = 1;
257 + }
367 258
368 259 $offset = $posts_per_page * ( (int) $paged - 1 );
369 260 $this->args['page'] = $paged;
370 261
@@ -383,74 +274,24 @@
383 274
384 275 /**
385 276 * Taxonomy parameters.
386 277 *
387 - * @return QueryArgs
278 + * @return void
388 279 */
389 - private function tax_params() {
280 + private function tax_params(): void {
390 281 $categories = isset( $this->meta['categories'] ) ? array_filter( $this->meta['categories'] ) : [];
282 + $brands = isset( $this->meta['brands'] ) ? array_filter( $this->meta['brands'] ) : [];
391 283 $tags = isset( $this->meta['tags'] ) ? array_filter( $this->meta['tags'] ) : [];
392 284 $attributes = isset( $this->meta['attributes'] ) ? array_filter( $this->meta['attributes'] ) : [];
393 - $taxQ = [];
394 285
395 - if ( is_array( $categories ) && ! empty( $categories ) ) {
396 - $taxQ[] = [
397 - 'taxonomy' => 'product_cat',
398 - 'field' => 'term_id',
399 - 'terms' => $categories,
400 - 'operator' => 'IN',
401 - ];
286 + if ( ! empty( $categories ) ) {
287 + $this->args['product_category_id'] = $categories;
402 288 }
403 289
404 - if ( ! empty( $tags ) && is_array( $tags ) ) {
405 - $taxQ[] = [
406 - 'taxonomy' => 'product_tag',
407 - 'field' => 'term_id',
408 - 'terms' => $tags,
409 - 'operator' => 'IN',
410 - ];
290 + if ( ! empty( $brands ) ) {
291 + $this->args['product_brand_id'] = $brands;
411 292 }
412 293
413 - if ( ! empty( $attributes ) && is_array( $attributes ) ) {
414 - $attribute_tax = null;
415 -
416 - foreach ( $attributes as $atts ) {
417 - $attribute_tax = get_term( $atts )->taxonomy;
418 -
419 - $taxQ[] = [
420 - 'taxonomy' => $attribute_tax,
421 - 'field' => 'term_id',
422 - 'terms' => [ $atts ],
423 - 'operator' => 'IN',
424 - ];
425 - }
426 - }
427 -
428 - if ( count( $taxQ ) >= 2 ) {
429 - $taxQ['relation'] = $this->meta['relation'];
430 - }
431 -
432 - if ( ! empty( $taxQ ) ) {
433 - $this->args['tax_query'] = $taxQ;
434 - }
435 -
436 - return $this;
437 - }
438 -
439 - /**
440 - * Taxonomy parameters.
441 - *
442 - * @return QueryArgs
443 - */
444 - private function wc_tax_params() {
445 - $categories = isset( $this->meta['categories'] ) ? array_filter( $this->meta['categories'] ) : [];
446 - $tags = isset( $this->meta['tags'] ) ? array_filter( $this->meta['tags'] ) : [];
447 - $attributes = isset( $this->meta['attributes'] ) ? array_filter( $this->meta['attributes'] ) : [];
448 -
449 - if ( ! empty( $categories ) ) {
450 - $this->args['product_category_id'] = $categories;
451 - }
452 -
453 294 if ( ! empty( $tags ) ) {
454 295 $this->args['product_tag_id'] = $tags;
455 296 }
456 297
@@ -456,8 +297,6 @@
456 297
457 298 if ( ! empty( $attributes ) ) {
458 299 $this->args['product_attribute_id'] = $attributes;
459 300 }
460 -
461 - return $this;
462 301 }
463 302 }