3
3
4
4
namespace BigCommerce \Templates ;
5
5
6
-
7
6
use BigCommerce \Customizer ;
8
7
use BigCommerce \Post_Types \Product \Product ;
9
8
use BigCommerce \Taxonomies \Brand \Brand ;
10
9
use BigCommerce \Taxonomies \Product_Category \Product_Category ;
11
10
use BigCommerce \Settings \Sections \Api_Credentials ;
11
+ use BigCommerce \Assets \Theme \Image_Sizes ;
12
12
13
13
class Product_Archive extends Controller {
14
14
const QUERY = 'query ' ;
15
15
16
- const POSTS = 'posts ' ;
17
- const NO_RESULTS = 'no_results ' ;
18
- const TITLE = 'title ' ;
19
- const DESCRIPTION = 'description ' ;
20
- const REFINERY = 'refinery ' ;
21
- const PAGINATION = 'pagination ' ;
22
- const COLUMNS = 'columns ' ;
16
+ const POSTS = 'posts ' ;
17
+ const NO_RESULTS = 'no_results ' ;
18
+ const TITLE = 'title ' ;
19
+ const DESCRIPTION = 'description ' ;
20
+ const THUMBNAIL = 'thumbnail ' ;
21
+ const THUMBNAIL_SIZE = 'thumbnail ' ;
22
+ const REFINERY = 'refinery ' ;
23
+ const PAGINATION = 'pagination ' ;
24
+ const COLUMNS = 'columns ' ;
23
25
24
26
protected $ template = 'components/catalog/product-archive.php ' ;
25
27
26
28
protected function parse_options ( array $ options ) {
27
29
$ defaults = [
28
- self ::QUERY => null , // \WP_Query
29
- self ::COLUMNS => absint ( get_option ( Customizer \Sections \Product_Archive::GRID_COLUMNS , 4 ) ),
30
+ self ::QUERY => null , // \WP_Query
31
+ self ::COLUMNS => absint ( get_option ( Customizer \Sections \Product_Archive::GRID_COLUMNS , 4 ) ),
32
+ /**
33
+ * Filter the thumbnail size
34
+ *
35
+ * @param string $size The image size to use
36
+ */
37
+ self ::THUMBNAIL_SIZE => apply_filters ( 'bigcommerce/template/product_archive/thumbnail_size ' , Image_Sizes::BC_CATEGORY_IMAGE ),
30
38
];
31
39
32
40
return wp_parse_args ( $ options , $ defaults );
@@ -40,6 +48,7 @@ public function get_data() {
40
48
self ::POSTS => $ this ->get_posts ( $ query ),
41
49
self ::TITLE => $ this ->get_title ( $ query ),
42
50
self ::DESCRIPTION => $ this ->get_description (),
51
+ self ::THUMBNAIL => $ this ->get_thumbnail (),
43
52
self ::REFINERY => $ this ->get_refinery ( $ query ),
44
53
self ::PAGINATION => $ this ->get_pagination ( $ query ),
45
54
self ::COLUMNS => $ this ->options [ self ::COLUMNS ],
@@ -98,6 +107,22 @@ private function get_description() {
98
107
return $ description ;
99
108
}
100
109
110
+ private function get_thumbnail () {
111
+ $ term = get_queried_object ();
112
+
113
+ if ( ! is_a ( $ term , 'WP_Term ' ) ) {
114
+ return '' ;
115
+ }
116
+
117
+ $ attachment_id = get_term_meta ( $ term ->term_id , 'thumbnail_id ' , true );
118
+
119
+ if ( $ attachment_id ) {
120
+ return wp_get_attachment_image ( $ attachment_id , $ this ->options [ self ::THUMBNAIL_SIZE ] );
121
+ }
122
+
123
+ return '' ;
124
+ }
125
+
101
126
private function get_refinery ( \WP_Query $ query ) {
102
127
$ component = Refinery::factory ( [
103
128
Refinery::QUERY => $ query ,
@@ -120,4 +145,4 @@ private function get_no_results() {
120
145
return $ component ->render ();
121
146
}
122
147
123
- }
148
+ }
0 commit comments