PluginProbe
Depicter — Popup & Slider Builder / trunk
Depicter — Popup & Slider Builder vtrunk
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / app / src / DataSources / HandPickedProducts.php

HandPickedProducts.php in Depicter — Popup & Slider Builder trunk, at app/src/DataSources/HandPickedProducts.php

84 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Depicter\DataSources;
3
4 use Averta\Core\Utility\Data;
5
6 class HandPickedProducts extends Products {
7
8 /**
9 * DataSource name
10 *
11 * @var string
12 */
13 protected string $type = 'wooHandpicks';
14
15 /**
16 * DataSource properties
17 *
18 * @var array
19 */
20 protected array $properties = [
21 'type' => 'wooHandpicks',
22 'postType' => 'product'
23 ];
24
25 /**
26 * Default input params for retrieving dataSource records
27 *
28 * @var array
29 */
30 protected array $defaultInputParams = [
31 'postType' => 'product',
32 'excerptLength' => 100,
33 'linkSlides' => false,
34 'orderBy' => 'post__in',
35 'order' => 'DESC',
36 'imageSource' => 'featured',
37 'includedIds' => '',
38 'excludeNonThumbnail' => true,
39 'inStockOnly' => true
40 ];
41
42 /**
43 * Retrieves the list of records based on query params
44 *
45 * @param $args
46 *
47 * @return \WP_Query
48 */
49 protected function getRecords( $args ){
50
51 $queryArgs = [
52 'post_type' => $args['postType'],
53 'order' => $args['order'],
54 'orderby' => $args['orderBy'],
55 'post__in' => $args['includedIds'],
56 'tax_query' => [],
57 'meta_query' => []
58 ];
59
60 if( Data::isTrue( $args['excludeNonThumbnail'] ) ){
61 $queryArgs['meta_query'][] = [
62 'key' => '_thumbnail_id',
63 'compare' => 'EXISTS'
64 ];
65 }
66
67 if ( !empty( $args['excerptLength'] ) ) {
68 add_filter( 'excerpt_length', function () use ($args) {
69 return $args['excerptLength'];
70 });
71 }
72
73 if ( Data::isTrue( $args['inStockOnly'] ) ) {
74 $queryArgs['meta_query'][] = [
75 'key' => '_stock_status',
76 'value' => 'instock',
77 'compare' => '=',
78 ];
79 }
80
81 return new \WP_Query( $queryArgs );
82 }
83 }
84