PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.2.0
ShopBuilder – WooCommerce Builder For Elementor v2.2.0
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.2.0, at app/Elementor/Widgets/Single/ProductImages.php

233 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 use RadiusTheme\SBPRO\Helpers\BuilderFunPro;
16
17 // Do not allow directly accessing this file.
18 if ( ! defined( 'ABSPATH' ) ) {
19 exit( 'This script cannot be accessed directly.' );
20 }
21
22 /**
23 * Product Images class
24 */
25 class ProductImages extends ElementorWidgetBase {
26 /**
27 * Construct function
28 *
29 * @param array $data default array.
30 * @param mixed $args default arg.
31 */
32 public function __construct( $data = [], $args = null ) {
33 $this->rtsb_name = esc_html__( 'Product Images', 'shopbuilder' );
34 $this->rtsb_base = 'rtsb-product-image';
35 parent::__construct( $data, $args );
36 add_action( 'wp_footer', 'woocommerce_photoswipe' );
37 $this->the_hooks();
38 }
39 /**
40 * Widget Field
41 *
42 * @return array
43 */
44 public function widget_fields() {
45 return ProductImagesSettings::widget_fields( $this );
46 }
47
48 /**
49 * Widget Field.
50 *
51 * @return void
52 */
53 public function init_scripts() {
54 ?>
55 <script>
56 /*
57 * Initialize all galleries on page.
58 */
59 jQuery('.woocommerce-product-gallery').each(function () {
60 const that = this;
61 jQuery(this).trigger('wc-product-gallery-before-init', [this, wc_single_product_params]);
62 setTimeout(function () {
63 jQuery(that).wc_product_gallery(wc_single_product_params);
64 }, 1000);
65
66 jQuery(this).trigger('wc-product-gallery-after-init', [this, wc_single_product_params]);
67 });
68 <?php if ( function_exists( 'rtwpvg' ) ) { ?>
69 setTimeout(function () {
70 jQuery('.rtwpvg-wrapper, .rtwpvg-grid-wrapper').rtWpVGallery();
71 }, 1000);
72 <?php } ?>
73
74 jQuery(document).ready(function ($) {
75 setTimeout(function () {
76 const zoomIcon = $('.rtsb-product-images').attr('data-zoom-icon');
77 if (!zoomIcon) {
78 $('.rtsb-product-images')
79 .find('.woocommerce-product-gallery__trigger,.rtwpvg-trigger')
80 .remove();
81 }
82 $('.rtsb-product-images')
83 .find('.woocommerce-product-gallery__trigger,.rtwpvg-trigger')
84 .html(zoomIcon);
85 }, 50);
86 });
87 </script>
88 <?php
89 }
90
91 /**
92 * Widget Field.
93 *
94 * @param array $control Control.
95 *
96 * @return void
97 */
98 public function the_hooks( $control = [] ) {
99 if ( empty( $control ) ) {
100 return;
101 }
102 add_filter(
103 'woocommerce_product_thumbnails_columns',
104 function ( $col ) {
105 $col = 0;
106
107 return $col;
108 }
109 );
110 if ( empty( $control['show_zoom'] ) ) {
111 add_filter( 'rtwpvg_trigger_icon', '__return_false' );
112 }
113 if ( empty( $control['show_thumbnails'] ) ) {
114 add_filter( 'rtwpvg_show_product_thumbnail_slider', '__return_false' );
115 remove_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20 );
116 }
117 add_filter( 'rtwpvg_thumbnail_slider_js_options', [ $this, 'thumbnail_slider_js_options' ], 50 );
118 add_filter( 'rtwpvg_thumbnail_position', [ $this, 'thumbnail_position' ], 50 );
119 add_filter( 'rtwpvg_thumbnails_columns', [ $this, 'thumbnails_columns' ] );
120 add_filter( 'rtwpvg_sm_thumbnails_columns', [ $this, 'thumbnails_columns_sm' ] );
121 add_filter( 'rtwpvg_xs_thumbnails_columns', [ $this, 'thumbnails_columns_xs' ] );
122 // add_filter( 'rtwpvg_image_classes', [ $this, 'rtwpvg_image_classes' ], 15 );.
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
181 if ( ! function_exists( 'rtwpvg' ) || ! rtwpvg()->active_pro() || ! ( BuilderFns::is_product() || BuilderFns::is_quick_views_page() ) ) {
182 return $position;
183 }
184
185 $controllers = $this->get_settings_for_display();
186 $show_thumbnails = ! empty( $controllers['show_thumbnails'] ) ? $controllers['show_thumbnails'] : false;
187
188 if ( ! $show_thumbnails ) {
189 add_filter( 'rtwpvg_show_product_thumbnail_slider', '__return_false', 20 );
190 return 'bottom';
191 }
192
193 return ! empty( $controllers['image_layout'] ) ? $controllers['image_layout'] : 'bottom';
194 }
195
196 /**
197 * Render Function
198 *
199 * @return void
200 */
201 protected function render() {
202 global $product, $post;
203 $_product = $product;
204 $product = Fns::get_product();
205 $controllers = $this->get_settings_for_display();
206 if ( empty( $controllers['show_module_badges'] ) ) {
207 add_filter( 'rtsb/module/badges/show', '__return_false', 99 );
208 }
209
210 $this->theme_support();
211
212 $controllers['lightbox_icon'] = Fns::icons_manager( $controllers['lightbox_icon'] );
213 $data = [
214 'template' => 'elementor/single-product/product-images',
215 'controllers' => $controllers,
216 ];
217 $this->the_hooks( $controllers );
218
219 Fns::load_template( $data['template'], $data );
220
221 if ( $this->is_builder_mode() ) {
222 $this->init_scripts();
223 }
224
225 if ( empty( $controllers['show_module_badges'] ) ) {
226 remove_filter( 'rtsb/module/badges/show', '__return_false', 99 );
227 }
228
229 $this->theme_support( 'render_reset' );
230 $product = $_product; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
231 }
232 }
233