PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.0.3
ShopBuilder – WooCommerce Builder For Elementor v2.0.3
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 2.0.3, at app/Abstracts/LoopWithProductSlider.php

459 lines 13.4 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['posts_per_page'] );
103 unset( $fields['columns'] );
104 unset( $fields['orderby'] );
105 unset( $fields['order'] );
106 }
107 return $fields;
108 }
109
110 /**
111 * Widget Field.
112 *
113 * @return void
114 */
115 public function script_init() {
116 wp_dequeue_script( 'rtsb-public' );
117
118 wp_enqueue_style( 'swiper' );
119 wp_enqueue_script( 'swiper' );
120 wp_enqueue_script( 'rtsb-public' );
121 }
122
123 /**
124 * Product loop start function
125 *
126 * @return string
127 */
128 public function product_loop_start( $html = '' ) {
129 $str = explode( 'products', $html );
130 if ( is_array( $str ) && count( $str ) > 1 ) {
131 $html = $str[0] . ' products swiper-wrapper ' . $str[1];
132 }
133 $controllers = $this->get_settings_for_display();
134
135 $swiper_data = [
136 // Optional parameters.
137 'wrapperClass' => 'products',
138 'slideClass' => 'product',
139 'slidesPerView' => 4,
140 'slidesPerGroup' => 3,
141 'spaceBetween' => 15,
142 'loop' => false,
143 ];
144 $classes = [];
145 if ( ! empty( $controllers['columns'] ) ) {
146 $swiper_data['slidesPerView'] = absint( $controllers['columns'] );
147 $swiper_data['slidesPerGroup'] = absint( $controllers['columns'] );
148 }
149 if ( ! empty( $controllers['space_between'] ) ) {
150 $swiper_data['spaceBetween'] = absint( $controllers['space_between'] );
151 }
152 if ( ! empty( $controllers['loop'] ) ) {
153 $swiper_data['loop'] = boolval( $controllers['loop'] );
154 }
155 if ( ! empty( $controllers['autoplay'] ) ) {
156 $swiper_data['autoplay']['delay'] = absint( $controllers['autoplay_delay'] );
157 $swiper_data['autoplay']['pauseOnMouseEnter'] = boolval( $controllers['pauseon_mouseenter'] );
158 $swiper_data['autoplay']['disableOnInteraction'] = false;
159 }
160 if ( ! empty( $controllers['speed'] ) ) {
161 $swiper_data['speed'] = absint( $controllers['speed'] );
162 }
163 if ( ! empty( $controllers['show_arrows'] ) ) {
164 $swiper_data['navigation'] = [
165 'nextEl' => '.button-right',
166 'prevEl' => '.button-left',
167 ];
168 $classes[] = 'has-navigation';
169 }
170 if ( ! empty( $controllers['show_dots'] ) ) {
171 $swiper_data['pagination'] = [
172 'el' => '.rtsb-slider-pagination',
173 'type' => 'bullets',
174 'clickable' => true,
175 ];
176 $classes[] = 'has-dots';
177 }
178
179 $data = [
180 'template' => 'global/slider-header',
181 'controllers' => $controllers,
182 'swiper_json_data' => wp_json_encode( $swiper_data ),
183 'classes' => $classes,
184 ];
185 $new = Fns::load_template( $data['template'], $data, true );
186 $html = $new . $html;
187 return $html;
188 }
189 /**
190 * Product loop start function
191 *
192 * @return string
193 */
194 public function product_loop_end( $html ) {
195 $controllers = $this->get_settings_for_display();
196 $data = [
197 'template' => 'global/slider-footer',
198 'controllers' => $controllers,
199 'left_arrow' => Fns::icons_manager( $controllers['left_arrow_icon'] ),
200 'right_arrow' => Fns::icons_manager( $controllers['right_arrow_icon'] ),
201 ];
202 $new = Fns::load_template( $data['template'], $data, true );
203 $html = $html . $new;
204 return $html;
205 }
206 /**
207 * Product loop start function
208 *
209 * @return string
210 */
211 public function post_class( $classes ) {
212 $classes[] = 'swiper-slide';
213 return $classes;
214 }
215
216 /**
217 * Image Wrapper.
218 *
219 * @return void
220 */
221 public function image_wrapper() {
222 if ( ! RenderHelpers::is_wrapper_needed() ) {
223 return;
224 }
225 ?>
226 <div class="rtsb-image-wrapper">
227 <?php
228 }
229 /**
230 * Image Wrapper.
231 *
232 * @return void
233 */
234 public function div_close() {
235 if ( ! RenderHelpers::is_wrapper_needed() ) {
236 return;
237 }
238 ?>
239 </div>
240 <?php
241 }
242 /**
243 * Image Wrapper.
244 *
245 * @return void
246 */
247 public function product_content_wrapper() {
248 if ( ! RenderHelpers::is_wrapper_needed() ) {
249 return;
250 }
251 ?>
252 <div class="rtsb-product-content">
253 <?php
254 }
255
256 /**
257 * Apply hooks function.
258 *
259 * @return void
260 */
261 public function apply_hooks() {
262 $controllers = $this->get_settings_for_display();
263
264 if ( empty( $controllers['show_rating'] ) ) {
265 remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 );
266 add_filter( 'woocommerce_product_get_rating_html', '__return_false' );
267 }
268 if ( empty( $controllers['show_flash_sale'] ) ) {
269 add_filter( 'woocommerce_sale_flash', '__return_false' );
270 }
271 if ( ! empty( $controllers['slider_activate'] ) ) {
272 add_filter( 'woocommerce_product_loop_start', [ $this, 'product_loop_start' ] );
273 add_filter( 'woocommerce_product_loop_end', [ $this, 'product_loop_end' ] );
274 add_filter( 'woocommerce_post_class', [ $this, 'post_class' ], 10, 1 );
275 $this->script_init();
276 }
277
278 if ( class_exists( 'WooProductVariationSwatches' ) ) {
279 remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 5 );
280 remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 20 );
281 remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 8 );
282 remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 12 );
283 }
284
285 // Remove Action Button
286 add_filter( 'rtsb/module/wishlist/show_button', '__return_false' );
287 add_filter( 'rtsb/module/quick_view/show_button', '__return_false' );
288 add_filter( 'rtsb/module/compare/show_button', '__return_false' );
289
290 //TODO:: Pro Will move if necessary
291 if ( empty( $controllers['show_quick_checkout'] ) ) {
292 add_filter( 'rtsb/module/quick_checkout/show_button', '__return_false' );
293 }
294 if ( empty( $controllers['show_flash_sale_countdown'] ) ) {
295 add_filter( 'rtsb/module/flash_sale_countdown/show_counter', '__return_false' );
296 }
297
298 // Default Link remove.
299 remove_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 );
300 remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5 );
301
302 // Image Wrapper open.
303 add_action( 'woocommerce_before_shop_loop_item', [ $this, 'image_wrapper' ], -1 );
304
305 // Image link.
306 add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 9 );
307 add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 11 );
308 // Image link end.
309
310 // Title Link.
311 add_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 9 );
312 add_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 11 );
313 // Title Link end.
314
315 // Image Wrapper close.
316 add_action( 'woocommerce_before_shop_loop_item_title', [ $this, 'div_close' ], 12 );
317 // Content Wrapper Open.
318 add_action( 'woocommerce_before_shop_loop_item_title', [ $this, 'product_content_wrapper' ], 13 );
319 // Content Wrapper Close.
320 add_action( 'woocommerce_after_shop_loop_item', [ $this, 'div_close' ], 99 );
321
322
323 if ( $this->is_edit_mode() ){
324 if( class_exists( Rtwpvs\Controllers\Hooks::class ) ){
325 remove_filter( 'woocommerce_ajax_variationX_threshold', [ Rtwpvs\Controllers\Hooks::class, 'ajax_variation_threshold' ], 99 );
326 }
327 add_filter( 'woocommerce_ajax_variation_threshold', function (){
328 return 1;
329 }, 99 );
330
331 }
332
333 }
334 /**
335 * Apply hooks function.
336 *
337 * @return void
338 */
339 public function apply_hooks_set_default() {
340
341 // Default Link re active.
342 add_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 );
343 add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5 );
344
345 // Image Wrapper open.
346 remove_action( 'woocommerce_before_shop_loop_item', [ $this, 'image_wrapper' ], -1 );
347
348 // Image link.
349 remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 9 );
350 remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 11 );
351 // Image link end.
352
353 // Title Link.
354 remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 9 );
355 remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 11 );
356 // Title Link End.
357
358 // Image Wrapper close.
359 remove_action( 'woocommerce_before_shop_loop_item_title', [ $this, 'div_close' ], 12 );
360
361 // Content Wrapper Open.
362 remove_action( 'woocommerce_before_shop_loop_item_title', [ $this, 'product_content_wrapper' ], 13 );
363 // Content Wrapper Close.
364 remove_action( 'woocommerce_after_shop_loop_item', [ $this, 'div_close' ], 99 );
365
366 // Remove Action Button.
367 remove_filter( 'rtsb/module/wishlist/show_button', '__return_false' );
368 remove_filter( 'rtsb/module/quick_view/show_button', '__return_false' );
369 remove_filter( 'rtsb/module/compare/show_button', '__return_false' );
370
371 }
372 /**
373 * Related Product Args function'
374 *
375 * @param [type] $args argument.
376 * @return array
377 */
378 public function products_args( $args ) {
379 $controllers = $this->get_settings_for_display();
380 if ( ! empty( $controllers['posts_per_page'] ) ) {
381 $args['posts_per_page'] = intval( $controllers['posts_per_page'] );
382 }
383 if ( ! empty( $controllers['columns'] ) ) {
384 $args['columns'] = absint( $controllers['columns'] );
385 }
386 if ( ! empty( $controllers['orderby'] ) ) {
387 $args['orderby'] = $controllers['orderby'];
388 }
389 if ( ! empty( $controllers['order'] ) ) {
390 $args['order'] = $controllers['order'];
391 }
392 return $args;
393 }
394
395 /**
396 * Elementor Edit mode script
397 *
398 * @return void
399 */
400 public function editor_script() {
401 if ( ! $this->is_edit_mode() ) {
402 return;
403 }
404 ?>
405 <script>
406 <?php if ( rtsb()->has_pro() ) { ?>
407 setTimeout( function (){
408 window.rtsbCountdownApply();
409 }, 1000 );
410 <?php } ?>
411 </script>
412 <?php
413 }
414
415 /**
416 * Render Function
417 *
418 * @return void
419 */
420 protected function render() {
421 global $product, $post;
422 $data = $this->template_data_arg();
423 if ( empty( $data['template'] ) ) {
424 return;
425 }
426 $_product = $product;
427 $product = Fns::get_product();
428 $controllers = $this->get_settings_for_display();
429
430 $controllers['cart_icon_html'] = Fns::icons_manager( $controllers['cart_icon'] );
431
432 $this->apply_hooks();
433 $this->theme_support();
434
435 $this->action_button_icon_modify();
436
437 $data['controllers'] = $controllers;
438
439 Fns::load_template( $data['template'], $data );
440
441 $this->apply_hooks_set_default();
442 $this->action_button_icon_set_default();
443 $this->theme_support( 'render_reset' );
444
445 $product = $_product; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
446 if ( ! empty( $controllers['slider_activate'] ) ) {
447 remove_filter( 'woocommerce_product_loop_start', [ $this, 'product_loop_start' ] );
448 remove_filter( 'woocommerce_product_loop_end', [ $this, 'product_loop_end' ] );
449 remove_filter( 'woocommerce_post_class', [ $this, 'post_class' ], 10, 1 );
450 $this->editor_slider_script();
451 }
452
453 $this->editor_script();
454 $this->editor_cart_icon_script();
455
456 }
457
458 }
459