PluginProbe
Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder / 3.0.9
Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder v3.0.9
3.1.4 3.0.8 3.0.9 3.1.0 3.1.2 3.1.3 3.0.7 3.0.5 3.0.4 3.0.3 3.0.2 trunk 1.5.0 1.5.1 1.5.2 1.6.1 1.6.2 1.6.3 1.6.4 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 All 93 releases
ultimate-store-kit / modules / shiny-grid / widgets / shiny-grid.php

shiny-grid.php in Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder 3.0.9, at modules/shiny-grid/widgets/shiny-grid.php

373 lines 13.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace UltimateStoreKit\Modules\ShinyGrid\Widgets;
4
5 use Elementor\Controls_Manager;
6 use UltimateStoreKit\Base\Module_Base;
7 use UltimateStoreKit\Traits\Global_Widget_Template;
8 use UltimateStoreKit\Includes\Controls\GroupQuery\Group_Control_Query;
9 use UltimateStoreKit\Traits\Global_Widget_Controls;
10 use WP_Query;
11 use UltimateStoreKit\Templates\USK_Shiny_Grid_Template;
12
13 if (!defined('ABSPATH')) {
14 exit;
15 }
16
17 class Shiny_Grid extends Module_Base {
18 use Global_Widget_Controls;
19 use Global_Widget_Template;
20 use Group_Control_Query;
21 // use Global_Widget_Template;
22
23 /**
24 * @var \WP_Query
25 */
26 private $_query = null;
27
28 public function get_name() {
29 return 'usk-shiny-grid';
30 }
31
32 public function get_title() {
33 return esc_html__('Shiny Grid', 'ultimate-store-kit');
34 }
35
36 public function get_icon() {
37 return 'usk-widget-icon usk-icon-shiny-grid';
38 }
39
40 public function get_categories() {
41 return ['ultimate-store-kit'];
42 }
43
44 public function get_keywords() {
45 return ['product', 'product-grid', 'table', 'wc'];
46 }
47 public function get_script_depends() {
48 if ($this->usk_is_edit_mode()) {
49 return ['usk-site'];
50 } else {
51 return ['usk-shiny-grid', 'usk-grid-variations'];
52 }
53 }
54
55 public function get_style_depends() {
56 if ($this->usk_is_edit_mode()) {
57 return ['usk-all-styles'];
58 } else {
59 return ['usk-font', 'usk-shiny-grid', 'slick-modal'];
60 }
61 }
62
63 // public function get_custom_help_url() {
64 // return 'https://youtu.be/3VkvEpVaNAM';
65 // }
66
67 public function get_query() {
68 return $this->_query;
69 }
70 public function has_widget_inner_wrapper(): bool {
71 return !\Elementor\Plugin::$instance->experiments->is_feature_active('e_optimized_markup');
72 }
73 protected function register_controls() {
74 $this->start_controls_section(
75 'section_woocommerce_layout',
76 [
77 'label' => esc_html__('Layout', 'ultimate-store-kit'),
78 ]
79 );
80
81 $this->add_control(
82 'layout_style',
83 [
84 'label' => esc_html__('Style', 'ultimate-store-kit'),
85 'type' => Controls_Manager::SELECT,
86 'default' => 'grid',
87 'options' => [
88 'grid' => esc_html__('Grid', 'ultimate-store-kit'),
89 'list' => esc_html__('List', 'ultimate-store-kit'),
90 ],
91 'condition' => [
92 'show_tab!' => 'yes'
93 ]
94 ]
95 );
96 $this->add_responsive_control(
97 'columns',
98 [
99 'label' => esc_html__('Columns', 'ultimate-store-kit'),
100 'type' => Controls_Manager::SELECT,
101 'default' => '3',
102 'tablet_default' => '2',
103 'mobile_default' => '1',
104 'options' => [
105 '1' => esc_html__('1', 'ultimate-store-kit'),
106 '2' => esc_html__('2', 'ultimate-store-kit'),
107 '3' => esc_html__('3', 'ultimate-store-kit'),
108 '4' => esc_html__('4', 'ultimate-store-kit'),
109 '5' => esc_html__('5', 'ultimate-store-kit'),
110 '6' => esc_html__('6', 'ultimate-store-kit'),
111 ],
112 'condition' => [
113 'layout_style' => 'grid',
114 'show_tab!' => 'yes'
115 ],
116 'selectors' => [
117 '{{WRAPPER}} .usk-shiny-grid .usk-grid.usk-grid-layout' => 'grid-template-columns: repeat({{VALUE}}, 1fr);',
118
119 ],
120 'render_type' => 'template'
121 ]
122 );
123
124 $this->add_responsive_control(
125 'columns_list',
126 [
127 'label' => esc_html__('Columns', 'ultimate-store-kit'),
128 'type' => Controls_Manager::SELECT,
129 'default' => '2',
130 'tablet_default' => '2',
131 'mobile_default' => '1',
132 'options' => [
133 '1' => esc_html__('1', 'ultimate-store-kit'),
134 '2' => esc_html__('2', 'ultimate-store-kit'),
135 '3' => esc_html__('3', 'ultimate-store-kit'),
136 '4' => esc_html__('4', 'ultimate-store-kit'),
137 '5' => esc_html__('5', 'ultimate-store-kit'),
138 '6' => esc_html__('6', 'ultimate-store-kit'),
139 ],
140 'condition' => [
141 'layout_style' => 'list'
142 ],
143 'selectors' => [
144 '{{WRAPPER}} .usk-shiny-grid .usk-grid.usk-list-layout' => 'grid-template-columns: repeat({{VALUE}}, 1fr);',
145
146 ],
147 'render_type' => 'template'
148 ]
149 );
150
151 $this->add_responsive_control(
152 'items_columns_gap',
153 [
154 'label' => esc_html__('Columns Gap', 'ultimate-store-kit'),
155 'type' => Controls_Manager::SLIDER,
156 'default' => [
157 'size' => 30,
158 ],
159 'selectors' => [
160 '{{WRAPPER}} .usk-shiny-grid .usk-grid' => 'grid-column-gap: {{SIZE}}px;',
161 ],
162 ]
163 );
164
165 $this->add_responsive_control(
166 'items_row_gap',
167 [
168 'label' => esc_html__('Row Gap', 'ultimate-store-kit'),
169 'type' => Controls_Manager::SLIDER,
170 'default' => [
171 'size' => 30,
172 ],
173 'selectors' => [
174 '{{WRAPPER}} .usk-shiny-grid .usk-grid' => 'grid-row-gap: {{SIZE}}px;',
175 ],
176 ]
177 );
178
179 $this->register_global_controls_grid_layout();
180
181 $this->add_control(
182 'show_tab',
183 [
184 'label' => esc_html__('Columns Filter', 'ultimate-store-kit'),
185 'type' => Controls_Manager::SWITCHER,
186 'separator' => 'before',
187 'condition' => [
188 'layout_style' => 'grid'
189 ],
190 ]
191 );
192
193 $this->add_control(
194 'filter_column_lists',
195 [
196 'label' => __('Select Column Type', 'ultimate-store-kit'),
197 'type' => Controls_Manager::SELECT2,
198 'label_block' => true,
199 'multiple' => true,
200 'options' => [
201 'list-2' => __('List', 'ultimate-store-kit'),
202 'grid-2' => __('Column 2', 'ultimate-store-kit'),
203 'grid-3' => __('Column 3', 'ultimate-store-kit'),
204 'grid-4' => __('Column 4', 'ultimate-store-kit'),
205 'grid-5' => __('Column 5', 'ultimate-store-kit'),
206 'grid-6' => __('Column 6', 'ultimate-store-kit'),
207
208 ],
209 'condition' => [
210 'show_tab' => 'yes',
211 'layout_style' => 'grid'
212 ],
213 'default' => ['list-2', 'grid-2', 'grid-3', 'grid-4'],
214 ]
215 );
216
217 $this->add_control(
218 'show_result_count',
219 [
220 'label' => esc_html__('Result Count', 'ultimate-store-kit'),
221 'type' => Controls_Manager::SWITCHER,
222 'label_on' => esc_html__('Show', 'ultimate-store-kit'),
223 'label_off' => esc_html__('Hide', 'ultimate-store-kit'),
224 'return_value' => 'yes',
225 'default' => 'yes',
226 'separator' => 'before',
227 'condition' => [
228 'show_tab' => 'yes'
229 ]
230 ]
231 );
232 $this->add_control(
233 'show_pagination',
234 [
235 'label' => esc_html__('Pagination', 'ultimate-store-kit'),
236 'type' => Controls_Manager::SWITCHER,
237 'separator' => 'before'
238 ]
239 );
240
241 $this->end_controls_section();
242 $this->start_controls_section(
243 'section_post_query_builder',
244 [
245 'label' => __('Query', 'ultimate-store-kit'),
246 'tab' => Controls_Manager::TAB_CONTENT,
247 ]
248 );
249 $this->register_query_builder_controls();
250 $this->register_controls_wc_additional();
251 $this->end_controls_section();
252 $this->register_global_controls_additional();
253 $this->register_global_controls_grid_columns();
254 $this->register_global_controls_result_count();
255 $this->register_global_controls_grid_items();
256 $this->register_global_controls_grid_image();
257 $this->register_global_controls_content();
258 $this->register_global_controls_title();
259 $this->register_global_controls_category();
260 $this->register_global_controls_excerpt();
261 $this->register_global_controls_price();
262 $this->register_global_controls_rating();
263 $this->register_global_controls_badge();
264 $this->register_global_controls_add_to_cart();
265 $this->register_global_controls_action_btn();
266 $this->register_global_controls_variation();
267
268 $this->register_global_controls_grid_pagination();
269 }
270 public function render_header() {
271 $settings = $this->get_settings_for_display();
272 $this->add_render_attribute('usk-shiny-grid', 'class', 'usk-shiny-grid usk-grid-carousel usk-css-grid', true);
273 $this->add_render_attribute(
274 'usk-shiny-grid',
275 'data-filter',
276 ('yes' === ($settings['show_tab'] ?? '')) ? 'yes' : ''
277 );
278
279 ?>
280 <div class="ultimate-store-kit">
281 <div <?php $this->print_render_attribute_string('usk-shiny-grid'); ?>>
282 <?php $this->template_grid_columns(); ?>
283 <?php
284 }
285 public function render_footer() { ?>
286 </div>
287 </div>
288 <?php
289 }
290 public function render_loop_item() {
291 $settings = $this->get_settings_for_display();
292 $this->query_product();
293 $wp_query = $this->get_query();
294
295
296 if ($settings['layout_style'] === 'grid') {
297 $this->add_render_attribute('usk-grid', 'class', ['usk-grid', 'usk-grid-layout']);
298 } else {
299 $this->add_render_attribute('usk-grid', 'class', ['usk-grid', 'usk-list-layout']);
300 }
301
302 if ($wp_query->have_posts()) { ?>
303 <div <?php $this->print_render_attribute_string('usk-grid'); ?>>
304 <?php while ($wp_query->have_posts()):
305 $wp_query->the_post();
306 global $product;
307 if (empty($product)) {
308 continue;
309 }
310 ?>
311 <?php $shiny_grid_template = new USK_Shiny_Grid_Template($settings, 'shiny-grid');
312 $shiny_grid_template->render_shiny_grid_item($product, $settings);
313 ?>
314 <?php endwhile; ?>
315 </div>
316 <?php if ($settings['show_pagination']):
317 ultimate_store_kit_post_pagination($wp_query);
318 endif;
319 wp_reset_postdata();
320 } else { ?>
321 <div class="usk-warning">
322 <span><?php echo esc_html__('Ops! There no product to display', 'ultimate-store-kit'); ?></span>
323 </div>
324 <?php
325 }
326 }
327 public function render() {
328 $this->render_header();
329 $this->render_loop_item();
330 $this->render_footer();
331 }
332
333 public function query_product() {
334 $default = $this->getGroupControlQueryArgs();
335 $this->_query = $this->build_query_from_args($default);
336 }
337 protected function template_grid_columns() {
338 $settings = $this->get_settings_for_display();
339 $this->query_product();
340 $wp_query = $this->get_query();
341 if (get_query_var('paged')) {
342 $paged = get_query_var('paged');
343 } elseif (get_query_var('page')) {
344 $paged = get_query_var('page');
345 } else {
346 $paged = 1;
347 }
348
349 $orderedby = $wp_query->get('orderby');
350 if (is_array($orderedby)) {
351 $orderedby = implode(' ', array_map('sanitize_key', $orderedby));
352 } else {
353 $orderedby = sanitize_key((string) $orderedby);
354 }
355
356 $args = array(
357 'total' => (int) $wp_query->found_posts,
358 'per_page' => absint($settings['product_limit'] ?? 0),
359 'current' => max(1, absint($paged)),
360 'orderedby' => $orderedby,
361 );
362 if ($settings['show_tab'] == 'yes'): ?>
363 <div class="usk-grid-header usk-visible@l">
364 <?php if (($settings['show_result_count'] == 'yes')):
365 wc_get_template('loop/result-count.php', $args);
366 endif;
367 ?>
368 <?php $this->register_templates_grid_columns_markup($settings); ?>
369 </div>
370 <?php endif;
371 }
372 }
373