PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / trunk
ShopBuilder – WooCommerce Builder For Elementor vtrunk
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 / AdditionalQueryCustomLayout.php

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

239 lines 6.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * ProductsGrid class.
4 *
5 * @package RadiusTheme\SB
6 */
7
8 namespace RadiusTheme\SB\Abstracts;
9
10 use RadiusTheme\SB\Helpers\Fns;
11 use RadiusTheme\SB\Elementor\Render\Render;
12 use RadiusTheme\SB\Elementor\Widgets\Controls;
13 use RadiusTheme\SB\Controllers\Hooks\FilterHooks;
14 use RadiusTheme\SB\Traits\ActionBtnTraits;
15
16 // Do not allow directly accessing this file.
17
18 if ( ! defined( 'ABSPATH' ) ) {
19 exit( 'This script cannot be accessed directly.' );
20 }
21
22 /**
23 * ProductsGrid class.
24 */
25 abstract class AdditionalQueryCustomLayout extends ElementorWidgetBase {
26 /**
27 * Action Button Traits.
28 */
29 use ActionBtnTraits;
30
31 /**
32 * Construct function
33 *
34 * @param array $data default array.
35 * @param mixed $args default arg.
36 */
37 public function __construct( $data = [], $args = null ) {
38 $this->rtsb_base = $this->get_the_base();
39 parent::__construct( $data, $args );
40 $this->pro_tab = 'layout';
41 }
42 /**
43 * @return string
44 */
45 abstract protected function get_the_base();
46
47 /**
48 * Output the related products.
49 *
50 * @param array $args Provided arguments.
51 */
52 abstract public function get_the_products( $args = [] );
53
54 /**
55 * Widget Field
56 *
57 * @return array
58 */
59 public function widget_fields() {
60 return array_merge(
61 $this->layout_tab(),
62 $this->settings_tab(),
63 $this->style_tab()
64 );
65 }
66
67 /**
68 * Controls for layout tab
69 *
70 * @return array
71 */
72 protected function layout_tab() {
73 $fields = apply_filters(
74 'rtsb/elements/elementor/grid_layout_tab/' . $this->rtsb_base,
75 array_merge(
76 $this->widget_layout(),
77 $this->widget_query()
78 )
79 );
80
81 return $fields;
82 }
83
84 /**
85 * Controls for settings tab
86 *
87 * @return array
88 */
89 protected function settings_tab() {
90 $content_visibility = Controls\SettingsFields::content_visibility( $this );
91
92 $extra_controls['show_section_title'] = [
93 'type' => 'switch',
94 'label' => esc_html__( 'Show Section Title?', 'shopbuilder' ),
95 'description' => esc_html__( 'Switch on to show product title.', 'shopbuilder' ),
96 'label_on' => esc_html__( 'On', 'shopbuilder' ),
97 'label_off' => esc_html__( 'Off', 'shopbuilder' ),
98 'separator' => 'default',
99 ];
100
101 $content_visibility = Fns::insert_controls( 'show_title', $content_visibility, $extra_controls );
102
103 unset( $content_visibility['show_title']['separator'] );
104
105 $sections = array_merge(
106 $content_visibility,
107 Controls\SettingsFields::content_ordering( $this ),
108 Controls\SettingsFields::section_title( $this ),
109 Controls\SettingsFields::image( $this ),
110 Controls\SettingsFields::action_buttons( $this ),
111 Controls\SettingsFields::product_title( $this ),
112 Controls\SettingsFields::product_excerpt( $this ),
113 Controls\SettingsFields::badges( $this ),
114 $this->variation_swatch_conditionaly(),
115 Controls\SettingsFields::links( $this )
116 );
117 return apply_filters( 'rtsb/elements/elementor/product_custom_settings_tab', $sections, $this );
118 }
119 /**
120 * Controls for layout tab
121 *
122 * @return array
123 */
124 protected function widget_layout() {
125 return Controls\LayoutFields::grid_layout( $this );
126 }
127
128 /**
129 * Controls for layout tab
130 *
131 * @return array
132 */
133 public function variation_swatch_conditionaly() {
134 if ( ! function_exists( 'rtwpvsp' ) && ! rtsb()->has_pro() ) {
135 return [];
136 }
137 $swatches_controls = Controls\SettingsFields::variation_swatch( $this );
138 if ( ! empty( $swatches_controls['swatch_position'] ) ) {
139 $swatches_controls['swatch_position']['condition'] = [
140 'layout' => [ 'grid-layout1' ],
141 ];
142 }
143 return $swatches_controls;
144 }
145 /**
146 * Controls for layout tab
147 *
148 * @return array
149 */
150 protected function widget_query() {
151 $additional_query = Controls\LayoutFields::additional_query( $this );
152 $additional_query['posts_limit']['separator'] = 'default';
153 return $additional_query;
154 }
155
156 /**
157 * Controls for style tab
158 *
159 * @return array
160 */
161 protected function pagination_navigation() {
162 return Controls\StyleFields::pagination( $this );
163 }
164
165 /**
166 * Controls for style tab
167 *
168 * @return array
169 */
170 protected function style_tab() {
171 return apply_filters(
172 'rtsb/elementor/grid_style_tab',
173 array_merge(
174 Controls\StyleFields::color_scheme( $this ),
175 Controls\StyleFields::layout_design( $this ),
176 Controls\StyleFields::product_image( $this ),
177 Controls\StyleFields::section_title( $this ),
178 Controls\StyleFields::product_title( $this ),
179 Controls\StyleFields::short_description( $this ),
180 Controls\StyleFields::product_price( $this ),
181 Controls\StyleFields::product_categories( $this ),
182 Controls\StyleFields::product_rating( $this ),
183 Controls\StyleFields::product_add_to_cart( $this ),
184 Controls\StyleFields::product_wishlist( $this ),
185 Controls\StyleFields::product_quick_view( $this ),
186 Controls\StyleFields::product_compare( $this ),
187 Controls\StyleFields::action_buttons( $this ),
188 Controls\StyleFields::product_badges( $this ),
189 $this->pagination_navigation(),
190 Controls\StyleFields::hover_icon_button( $this )
191 ),
192 $this
193 );
194 }
195
196 /**
197 * Widget Field
198 *
199 * @return string
200 */
201 protected function render_template_file() {
202 return 'elementor/general/grid/';
203 }
204 /**
205 * Render Function
206 *
207 * @return void
208 */
209 protected function render() {
210 $settings = $this->get_settings_for_display();
211
212 $this->action_button_icon_modify();
213
214 $this->render_start();
215 $args = [
216 'posts_per_page' => $settings['posts_limit'],
217 'columns' => $settings['posts_limit'],
218 'orderby' => $settings['posts_order_by'],
219 'order' => $settings['posts_order'],
220 ];
221
222 $settings['query_products'] = $this->get_the_products( $args );
223
224 if ( empty( $settings['query_products'] ) ) {
225 return;
226 }
227
228 if ( $this->is_builder_mode() ) {
229 add_filter( 'wp_kses_allowed_html', [ FilterHooks::class, 'custom_wpkses_post_tags' ], 10, 2 );
230 }
231
232 // Call the template rendering method.
233 Fns::print_html( Render::instance()->setup_loop_for_product_view( $this->render_template_file(), $settings, $this ), true );
234
235 $this->action_button_icon_set_default();
236 $this->render_end();
237 }
238 }
239