PluginProbe
Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder / 2.0.5
Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder v2.0.5
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 2.0.5, at modules/shiny-grid/widgets/shiny-grid.php

498 lines 20.6 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 Elementor\Group_Control_Border;
7 use Elementor\Group_Control_Box_Shadow;
8 use Elementor\Group_Control_Typography;
9 use Elementor\Group_Control_Background;
10 use UltimateStoreKit\Base\Module_Base;
11 use UltimateStoreKit\Traits\Global_Widget_Template;
12 use UltimateStoreKit\Includes\Controls\GroupQuery\Group_Control_Query;
13 use UltimateStoreKit\Traits\Global_Widget_Controls;
14 use WP_Query;
15
16 if (!defined('ABSPATH')) {
17 exit;
18 }
19
20 // Exit if accessed directly
21
22 class Shiny_Grid extends Module_Base {
23 use Global_Widget_Controls;
24 use Global_Widget_Template;
25 use Group_Control_Query;
26 // use Global_Widget_Template;
27
28 /**
29 * @var \WP_Query
30 */
31 private $_query = null;
32
33 public function get_name() {
34 return 'usk-shiny-grid';
35 }
36
37 public function get_title() {
38 return esc_html__('Shiny Grid', 'ultimate-store-kit');
39 }
40
41 public function get_icon() {
42 return 'usk-widget-icon usk-icon-shiny-grid';
43 }
44
45 public function get_categories() {
46 return ['ultimate-store-kit'];
47 }
48
49 public function get_keywords() {
50 return ['product', 'product-grid', 'table', 'wc'];
51 }
52
53 // public function get_script_depends() {
54 // return ['usk-shiny-grid'];
55 // }
56
57 public function get_style_depends() {
58 if ($this->usk_is_edit_mode()) {
59 return ['usk-all-styles'];
60 } else {
61 return ['usk-font', 'usk-shiny-grid', 'slick-modal'];
62 }
63 }
64
65 // public function get_custom_help_url() {
66 // return 'https://youtu.be/3VkvEpVaNAM';
67 // }
68
69 public function get_query() {
70 return $this->_query;
71 }
72 protected function register_controls() {
73 $this->start_controls_section(
74 'section_woocommerce_layout',
75 [
76 'label' => esc_html__('Layout', 'ultimate-store-kit'),
77 ]
78 );
79
80 $this->add_control(
81 'layout_style',
82 [
83 'label' => esc_html__('Style', 'ultimate-store-kit'),
84 'type' => Controls_Manager::SELECT,
85 'default' => 'grid',
86 'options' => [
87 'grid' => esc_html__('Grid', 'ultimate-store-kit'),
88 'list' => esc_html__('List', 'ultimate-store-kit'),
89 ],
90 ]
91 );
92 $this->add_responsive_control(
93 'columns',
94 [
95 'label' => esc_html__('Columns', 'ultimate-store-kit'),
96 'type' => Controls_Manager::SELECT,
97 'default' => '3',
98 'tablet_default' => '2',
99 'mobile_default' => '1',
100 'options' => [
101 '1' => '1',
102 '2' => '2',
103 '3' => '3',
104 '4' => '4',
105 '5' => '5',
106 '6' => '6',
107 ],
108 'condition' => [
109 'layout_style' => 'grid'
110 ],
111 'selectors' => [
112 '{{WRAPPER}} .usk-shiny-grid .usk-grid' => 'grid-template-columns: repeat({{VALUE}}, 1fr);',
113
114 ],
115 'render_type' => 'template'
116 ]
117 );
118
119 $this->add_responsive_control(
120 'items_columns_gap',
121 [
122 'label' => esc_html__('Columns Gap', 'ultimate-store-kit'),
123 'type' => Controls_Manager::SLIDER,
124 'default' => [
125 'size' => 30,
126 ],
127 'selectors' => [
128 '{{WRAPPER}} .usk-shiny-grid .usk-grid' => 'grid-column-gap: {{SIZE}}px;',
129 ],
130 ]
131 );
132
133 $this->add_responsive_control(
134 'items_row_gap',
135 [
136 'label' => esc_html__('Row Gap', 'ultimate-store-kit'),
137 'type' => Controls_Manager::SLIDER,
138 'default' => [
139 'size' => 30,
140 ],
141 'selectors' => [
142 '{{WRAPPER}} .usk-shiny-grid .usk-grid' => 'grid-row-gap: {{SIZE}}px;',
143 ],
144 ]
145 );
146
147 $this->register_global_controls_grid_layout();
148
149 $this->add_control(
150 'show_tab',
151 [
152 'label' => esc_html__('Columns Filter', 'ultimate-store-kit'),
153 'type' => Controls_Manager::SWITCHER,
154 'separator' => 'before'
155 ]
156 );
157
158 $this->add_control(
159 'filter_column_lists',
160 [
161 'label' => __('Select Column Type', 'ultimate-store-kit'),
162 'type' => Controls_Manager::SELECT2,
163 'label_block' => true,
164 'multiple' => true,
165 'options' => [
166 'list-2' => __('List', 'ultimate-store-kit'),
167 'grid-2' => __('Column 2', 'ultimate-store-kit'),
168 'grid-3' => __('Column 3', 'ultimate-store-kit'),
169 'grid-4' => __('Column 4', 'ultimate-store-kit'),
170 'grid-5' => __('Column 5', 'ultimate-store-kit'),
171 'grid-6' => __('Column 6', 'ultimate-store-kit'),
172
173 ],
174 'condition' => [
175 'show_tab' => 'yes'
176 ],
177 'default' => ['list-2', 'grid-2', 'grid-3', 'grid-4'],
178 ]
179 );
180 $this->add_control(
181 'show_result_count',
182 [
183 'label' => esc_html__('Result Count', 'ultimate-store-kit'),
184 'type' => Controls_Manager::SWITCHER,
185 'label_on' => esc_html__('Show', 'ultimate-store-kit'),
186 'label_off' => esc_html__('Hide', 'ultimate-store-kit'),
187 'return_value' => 'yes',
188 'default' => 'yes',
189 'separator' => 'before',
190 'condition' => [
191 'show_tab' => 'yes'
192 ]
193 ]
194 );
195 $this->add_control(
196 'show_pagination',
197 [
198 'label' => esc_html__('Pagination', 'ultimate-store-kit'),
199 'type' => Controls_Manager::SWITCHER,
200 'separator' => 'before'
201 ]
202 );
203
204 $this->end_controls_section();
205 $this->start_controls_section(
206 'section_post_query_builder',
207 [
208 'label' => __('Query', 'ultimate-store-kit'),
209 'tab' => Controls_Manager::TAB_CONTENT,
210 ]
211 );
212 $this->register_query_builder_controls();
213 $this->register_controls_wc_additional();
214 $this->end_controls_section();
215 $this->register_global_controls_additional();
216 $this->register_global_controls_grid_columns();
217 $this->register_global_controls_result_count();
218 $this->register_global_controls_grid_items();
219 $this->register_global_controls_grid_image();
220 $this->register_global_controls_content();
221 $this->register_global_controls_title();
222 $this->register_global_controls_category();
223 $this->register_global_controls_excerpt();
224 $this->register_global_controls_price();
225 $this->register_global_controls_rating();
226 $this->register_global_controls_badge();
227 $this->register_global_controls_add_to_cart();
228 $this->register_global_controls_action_btn();
229 $this->register_global_controls_grid_pagination();
230 }
231 public function render_header() {
232 $settings = $this->get_settings_for_display();
233 $this->add_render_attribute('usk-shiny-grid', 'class', 'usk-shiny-grid usk-grid-carousel usk-css-grid', true);
234 $this->add_render_attribute('usk-shiny-grid', 'data-filter', [$settings['show_tab']]);
235
236 ?>
237 <div class="ultimate-store-kit">
238 <div <?php $this->print_render_attribute_string('usk-shiny-grid'); ?>>
239 <?php $this->template_grid_columns(); ?>
240 <?php
241 }
242 public function render_footer() { ?>
243 </div>
244 </div>
245 <?php
246 }
247 public function render_add_to_cart() {
248 global $product;
249 $settings = $this->get_settings_for_display();
250 if ('yes' == $settings['show_cart']) : ?>
251 <?php if ($product) {
252 $defaults = [
253 'quantity' => 1,
254 'class' => implode(
255 ' ',
256 array_filter(
257 [
258 'usk-button',
259 'product_type_' . $product->get_type(),
260 $product->is_purchasable() && $product->is_in_stock() ? 'add_to_cart_button' : '',
261 $product->supports('ajax_add_to_cart') && $product->is_purchasable() && $product->is_in_stock() ? 'ajax_add_to_cart' : '',
262 ]
263 )
264 ),
265 'attributes' => [
266 'data-product_id' => $product->get_id(),
267 'data-product_sku' => $product->get_sku(),
268 'aria-label' => $product->add_to_cart_description(),
269 'rel' => 'nofollow',
270 ],
271 ];
272 $args = apply_filters('woocommerce_loop_add_to_cart_args', wp_parse_args($defaults), $product);
273 if (isset($args['attributes']['aria-label'])) {
274 $args['attributes']['aria-label'] = wp_strip_all_tags($args['attributes']['aria-label']);
275 }
276 echo wp_kses_post(apply_filters(
277 'woocommerce_loop_add_to_cart_link', // WPCS: XSS ok.
278 sprintf(
279 '<a href="%s" data-quantity="%s" class="%s" %s>%s <i class="button-icon usk-icon-arrow-right-8"></i></a>',
280 esc_url($product->add_to_cart_url()),
281 esc_attr(isset($args['quantity']) ? $args['quantity'] : 1),
282 esc_attr(isset($args['class']) ? $args['class'] : 'button'),
283 isset($args['attributes']) ? wc_implode_html_attributes($args['attributes']) : '',
284 esc_html($product->add_to_cart_text())
285 ),
286 $product,
287 $args
288 ));
289 }; ?>
290 <?php endif;
291 }
292 public function render_image() {
293 global $product;
294 $tooltip_position = 'left';
295 $settings = $this->get_settings_for_display();
296 $gallery_thumbs = $product->get_gallery_image_ids();
297 $product_image = wp_get_attachment_image_url(get_post_thumbnail_id(), $settings['image_size']);
298 if ($gallery_thumbs) {
299 foreach ($gallery_thumbs as $key => $gallery_thumb) {
300 if ($key == 0) :
301 $gallery_image_link = wp_get_attachment_image_url($gallery_thumb, $settings['image_size']);
302 endif;
303 }
304 } else {
305 $gallery_image_link = wp_get_attachment_image_url(get_post_thumbnail_id(), $settings['image_size']);
306 }
307 ?>
308 <div class="usk-image">
309 <a href="<?php echo esc_url(get_permalink()); ?>">
310 <img class="img image-default" src="<?php echo esc_url($product_image); ?>" alt="<?php echo esc_html(get_the_title()); ?>">
311 <img class="img image-hover" src="<?php echo esc_url($gallery_image_link); ?>" alt="<?php echo esc_html(get_the_title()); ?>">
312 </a>
313 <?php $this->render_add_to_cart(); ?>
314 <div class="usk-shoping">
315 <?php $this->register_global_template_add_to_wishlist($tooltip_position); ?>
316 <?php $this->register_global_template_add_to_compare($tooltip_position); ?>
317 <?php $this->register_global_template_quick_view($product->get_id(), $tooltip_position); ?>
318 </div>
319 <div class="usk-badge-label-wrapper">
320 <div class="usk-badge-label-content usk-flex usk-flex-column">
321 <?php $this->register_global_template_badge_label(); ?>
322 </div>
323 </div>
324 </div>
325 <?php
326 }
327 public function print_price_output($output) {
328 $tags = [
329 'del' => ['aria-hidden' => []],
330 'span' => ['class' => []],
331 'bdi' => [],
332 'ins' => [],
333 ];
334
335 if (isset($output)) {
336 echo wp_kses($output, $tags);
337 }
338 }
339 public function render_loop_item() {
340 $settings = $this->get_settings_for_display();
341 $this->query_product();
342 $wp_query = $this->get_query();
343
344
345 if ($settings['layout_style'] === 'grid') {
346 $this->add_render_attribute('usk-grid', 'class', ['usk-grid', 'usk-grid-layout']);
347 } else {
348 $this->add_render_attribute('usk-grid', 'class', ['usk-grid', 'usk-list-layout', 'usk-grid-2']);
349 }
350
351 if ($wp_query->have_posts()) { ?>
352 <div <?php $this->print_render_attribute_string('usk-grid'); ?>">
353 <?php while ($wp_query->have_posts()) : $wp_query->the_post();
354 global $product;
355 $rating_count = $product->get_rating_count();
356 $average = $product->get_average_rating();
357 if ($settings['show_rating'] == 'yes') {
358 $have_rating = 'usk-have-rating';
359 } else {
360 $have_rating = '';
361 }
362 $categories = str_replace(',', '', wc_get_product_category_list($product->get_id()));
363 ?>
364 <div class="usk-item <?php esc_attr_e($have_rating, 'utlimate-woo-kit'); ?>">
365 <div class="usk-item-box">
366 <?php $this->render_image(); ?>
367 <div class="usk-content">
368 <div class="usk-content-inner">
369 <?php if ('yes' == $settings['show_category']) : ?>
370 <?php printf('<%1$s class="usk-category">%2$s</%1$s>', esc_attr($settings['category_tags']), wp_kses_post($categories)); ?>
371 <?php endif; ?>
372 <?php if ('yes' == $settings['show_title']) :
373 printf('<a href="%2$s" class="usk-title"><%1$s class="title">%3$s</%1$s></a>', esc_attr($settings['title_tags']), esc_url($product->get_permalink()), esc_html($product->get_title()));
374 endif; ?>
375 <div class="usk-desc">
376 <span class="desc"><?php echo wp_kses_post(wp_trim_words($product->get_short_description(), $settings['excerpt_limit'], '…')); ?></span>
377 </div>
378 <?php if (('yes' == $settings['show_price'])) : ?>
379 <div class="usk-price">
380 <?php $this->print_price_output($product->get_price_html()); ?>
381 </div>
382 <?php endif; ?>
383
384 <?php if ('yes' == $settings['show_rating']) : ?>
385 <div class="usk-rating">
386 <span><?php echo wp_kses_post($this->register_global_template_wc_rating($average, $rating_count)); ?></span>
387 </div>
388 <?php endif; ?>
389 </div>
390 </div>
391 </div>
392 </div>
393 <?php endwhile; ?>
394 </div>
395 <?php if ($settings['show_pagination']) :
396 ultimate_store_kit_post_pagination($wp_query);
397 endif;
398 wp_reset_postdata();
399 } else { ?>
400 <div class="usk-warning">
401 <span><?php echo esc_html__('Ops! There no product to display', 'ultimate-store-kit'); ?></span>
402 </div>
403 <?php
404 }
405 }
406 public function render() {
407 $this->render_header();
408 $this->render_loop_item();
409 $this->render_footer();
410 }
411
412 public function query_product() {
413 $default = $this->getGroupControlQueryArgs();
414 $this->_query = new WP_Query($default);
415 }
416 protected function template_grid_columns() {
417 $settings = $this->get_settings_for_display();
418 $this->query_product();
419 $wp_query = $this->get_query();
420 if (get_query_var('paged')) {
421 $paged = get_query_var('paged');
422 } elseif (get_query_var('page')) {
423 $paged = get_query_var('page');
424 } else {
425 $paged = 1;
426 }
427 $args = array(
428 'total' => $wp_query->found_posts,
429 'per_page' => $settings['product_limit'],
430 'current' => $paged,
431 );
432 if ($settings['show_tab'] == 'yes') : ?>
433 <div class="usk-grid-header usk-visible@l">
434 <?php if (($settings['show_result_count'] == 'yes')) :
435 wc_get_template('loop/result-count.php', $args);
436 endif;
437 ?>
438 <ul class="usk-grid-header-tabs">
439 <?php if (in_array("list-2", $settings['filter_column_lists'])) : ?>
440 <li class="usk-grid-tabs-list">
441 <a class="tab-option" href="javascript:void(0)" data-grid-column="usk-list-2">
442 <span class="usk-icon-grid-list"></span>
443 </a>
444 </li>
445 <?php
446 endif;
447 if (in_array('grid-2', $settings['filter_column_lists'])) :
448 ?>
449 <li class="usk-grid-tabs-list">
450 <a class="tab-option" href="javascript:void(0)" data-grid-column="usk-grid-2">
451 <span class="usk-icon-grid-2"></span>
452 </a>
453 </li>
454 <?php
455 endif;
456 if (in_array('grid-3', $settings['filter_column_lists'])) :
457 ?>
458 <li class="usk-grid-tabs-list">
459 <a class="tab-option" href="javascript:void(0)" data-grid-column="usk-grid-3">
460 <span class="usk-icon-grid-3"></span>
461 </a>
462 </li>
463 <?php
464 endif;
465 if (in_array('grid-4', $settings['filter_column_lists'])) :
466 ?>
467 <li class="usk-grid-tabs-list">
468 <a class="tab-option" href="javascript:void(0)" data-grid-column="usk-grid-4">
469 <span class="usk-icon-grid-4"></span>
470 </a>
471 </li>
472 <?php
473 endif;
474 if (in_array('grid-5', $settings['filter_column_lists'])) :
475 ?>
476 <li class="usk-grid-tabs-list">
477 <a class="tab-option" href="javascript:void(0)" data-grid-column="usk-grid-5">
478 <span class="usk-icon-grid-5"></span>
479 </a>
480 </li>
481 <?php
482 endif;
483 if (in_array('grid-6', $settings['filter_column_lists'])) :
484 ?>
485 <li class="usk-grid-tabs-list">
486 <a class="tab-option" href="javascript:void(0)" data-grid-column="usk-grid-6">
487 <span class="usk-icon-grid-6"></span>
488 </a>
489 </li>
490 <?php
491 endif;
492 ?>
493 </ul>
494 </div>
495 <?php endif;
496 }
497 }
498