PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / trunk
ShopBuilder – WooCommerce Builder For Elementor vtrunk
3.4.1 3.4.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.3.0 All 62 releases
shopbuilder / app / Abstracts / LoopWithProductSlider.php

LoopWithProductSlider.php in ShopBuilder – WooCommerce Builder For Elementor trunk, at app/Abstracts/LoopWithProductSlider.php

470 lines 13.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Main ProductDescription class.
4 *
5 * @package RadiusTheme\SB
6 */
7
8 namespace RadiusTheme\SB\Abstracts;
9
10 use RadiusTheme\SB\Helpers\Fns;
11 use RadiusTheme\SB\Traits\ActionBtnTraits;
12 use RadiusTheme\SB\Elementor\Helper\RenderHelpers;
13 use RadiusTheme\SB\Elementor\Widgets\Controls\StyleFields;
14 use RadiusTheme\SB\Elementor\Widgets\Controls\SliderSettings;
15 use RadiusTheme\SB\Elementor\Widgets\Controls\ProductsSettings;
16 use RadiusTheme\SB\Elementor\Widgets\Controls\ReviewsStarSettings;
17
18 // Do not allow directly accessing this file.
19 if ( ! defined( 'ABSPATH' ) ) {
20 exit( 'This script cannot be accessed directly.' );
21 }
22
23 /**
24 * Product Description class
25 */
26 abstract class LoopWithProductSlider extends ElementorWidgetBase {
27 /**
28 * Action Button Traits.
29 */
30 use ActionBtnTraits;
31
32 /**
33 * Product Loop Settings.
34 *
35 * @var object $loop_settings
36 */
37 public $loop_settings;
38 /**
39 * Product Loop Settings.
40 *
41 * @var object $loop_settings
42 */
43 public $has_slider = true;
44 /**
45 * Product Loop Settings.
46 *
47 * @var object $loop_settings
48 */
49 public $has_title = true;
50 /**
51 * Product Loop Settings.
52 *
53 * @var object $loop_settings
54 */
55 public $has_pagination = false;
56 /**
57 * This function Will overwrite by the main function'
58 *
59 * @return array
60 */
61 abstract public function template_data_arg();
62 /**
63 * Widget Field
64 *
65 * @return array
66 */
67 public function widget_fields() {
68 $this->loop_settings = new ProductsSettings( $this );
69 $slider_control = $this->has_slider ? SliderSettings::slider_controls() : [];
70 $slider_style = $this->has_slider ? SliderSettings::slider_style( $this ) : [];
71 $heading = $this->has_title ? $this->loop_settings->heading_controls() : [];
72 $pagination = $this->has_pagination ? $this->loop_settings->pagination() : [];
73
74 return $this->general_section() +
75 $this->loop_settings->widget_icons() +
76 $slider_control +
77 $heading +
78 $this->loop_settings->image_section() +
79 $this->loop_settings->product_title() +
80 $this->loop_settings->product_price() +
81 $this->loop_settings->flash_sale() +
82 ReviewsStarSettings::widget_fields( $this ) +
83 $this->loop_settings->add_to_cart() +
84 $this->loop_settings->module_button_style() +
85 $slider_style +
86 $pagination +
87 StyleFields::not_found_notice( $this );
88 }
89
90 /**
91 * Widget Field
92 *
93 * @return array
94 */
95 public function general_section() {
96 $fields = $this->loop_settings->general_section();
97 if ( 'rtsb-related-product' === $this->rtsb_base ) {
98 unset( $fields['orderby'] );
99 unset( $fields['order'] );
100 }
101 if ( 'rtsb-products-archive' === $this->rtsb_base ) {
102 unset( $fields['columns'] );
103 unset( $fields['orderby'] );
104 unset( $fields['order'] );
105 }
106 return $fields;
107 }
108
109 /**
110 * Widget Field.
111 *
112 * @return void
113 */
114 public function script_init() {
115 $handle = Fns::optimized_handle( 'rtsb-public' );
116 wp_dequeue_script( $handle );
117
118 wp_enqueue_script( 'swiper' );
119 wp_enqueue_script( $handle );
120 }
121
122 /**
123 * Product loop start function
124 *
125 * @param string $html html.
126 *
127 * @return string
128 */
129 public function product_loop_start( $html = '' ) {
130 $str = explode( 'products', $html );
131 if ( is_array( $str ) && count( $str ) > 1 ) {
132 $html = $str[0] . ' products swiper-wrapper ' . $str[1];
133 }
134 $controllers = $this->get_settings_for_display();
135
136 $swiper_data = [
137 // Optional parameters.
138 'wrapperClass' => 'products',
139 'slideClass' => 'product',
140 'slidesPerView' => 4,
141 'slidesPerGroup' => 3,
142 'spaceBetween' => 15,
143 'loop' => false,
144 ];
145 $classes = [];
146 if ( ! empty( $controllers['columns'] ) ) {
147 $swiper_data['slidesPerView'] = absint( $controllers['columns'] );
148 $swiper_data['slidesPerGroup'] = absint( $controllers['columns'] );
149 }
150 if ( ! empty( $controllers['space_between'] ) ) {
151 $swiper_data['spaceBetween'] = absint( $controllers['space_between'] );
152 }
153 if ( ! empty( $controllers['loop'] ) ) {
154 $swiper_data['loop'] = boolval( $controllers['loop'] );
155 }
156 if ( ! empty( $controllers['autoplay'] ) ) {
157 $swiper_data['autoplay']['delay'] = absint( $controllers['autoplay_delay'] );
158 $swiper_data['autoplay']['pauseOnMouseEnter'] = boolval( $controllers['pauseon_mouseenter'] );
159 $swiper_data['autoplay']['disableOnInteraction'] = false;
160 }
161 if ( ! empty( $controllers['speed'] ) ) {
162 $swiper_data['speed'] = absint( $controllers['speed'] );
163 }
164 if ( ! empty( $controllers['show_arrows'] ) ) {
165 $swiper_data['navigation'] = [
166 'nextEl' => '.button-right',
167 'prevEl' => '.button-left',
168 ];
169 $classes[] = 'has-navigation';
170 }
171 if ( ! empty( $controllers['show_dots'] ) ) {
172 $swiper_data['pagination'] = [
173 'el' => '.rtsb-slider-pagination',
174 'type' => 'bullets',
175 'clickable' => true,
176 ];
177 $classes[] = 'has-dots';
178 }
179
180 $data = [
181 'template' => 'global/slider-header',
182 'controllers' => $controllers,
183 'swiper_json_data' => wp_json_encode( $swiper_data ),
184 'classes' => $classes,
185 ];
186 $new = Fns::load_template( $data['template'], $data, true );
187 $html = $new . $html;
188 return $html;
189 }
190 /**
191 * Product loop start function
192 *
193 * @param string $html html.
194 *
195 * @return string
196 */
197 public function product_loop_end( $html ) {
198 $controllers = $this->get_settings_for_display();
199 $data = [
200 'template' => 'global/slider-footer',
201 'controllers' => $controllers,
202 'left_arrow' => Fns::icons_manager( $controllers['left_arrow_icon'] ),
203 'right_arrow' => Fns::icons_manager( $controllers['right_arrow_icon'] ),
204 ];
205 $new = Fns::load_template( $data['template'], $data, true );
206 $html = $html . $new;
207 return $html;
208 }
209 /**
210 * Product loop start function
211 *
212 * @param string $classes classes.
213 *
214 * @return string
215 */
216 public function post_class( $classes ) {
217 $classes[] = 'swiper-slide';
218 return $classes;
219 }
220
221 /**
222 * Image Wrapper.
223 *
224 * @return void
225 */
226 public function image_wrapper() {
227 if ( ! RenderHelpers::is_wrapper_needed() ) {
228 return;
229 }
230 ?>
231 <div class="rtsb-image-wrapper">
232 <?php
233 }
234 /**
235 * Image Wrapper.
236 *
237 * @return void
238 */
239 public function div_close() {
240 if ( ! RenderHelpers::is_wrapper_needed() ) {
241 return;
242 }
243 ?>
244 </div>
245 <?php
246 }
247 /**
248 * Image Wrapper.
249 *
250 * @return void
251 */
252 public function product_content_wrapper() {
253 if ( ! RenderHelpers::is_wrapper_needed() ) {
254 return;
255 }
256 ?>
257 <div class="rtsb-product-content">
258 <?php
259 }
260
261 /**
262 * Apply hooks function.
263 *
264 * @return void
265 */
266 public function apply_hooks() {
267 $controllers = $this->get_settings_for_display();
268
269 if ( empty( $controllers['show_rating'] ) ) {
270 remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 );
271 add_filter( 'woocommerce_product_get_rating_html', '__return_false' );
272 }
273 if ( empty( $controllers['show_flash_sale'] ) ) {
274 add_filter( 'woocommerce_sale_flash', '__return_false' );
275 }
276 if ( ! empty( $controllers['slider_activate'] ) ) {
277 add_filter( 'woocommerce_product_loop_start', [ $this, 'product_loop_start' ] );
278 add_filter( 'woocommerce_product_loop_end', [ $this, 'product_loop_end' ] );
279 add_filter( 'woocommerce_post_class', [ $this, 'post_class' ], 10, 1 );
280 $this->script_init();
281 }
282
283 if ( class_exists( 'WooProductVariationSwatches' ) ) {
284 remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 5 );
285 remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 20 );
286 remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 8 );
287 remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 12 );
288 }
289
290 // Remove Action Button.
291 add_filter( 'rtsb/module/wishlist/show_button', '__return_false' );
292 add_filter( 'rtsb/module/quick_view/show_button', '__return_false' );
293 add_filter( 'rtsb/module/compare/show_button', '__return_false' );
294
295 if ( empty( $controllers['show_quick_checkout'] ) ) {
296 add_filter( 'rtsb/module/quick_checkout/show_button', '__return_false' );
297 }
298 if ( empty( $controllers['show_flash_sale_countdown'] ) ) {
299 add_filter( 'rtsb/module/flash_sale_countdown/show_counter', '__return_false' );
300 }
301
302 // Default Link remove.
303 remove_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 );
304 remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5 );
305
306 // Image Wrapper open.
307 add_action( 'woocommerce_before_shop_loop_item', [ $this, 'image_wrapper' ], -1 );
308
309 // Image link.
310 add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 9 );
311 add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 11 );
312 // Image link end.
313
314 // Title Link.
315 add_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 9 );
316 add_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 11 );
317 // Title Link end.
318
319 // Image Wrapper close.
320 add_action( 'woocommerce_before_shop_loop_item_title', [ $this, 'div_close' ], 12 );
321 // Content Wrapper Open.
322 add_action( 'woocommerce_before_shop_loop_item_title', [ $this, 'product_content_wrapper' ], 13 );
323 // Content Wrapper Close.
324 add_action( 'woocommerce_after_shop_loop_item', [ $this, 'div_close' ], 99 );
325
326 if ( $this->is_edit_mode() ) {
327 if ( class_exists( Rtwpvs\Controllers\Hooks::class ) ) {
328 remove_filter( 'woocommerce_ajax_variationX_threshold', [ Rtwpvs\Controllers\Hooks::class, 'ajax_variation_threshold' ], 99 );
329 }
330 add_filter(
331 'woocommerce_ajax_variation_threshold',
332 function () {
333 return 1;
334 },
335 99
336 );
337
338 }
339 }
340 /**
341 * Apply hooks function.
342 *
343 * @return void
344 */
345 public function apply_hooks_set_default() {
346
347 // Default Link re active.
348 add_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 );
349 add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5 );
350
351 // Image Wrapper open.
352 remove_action( 'woocommerce_before_shop_loop_item', [ $this, 'image_wrapper' ], -1 );
353
354 // Image link.
355 remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 9 );
356 remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 11 );
357 // Image link end.
358
359 // Title Link.
360 remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 9 );
361 remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 11 );
362 // Title Link End.
363
364 // Image Wrapper close.
365 remove_action( 'woocommerce_before_shop_loop_item_title', [ $this, 'div_close' ], 12 );
366
367 // Content Wrapper Open.
368 remove_action( 'woocommerce_before_shop_loop_item_title', [ $this, 'product_content_wrapper' ], 13 );
369 // Content Wrapper Close.
370 remove_action( 'woocommerce_after_shop_loop_item', [ $this, 'div_close' ], 99 );
371
372 // Remove Action Button.
373 remove_filter( 'rtsb/module/wishlist/show_button', '__return_false' );
374 remove_filter( 'rtsb/module/quick_view/show_button', '__return_false' );
375 remove_filter( 'rtsb/module/compare/show_button', '__return_false' );
376 }
377 /**
378 * Related Product Args function'
379 *
380 * @param [type] $args argument.
381 * @return array
382 */
383 public function products_args( $args ) {
384 $controllers = $this->get_settings_for_display();
385 if ( ! empty( $controllers['posts_per_page'] ) ) {
386 $args['posts_per_page'] = intval( $controllers['posts_per_page'] );
387 }
388 if ( ! empty( $controllers['columns'] ) ) {
389 $args['columns'] = absint( $controllers['columns'] );
390 }
391 if ( ! empty( $controllers['orderby'] ) ) {
392 $args['orderby'] = $controllers['orderby'];
393 }
394 if ( ! empty( $controllers['order'] ) ) {
395 $args['order'] = $controllers['order'];
396 }
397 return $args;
398 }
399
400 /**
401 * Elementor Edit mode script
402 *
403 * @return void
404 */
405 public function editor_script() {
406 if ( ! $this->is_edit_mode() ) {
407 return;
408 }
409 ?>
410 <script>
411 <?php if ( rtsb()->has_pro() ) { ?>
412 if (!'<?php echo esc_attr( Fns::is_optimization_enabled() ); ?>') {
413 setTimeout( function (){
414 window.rtsbCountdownApply();
415 }, 1000 );
416 } else {
417 if (typeof elementorFrontend !== 'undefined') {
418 window.waitForRTSB((RTSB) => {
419 RTSB.modules.get('countdownPro')?.refresh();
420 });
421 }
422 }
423 <?php } ?>
424 </script>
425 <?php
426 }
427
428 /**
429 * Render Function
430 *
431 * @return void
432 */
433 protected function render() {
434 global $product, $post;
435 $data = $this->template_data_arg();
436 if ( empty( $data['template'] ) ) {
437 return;
438 }
439 $_product = $product;
440 $product = Fns::get_product();
441 $controllers = $this->get_settings_for_display();
442
443 $controllers['cart_icon_html'] = Fns::icons_manager( $controllers['cart_icon'] );
444
445 $this->apply_hooks();
446 $this->theme_support();
447
448 $this->action_button_icon_modify();
449
450 $data['controllers'] = $controllers;
451
452 Fns::load_template( $data['template'], $data );
453
454 $this->apply_hooks_set_default();
455 $this->action_button_icon_set_default();
456 $this->theme_support( 'render_reset' );
457
458 $product = $_product; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
459 if ( ! empty( $controllers['slider_activate'] ) ) {
460 remove_filter( 'woocommerce_product_loop_start', [ $this, 'product_loop_start' ] );
461 remove_filter( 'woocommerce_product_loop_end', [ $this, 'product_loop_end' ] );
462 remove_filter( 'woocommerce_post_class', [ $this, 'post_class' ], 10, 1 );
463 $this->editor_slider_script();
464 }
465
466 $this->editor_script();
467 $this->editor_cart_icon_script();
468 }
469 }
470