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