PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 1.0.1
ShopBuilder – WooCommerce Builder For Elementor v1.0.1
3.4.2 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 All 63 releases
shopbuilder / app / Abstracts / LoopWithProductSlider.php

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

441 lines 13.5 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\Widgets\Controls\ProductsSettings;
13 use RadiusTheme\SB\Elementor\Widgets\Controls\ReviewsStarSettings;
14 use RadiusTheme\SB\Elementor\Widgets\Controls\SliderSettings;
15
16 // Do not allow directly accessing this file.
17 if ( ! defined( 'ABSPATH' ) ) {
18 exit( 'This script cannot be accessed directly.' );
19 }
20
21 /**
22 * Product Description class
23 */
24 abstract class LoopWithProductSlider extends ElementorWidgetBase {
25 /**
26 * Action Button Traits.
27 */
28 use ActionBtnTraits;
29
30 /**
31 * Product Loop Settings.
32 *
33 * @var object $loop_settings
34 */
35 public $loop_settings;
36 /**
37 * Product Loop Settings.
38 *
39 * @var object $loop_settings
40 */
41 public $has_slider = true;
42 /**
43 * Product Loop Settings.
44 *
45 * @var object $loop_settings
46 */
47 public $has_title = true;
48 /**
49 * Product Loop Settings.
50 *
51 * @var object $loop_settings
52 */
53 public $has_pagination = false;
54 /**
55 * This function Will overwrite by the main function'
56 *
57 * @return array
58 */
59 abstract public function template_data_arg();
60 /**
61 * Widget Field
62 *
63 * @return array
64 */
65 public function widget_fields() {
66
67 $this->loop_settings = new ProductsSettings( $this );
68 $slider_control = $this->has_slider ? SliderSettings::slider_controls() : [];
69 $slider_style = $this->has_slider ? SliderSettings::slider_style( $this ) : [];
70 $heading = $this->has_title ? $this->loop_settings->heading_controls() : [];
71 $pagination = $this->has_pagination ? $this->loop_settings->pagination() : [];
72
73 $fields = $this->general_section() +
74 $this->loop_settings->widget_icons() +
75 $slider_control +
76 $heading +
77 $this->loop_settings->image_section() +
78 $this->loop_settings->product_title() +
79 $this->loop_settings->product_price() +
80 $this->loop_settings->flash_sale() +
81 ReviewsStarSettings::widget_fields( $this ) +
82 $this->loop_settings->add_to_cart() +
83 $this->loop_settings->module_button_style() +
84 $slider_style +
85 $pagination;
86 // Fns::is_module_active('wishlist')
87 return apply_filters( 'rtsb/elements/elementor/rtsb_product_loop/' . $this->rtsb_base, $fields, $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 ) ) {
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 'autoplay' => 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 * @return string
194 */
195 public function product_loop_end( $html ) {
196 $controllers = $this->get_settings_for_display();
197 $data = [
198 'template' => 'global/slider-footer',
199 'controllers' => $controllers,
200 'left_arrow' => Fns::icons_manager( $controllers['left_arrow_icon'] ),
201 'right_arrow' => Fns::icons_manager( $controllers['right_arrow_icon'] ),
202 ];
203 $new = Fns::load_template( $data['template'], $data, true );
204 $html = $html . $new;
205 return $html;
206 }
207 /**
208 * Product loop start function
209 *
210 * @return string
211 */
212 public function post_class( $classes ) {
213 $classes[] = 'swiper-slide';
214 return $classes;
215 }
216 /**
217 * Product loop start function
218 *
219 * @return string
220 */
221 public function is_rtsb_wrap_based_on_theme() {
222 $theme_list = apply_filters( 'rtsb/products/innner/wrapper/basedon/themes', [
223 'twentytwentyone',
224 'twentytwentytwo',
225 'twentytwentythree',
226 'storefront',
227 'hello-elementor',
228 'astra'
229 ], rtsb()->current_theme );
230 if ( in_array( rtsb()->current_theme, $theme_list, true) ) {
231 return true;
232 }
233 return false;
234 }
235 /**
236 * Image Wrapper.
237 *
238 * @return void
239 */
240 public function image_wrapper() {
241
242 if( ! $this->is_rtsb_wrap_based_on_theme() ){
243 return;
244 }
245 ?>
246 <div class="rtsb-image-wrapper">
247 <?php
248 }
249 /**
250 * Image Wrapper.
251 *
252 * @return void
253 */
254 public function div_close() {
255 if( ! $this->is_rtsb_wrap_based_on_theme() ){
256 return;
257 }
258 ?>
259 </div>
260 <?php
261 }
262 /**
263 * Image Wrapper.
264 *
265 * @return void
266 */
267 public function product_content_wrapper() {
268 if( ! $this->is_rtsb_wrap_based_on_theme() ){
269 return;
270 }
271 ?>
272 <div class="rtsb-product-content">
273 <?php
274 }
275
276 /**
277 * Apply hooks function.
278 *
279 * @return void
280 */
281 public function apply_hooks() {
282 $controllers = $this->get_settings_for_display();
283
284 if ( empty( $controllers['show_rating'] ) ) {
285 remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 );
286 add_filter( 'woocommerce_product_get_rating_html', '__return_false' );
287 }
288 if ( empty( $controllers['show_flash_sale'] ) ) {
289 add_filter( 'woocommerce_sale_flash', '__return_false' );
290 }
291 if ( ! empty( $controllers['slider_activate'] ) ) {
292 add_filter( 'woocommerce_product_loop_start', [ $this, 'product_loop_start' ] );
293 add_filter( 'woocommerce_product_loop_end', [ $this, 'product_loop_end' ] );
294 add_filter( 'woocommerce_post_class', [ $this, 'post_class' ], 10, 1 );
295 $this->script_init();
296 }
297
298 if ( class_exists('WooProductVariationSwatches') ) {
299 remove_action('woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 5);
300 remove_action('woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 20);
301 remove_action('woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 8);
302 remove_action('woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 12);
303 }
304
305 // Remove Action Button
306 add_filter( 'rtsb/module/wishlist/show_button', '__return_false' );
307 add_filter( 'rtsb/module/quick_view/show_button', '__return_false' );
308 add_filter( 'rtsb/module/compare/show_button', '__return_false' );
309
310 // Default Link remove.
311 remove_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 );
312 remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5 );
313
314 // Image Wrapper open.
315 add_action( 'woocommerce_before_shop_loop_item', [ $this, 'image_wrapper' ], -1 );
316
317 // Image link.
318 add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 9 );
319 add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 11 );
320 // Image link end.
321
322 // Title Link.
323 add_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 9 );
324 add_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 11 );
325 // Title Link end.
326
327 // Image Wrapper close.
328 add_action( 'woocommerce_before_shop_loop_item_title', [ $this, 'div_close' ], 12 );
329 // Content Wrapper Open.
330 add_action( 'woocommerce_before_shop_loop_item_title', [ $this, 'product_content_wrapper' ], 13 );
331 // Content Wrapper Close.
332 add_action( 'woocommerce_after_shop_loop_item', [ $this, 'div_close' ], 99 );
333
334 }
335 /**
336 * Apply hooks function.
337 *
338 * @return void
339 */
340 public function apply_hooks_set_default() {
341
342 // Default Link re active.
343 add_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 );
344 add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5 );
345
346 // Image Wrapper open.
347 remove_action( 'woocommerce_before_shop_loop_item', [ $this, 'image_wrapper' ], -1 );
348
349 // Image link.
350 remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 9 );
351 remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 11 );
352 // Image link end.
353
354 // Title Link.
355 remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 9 );
356 remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 11 );
357 // Title Link End.
358
359 // Image Wrapper close.
360 remove_action( 'woocommerce_before_shop_loop_item_title', [ $this, 'div_close' ], 12 );
361
362 // Content Wrapper Open.
363 remove_action( 'woocommerce_before_shop_loop_item_title', [ $this, 'product_content_wrapper' ], 13 );
364 // Content Wrapper Close.
365 remove_action( 'woocommerce_after_shop_loop_item', [ $this, 'div_close' ], 99 );
366
367 // Remove Action Button.
368 remove_filter( 'rtsb/module/wishlist/show_button', '__return_false' );
369 remove_filter( 'rtsb/module/quick_view/show_button', '__return_false' );
370 remove_filter( 'rtsb/module/compare/show_button', '__return_false' );
371
372 }
373 /**
374 * Related Product Args function'
375 *
376 * @param [type] $args argument.
377 * @return array
378 */
379 public function products_args( $args ) {
380 $controllers = $this->get_settings_for_display();
381 if ( ! empty( $controllers['posts_per_page'] ) ) {
382 $args['posts_per_page'] = intval( $controllers['posts_per_page'] );
383 }
384 if ( ! empty( $controllers['columns'] ) ) {
385 $args['columns'] = absint( $controllers['columns'] );
386 }
387 if ( ! empty( $controllers['orderby'] ) ) {
388 $args['orderby'] = $controllers['orderby'];
389 }
390 if ( ! empty( $controllers['order'] ) ) {
391 $args['order'] = $controllers['order'];
392 }
393 return $args;
394 }
395
396 /**
397 * Render Function
398 *
399 * @return void
400 */
401 protected function render() {
402 global $product, $post;
403 $data = $this->template_data_arg();
404 if ( empty( $data['template'] ) ) {
405 return;
406 }
407 $_product = $product;
408 $product = Fns::get_product();
409 $controllers = $this->get_settings_for_display();
410
411 $controllers['cart_icon_html'] = Fns::icons_manager( $controllers['cart_icon'] );
412
413 $this->apply_hooks();
414 $this->theme_support();
415
416 $this->action_button_icon_modify();
417
418 $data['controllers'] = $controllers;
419
420 Fns::load_template( $data['template'], $data );
421
422
423
424 $this->apply_hooks_set_default();
425 $this->action_button_icon_set_default();
426 $this->theme_support( 'render_reset' );
427
428 $product = $_product; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
429 if ( ! empty( $controllers['slider_activate'] ) ) {
430 remove_filter( 'woocommerce_product_loop_start', [ $this, 'product_loop_start' ] );
431 remove_filter( 'woocommerce_product_loop_end', [ $this, 'product_loop_end' ] );
432 remove_filter( 'woocommerce_post_class', [ $this, 'post_class' ], 10, 1 );
433 $this->editor_slider_script();
434 }
435
436 $this->editor_cart_icon_script();
437
438 }
439
440 }
441