PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.1.1
ShopBuilder – WooCommerce Builder For Elementor v2.1.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 / Elementor / Widgets / Single / ProductImages.php

ProductImages.php in ShopBuilder – WooCommerce Builder For Elementor 2.1.1, at app/Elementor/Widgets/Single/ProductImages.php

225 lines 6.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Main ProductImages class.
4 *
5 * @package RadiusTheme\SB
6 */
7
8 namespace RadiusTheme\SB\Elementor\Widgets\Single;
9
10 use RadiusTheme\SB\Helpers\BuilderFns;
11 use RadiusTheme\SB\Helpers\ElementorDataMap;
12 use RadiusTheme\SB\Helpers\Fns;
13 use RadiusTheme\SB\Abstracts\ElementorWidgetBase;
14 use RadiusTheme\SB\Elementor\Widgets\Controls\ProductImagesSettings;
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 Images class
23 */
24 class ProductImages extends ElementorWidgetBase {
25 /**
26 * Construct function
27 *
28 * @param array $data default array.
29 * @param mixed $args default arg.
30 */
31 public function __construct( $data = [], $args = null ) {
32 $this->rtsb_name = esc_html__( 'Product Images', 'shopbuilder' );
33 $this->rtsb_base = 'rtsb-product-image';
34 parent::__construct( $data, $args );
35 add_action( 'wp_footer', 'woocommerce_photoswipe' );
36 $this->the_hooks();
37 }
38 /**
39 * Widget Field
40 *
41 * @return array
42 */
43 public function widget_fields() {
44 return ProductImagesSettings::widget_fields( $this );
45 }
46
47 /**
48 * Widget Field.
49 *
50 * @return void
51 */
52 public function editor_scripts() {
53 ?>
54 <script>
55 /*
56 * Initialize all galleries on page.
57 */
58 jQuery('.woocommerce-product-gallery').each(function () {
59 const that = this;
60 jQuery(this).trigger('wc-product-gallery-before-init', [this, wc_single_product_params]);
61 setTimeout(function () {
62 jQuery(that).wc_product_gallery(wc_single_product_params);
63 }, 1000);
64
65 jQuery(this).trigger('wc-product-gallery-after-init', [this, wc_single_product_params]);
66 });
67 <?php if ( function_exists( 'rtwpvg' ) ) { ?>
68 setTimeout(function () {
69 jQuery('.rtsb-product-images .rtwpvg-wrapper').rtWpVGallery();
70 }, 1000);
71 <?php } ?>
72
73 jQuery(document).ready(function ($) {
74 setTimeout(function () {
75 const zoomIcon = $('.rtsb-product-images').attr('data-zoom-icon');
76 if (!zoomIcon) {
77 $('.rtsb-product-images')
78 .find('.woocommerce-product-gallery__trigger,.rtwpvg-trigger')
79 .remove();
80 }
81 $('.rtsb-product-images')
82 .find('.woocommerce-product-gallery__trigger,.rtwpvg-trigger')
83 .html(zoomIcon);
84 }, 50);
85 });
86 </script>
87 <?php
88 }
89
90 /**
91 * Widget Field.
92 *
93 * @param array $control Control.
94 *
95 * @return void
96 */
97 public function the_hooks( $control = [] ) {
98 if ( empty( $control ) ) {
99 return;
100 }
101 add_filter(
102 'woocommerce_product_thumbnails_columns',
103 function ( $col ) {
104 $col = 0;
105
106 return $col;
107 }
108 );
109 if ( empty( $control['show_zoom'] ) ) {
110 add_filter( 'rtwpvg_trigger_icon', '__return_false' );
111 }
112 if ( empty( $control['show_thumbnails'] ) ) {
113 add_filter( 'rtwpvg_show_product_thumbnail_slider', '__return_false' );
114 remove_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20 );
115 }
116 add_filter( 'rtwpvg_thumbnail_slider_js_options', [ $this, 'thumbnail_slider_js_options' ], 50 );
117 add_filter( 'rtwpvg_thumbnail_position', [ $this, 'thumbnail_position' ], 50 );
118 add_filter( 'rtwpvg_thumbnails_columns', [ $this, 'thumbnails_columns' ] );
119 add_filter( 'rtwpvg_sm_thumbnails_columns', [ $this, 'thumbnails_columns_sm' ] );
120 add_filter( 'rtwpvg_xs_thumbnails_columns', [ $this, 'thumbnails_columns_xs' ] );
121 // add_filter( 'rtwpvg_image_classes', [ $this, 'rtwpvg_image_classes' ], 15 );
122
123 }
124
125 /**
126 * @param $position
127 *
128 * @return mixed
129 */
130 public function rtwpvg_image_classes( $classes ) {
131 $controllers = $this->get_settings_for_display();
132 $show_thumbnails = ! empty( $controllers['show_thumbnails'] ) ? $controllers['show_thumbnails'] : false;
133
134 if ( ! $show_thumbnails ) {
135 $key = array_search( 'rtwpvg-has-product-thumbnail', $classes );
136 if ( $key ) {
137 unset( $classes[ $key ] );
138 add_filter( 'rtwpvg_show_product_thumbnail_slider', '__return_false', 20 );
139 }
140 }
141
142 return $classes;
143 }
144
145 public function thumbnail_slider_js_options( $options ) {
146 if( isset( $options['spaceBetween'] ) ){
147 $controllers = $this->get_settings_for_display();
148 $options['spaceBetween'] = $controllers['gallery_thumbs_column_gap']['size'] ;
149 }
150 return $options;
151 }
152
153 public function thumbnails_columns( $column ) {
154 $controllers = $this->get_settings_for_display();
155 $column = ! empty( $controllers['gallery_thumbs_column']['size'] ) ? $controllers['gallery_thumbs_column']['size'] : $column;
156
157 return $column;
158 }
159
160 public function thumbnails_columns_sm( $column ) {
161 $controllers = $this->get_settings_for_display();
162 $column = ! empty( $controllers['gallery_thumbs_column_tablet']['size'] ) ? $controllers['gallery_thumbs_column_tablet']['size'] : $column;
163
164 return $column;
165 }
166
167 public function thumbnails_columns_xs( $column ) {
168 $controllers = $this->get_settings_for_display();
169 $column = ! empty( $controllers['gallery_thumbs_column_mobile']['size'] ) ? $controllers['gallery_thumbs_column_mobile']['size'] : $column;
170
171 return $column;
172 }
173
174 /**
175 * @param $position
176 *
177 * @return mixed
178 */
179 public function thumbnail_position( $position ) {
180 if ( ! function_exists( 'rtwpvg' ) || ! rtwpvg()->active_pro() || ! BuilderFns::is_product() ) {
181 return $position;
182 }
183
184 $controllers = $this->get_settings_for_display();
185 $show_thumbnails = ! empty( $controllers['show_thumbnails'] ) ? $controllers['show_thumbnails'] : false;
186
187 if ( ! $show_thumbnails ) {
188 add_filter( 'rtwpvg_show_product_thumbnail_slider', '__return_false', 20 );
189 return 'bottom';
190 }
191
192 return ! empty( $controllers['image_layout'] ) ? $controllers['image_layout'] : 'bottom';
193 }
194
195 /**
196 * Render Function
197 *
198 * @return void
199 */
200 protected function render() {
201 global $product, $post;
202 $_product = $product;
203 $product = Fns::get_product();
204 $controllers = $this->get_settings_for_display();
205
206 $this->theme_support();
207
208 $controllers['lightbox_icon'] = Fns::icons_manager( $controllers['lightbox_icon'] );
209 $data = [
210 'template' => 'elementor/single-product/product-images',
211 'controllers' => $controllers,
212 ];
213 $this->the_hooks( $controllers );
214
215 Fns::load_template( $data['template'], $data );
216
217 if ( $this->is_edit_mode() ) {
218 $this->editor_scripts();
219 }
220 $this->theme_support( 'render_reset' );
221 $product = $_product; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
222 }
223
224 }
225