| 1 |
<?php |
| 2 |
|
| 3 |
namespace UltimateStoreKit\Modules\FlorenceGrid\Widgets; |
| 4 |
|
| 5 |
use Elementor\Controls_Manager; |
| 6 |
use UltimateStoreKit\Base\Module_Base; |
| 7 |
use UltimateStoreKit\Traits\Global_Widget_Controls; |
| 8 |
use UltimateStoreKit\Traits\Global_Widget_Template; |
| 9 |
use UltimateStoreKit\Includes\Controls\GroupQuery\Group_Control_Query; |
| 10 |
use WP_Query; |
| 11 |
use UltimateStoreKit\Templates\USK_Florence_Grid_Template; |
| 12 |
|
| 13 |
if (!defined('ABSPATH')) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
// Exit if accessed directly |
| 18 |
|
| 19 |
class Florence_Grid extends Module_Base { |
| 20 |
use Global_Widget_Controls; |
| 21 |
use Global_Widget_Template; |
| 22 |
use Group_Control_Query; |
| 23 |
/** |
| 24 |
* @var \WP_Query |
| 25 |
*/ |
| 26 |
private $_query = null; |
| 27 |
public function get_name() { |
| 28 |
return 'usk-florence-grid'; |
| 29 |
} |
| 30 |
|
| 31 |
public function get_title() { |
| 32 |
return esc_html__('Florence Grid', 'ultimate-store-kit'); |
| 33 |
} |
| 34 |
|
| 35 |
public function get_icon() { |
| 36 |
return 'usk-widget-icon usk-icon-florence-grid'; |
| 37 |
} |
| 38 |
|
| 39 |
public function get_categories() { |
| 40 |
return ['ultimate-store-kit']; |
| 41 |
} |
| 42 |
|
| 43 |
public function get_keywords() { |
| 44 |
return ['product', 'product grid', 'table', 'wc', 'grid', 'list', 'florence grid']; |
| 45 |
} |
| 46 |
|
| 47 |
public function get_script_depends() { |
| 48 |
return ['usk-shiny-grid']; |
| 49 |
} |
| 50 |
|
| 51 |
public function get_style_depends() { |
| 52 |
if ($this->usk_is_edit_mode()) { |
| 53 |
return ['usk-all-styles']; |
| 54 |
} else { |
| 55 |
return ['usk-font', 'usk-florence-grid']; |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
public function get_custom_help_url() { |
| 60 |
return 'https://youtu.be/5UDpy3MqFbU'; |
| 61 |
} |
| 62 |
|
| 63 |
public function get_query() { |
| 64 |
return $this->_query; |
| 65 |
} |
| 66 |
|
| 67 |
public function has_widget_inner_wrapper(): bool { |
| 68 |
return !\Elementor\Plugin::$instance->experiments->is_feature_active('e_optimized_markup'); |
| 69 |
} |
| 70 |
protected function register_controls() { |
| 71 |
|
| 72 |
$this->start_controls_section( |
| 73 |
'section_woocommerce_layout', |
| 74 |
[ |
| 75 |
'label' => esc_html__('Layout', 'ultimate-store-kit'), |
| 76 |
] |
| 77 |
); |
| 78 |
|
| 79 |
$this->add_control( |
| 80 |
'layout_style', |
| 81 |
[ |
| 82 |
'label' => esc_html__('Style', 'ultimate-store-kit'), |
| 83 |
'type' => Controls_Manager::SELECT, |
| 84 |
'default' => 'grid', |
| 85 |
'options' => [ |
| 86 |
'grid' => esc_html__('Grid', 'ultimate-store-kit'), |
| 87 |
'list' => esc_html__('List', 'ultimate-store-kit'), |
| 88 |
], |
| 89 |
'condition' => [ |
| 90 |
'show_tab!' => 'yes' |
| 91 |
] |
| 92 |
] |
| 93 |
); |
| 94 |
$this->add_responsive_control( |
| 95 |
'columns', |
| 96 |
[ |
| 97 |
'label' => esc_html__('Columns', 'ultimate-store-kit'), |
| 98 |
'type' => Controls_Manager::SELECT, |
| 99 |
'default' => '3', |
| 100 |
'tablet_default' => '2', |
| 101 |
'mobile_default' => '1', |
| 102 |
'options' => [ |
| 103 |
'1' => '1', |
| 104 |
'2' => '2', |
| 105 |
'3' => '3', |
| 106 |
'4' => '4', |
| 107 |
'5' => '5', |
| 108 |
'6' => '6', |
| 109 |
], |
| 110 |
'condition' => [ |
| 111 |
'layout_style' => 'grid', |
| 112 |
'show_tab!' => 'yes' |
| 113 |
], |
| 114 |
'selectors' => [ |
| 115 |
'{{WRAPPER}} .usk-florence-grid .usk-grid.usk-grid-layout' => 'grid-template-columns: repeat({{VALUE}}, 1fr);', |
| 116 |
|
| 117 |
], |
| 118 |
'render_type' => 'template' |
| 119 |
] |
| 120 |
); |
| 121 |
|
| 122 |
$this->add_responsive_control( |
| 123 |
'columns_list', |
| 124 |
[ |
| 125 |
'label' => esc_html__('Columns', 'ultimate-store-kit'), |
| 126 |
'type' => Controls_Manager::SELECT, |
| 127 |
'default' => '2', |
| 128 |
'tablet_default' => '2', |
| 129 |
'mobile_default' => '1', |
| 130 |
'options' => [ |
| 131 |
'1' => '1', |
| 132 |
'2' => '2', |
| 133 |
'3' => '3', |
| 134 |
'4' => '4', |
| 135 |
'5' => '5', |
| 136 |
'6' => '6', |
| 137 |
], |
| 138 |
'condition' => [ |
| 139 |
'layout_style' => 'list' |
| 140 |
], |
| 141 |
'selectors' => [ |
| 142 |
'{{WRAPPER}} .usk-florence-grid .usk-grid.usk-list-layout' => 'grid-template-columns: repeat({{VALUE}}, 1fr);', |
| 143 |
|
| 144 |
], |
| 145 |
'render_type' => 'template' |
| 146 |
] |
| 147 |
); |
| 148 |
|
| 149 |
$this->add_responsive_control( |
| 150 |
'items_columns_gap', |
| 151 |
[ |
| 152 |
'label' => esc_html__('Column Gap', 'ultimate-store-kit'), |
| 153 |
'type' => Controls_Manager::SLIDER, |
| 154 |
'default' => [ |
| 155 |
'size' => 30, |
| 156 |
], |
| 157 |
'selectors' => [ |
| 158 |
'{{WRAPPER}} .usk-florence-grid .usk-grid' => 'grid-column-gap: {{SIZE}}px;', |
| 159 |
], |
| 160 |
] |
| 161 |
); |
| 162 |
|
| 163 |
$this->add_responsive_control( |
| 164 |
'items_row_gap', |
| 165 |
[ |
| 166 |
'label' => esc_html__('Row Gap', 'ultimate-store-kit'), |
| 167 |
'type' => Controls_Manager::SLIDER, |
| 168 |
'default' => [ |
| 169 |
'size' => 30, |
| 170 |
], |
| 171 |
'selectors' => [ |
| 172 |
'{{WRAPPER}} .usk-florence-grid .usk-grid' => 'grid-row-gap: {{SIZE}}px;', |
| 173 |
], |
| 174 |
] |
| 175 |
); |
| 176 |
|
| 177 |
$this->register_global_controls_grid_layout(); |
| 178 |
|
| 179 |
$this->add_control( |
| 180 |
'show_tab', |
| 181 |
[ |
| 182 |
'label' => esc_html__('Columns Filter', 'ultimate-store-kit'), |
| 183 |
'type' => Controls_Manager::SWITCHER, |
| 184 |
'separator' => 'before', |
| 185 |
'condition' => [ |
| 186 |
'layout_style' => 'grid' |
| 187 |
] |
| 188 |
] |
| 189 |
); |
| 190 |
$this->add_control( |
| 191 |
'filter_column_lists', |
| 192 |
[ |
| 193 |
'label' => __('Select Column Type', 'ultimate-store-kit'), |
| 194 |
'type' => Controls_Manager::SELECT2, |
| 195 |
'label_block' => true, |
| 196 |
'multiple' => true, |
| 197 |
'options' => [ |
| 198 |
'list-2' => __('List', 'ultimate-store-kit'), |
| 199 |
'grid-2' => __('Column 2', 'ultimate-store-kit'), |
| 200 |
'grid-3' => __('Column 3', 'ultimate-store-kit'), |
| 201 |
'grid-4' => __('Column 4', 'ultimate-store-kit'), |
| 202 |
'grid-5' => __('Column 5', 'ultimate-store-kit'), |
| 203 |
'grid-6' => __('Column 6', 'ultimate-store-kit'), |
| 204 |
|
| 205 |
], |
| 206 |
'condition' => [ |
| 207 |
'show_tab' => 'yes', |
| 208 |
'layout_style' => 'grid' |
| 209 |
], |
| 210 |
'default' => ['list-2', 'grid-2', 'grid-3', 'grid-4'], |
| 211 |
] |
| 212 |
); |
| 213 |
$this->add_control( |
| 214 |
'show_result_count', |
| 215 |
[ |
| 216 |
'label' => esc_html__('Result Count', 'ultimate-store-kit'), |
| 217 |
'type' => Controls_Manager::SWITCHER, |
| 218 |
'label_on' => esc_html__('Show', 'ultimate-store-kit'), |
| 219 |
'label_off' => esc_html__('Hide', 'ultimate-store-kit'), |
| 220 |
'return_value' => 'yes', |
| 221 |
'default' => 'yes', |
| 222 |
'condition' => [ |
| 223 |
'show_tab' => 'yes' |
| 224 |
] |
| 225 |
] |
| 226 |
); |
| 227 |
|
| 228 |
$this->add_control( |
| 229 |
'show_pagination', |
| 230 |
[ |
| 231 |
'label' => esc_html__('Pagination', 'ultimate-store-kit'), |
| 232 |
'type' => Controls_Manager::SWITCHER, |
| 233 |
'separator' => 'before' |
| 234 |
] |
| 235 |
); |
| 236 |
|
| 237 |
$this->end_controls_section(); |
| 238 |
$this->start_controls_section( |
| 239 |
'section_post_query_builder', |
| 240 |
[ |
| 241 |
'label' => __('Query', 'ultimate-store-kit'), |
| 242 |
'tab' => Controls_Manager::TAB_CONTENT, |
| 243 |
] |
| 244 |
); |
| 245 |
$this->register_query_builder_controls(); |
| 246 |
$this->register_controls_wc_additional(); |
| 247 |
$this->end_controls_section(); |
| 248 |
$this->register_global_controls_additional(); |
| 249 |
$this->register_global_controls_grid_columns(); |
| 250 |
$this->register_global_controls_result_count(); |
| 251 |
$this->register_global_controls_grid_items(); |
| 252 |
$this->register_global_controls_grid_image(); |
| 253 |
$this->register_global_controls_content(); |
| 254 |
$this->register_global_controls_title(); |
| 255 |
$this->register_global_controls_category(); |
| 256 |
$this->register_global_controls_excerpt(); |
| 257 |
$this->register_global_controls_price(); |
| 258 |
$this->register_global_controls_rating(); |
| 259 |
$this->register_global_controls_badge(); |
| 260 |
$this->register_global_controls_action_btn(); |
| 261 |
$this->register_global_controls_grid_pagination(); |
| 262 |
} |
| 263 |
|
| 264 |
public function render_header() { |
| 265 |
$settings = $this->get_settings_for_display(); |
| 266 |
$this->add_render_attribute('usk-florence-grid', 'class', 'usk-florence-grid usk-grid-carousel usk-css-grid', true); |
| 267 |
$this->add_render_attribute('usk-florence-grid', 'data-filter', [$settings['show_tab']]); |
| 268 |
?> |
| 269 |
<div class="ultimate-store-kit"> |
| 270 |
<div <?php $this->print_render_attribute_string('usk-florence-grid'); ?>> |
| 271 |
<?php $this->template_grid_columns(); ?> |
| 272 |
<?php |
| 273 |
} |
| 274 |
public function render_footer() { ?> |
| 275 |
</div> |
| 276 |
</div> |
| 277 |
<?php |
| 278 |
} |
| 279 |
protected function template_grid_columns() { |
| 280 |
$settings = $this->get_settings_for_display(); |
| 281 |
$this->query_product(); |
| 282 |
$wp_query = $this->get_query(); |
| 283 |
if (get_query_var('paged')) { |
| 284 |
$paged = get_query_var('paged'); |
| 285 |
} elseif (get_query_var('page')) { |
| 286 |
$paged = get_query_var('page'); |
| 287 |
} else { |
| 288 |
$paged = 1; |
| 289 |
} |
| 290 |
$args = array( |
| 291 |
'total' => $wp_query->found_posts, |
| 292 |
'per_page' => $settings['product_limit'], |
| 293 |
'current' => $paged, |
| 294 |
'orderedby' => $wp_query->get('orderby'), |
| 295 |
); |
| 296 |
if ($settings['show_tab'] == 'yes'): ?> |
| 297 |
<div class="usk-grid-header usk-visible@l"> |
| 298 |
<?php if (($settings['show_result_count'] == 'yes')): |
| 299 |
wc_get_template('loop/result-count.php', $args); |
| 300 |
endif; |
| 301 |
?> |
| 302 |
<?php $this->register_templates_grid_columns_markup($settings); ?> |
| 303 |
</div> |
| 304 |
<?php endif; |
| 305 |
} |
| 306 |
|
| 307 |
public function render_loop_item() { |
| 308 |
$settings = $this->get_settings_for_display(); |
| 309 |
$this->query_product(); |
| 310 |
$wp_query = $this->get_query(); |
| 311 |
if ($settings['layout_style'] === 'grid') { |
| 312 |
$this->add_render_attribute('usk-grid', 'class', ['usk-grid', 'usk-grid-layout']); |
| 313 |
} else { |
| 314 |
$this->add_render_attribute('usk-grid', 'class', ['usk-grid', 'usk-list-layout']); |
| 315 |
} |
| 316 |
if ($wp_query->have_posts()): ?> |
| 317 |
<div <?php $this->print_render_attribute_string('usk-grid'); ?>> |
| 318 |
<?php while ($wp_query->have_posts()): |
| 319 |
$wp_query->the_post(); |
| 320 |
global $product; |
| 321 |
$florence_grid_template = new USK_Florence_Grid_Template($settings, 'florence-grid'); |
| 322 |
$florence_grid_template->render_florence_grid_item($product, $settings); |
| 323 |
endwhile; ?> |
| 324 |
</div> |
| 325 |
<?php |
| 326 |
if ($settings['show_pagination']): |
| 327 |
ultimate_store_kit_post_pagination__new($wp_query); |
| 328 |
endif; |
| 329 |
wp_reset_postdata(); |
| 330 |
else: |
| 331 |
echo '<div class="usk-alert-warning">' . esc_html__('Ops! There no product to display.', 'ultimate-store-kit') . '</div>'; |
| 332 |
endif; |
| 333 |
} |
| 334 |
|
| 335 |
public function render() { |
| 336 |
$this->render_header(); |
| 337 |
$this->render_loop_item(); |
| 338 |
$this->render_footer(); |
| 339 |
} |
| 340 |
public function query_product() { |
| 341 |
$default = $this->getGroupControlQueryArgs(); |
| 342 |
$this->_query = $this->build_query_from_args($default); |
| 343 |
} |
| 344 |
} |
| 345 |
|