view-single-product.php
322 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Elementor; |
| 4 | |
| 5 | use ShopEngine\Widgets\Products; |
| 6 | |
| 7 | defined('ABSPATH') || exit; |
| 8 | |
| 9 | class ShopEngine_View_Single_Product extends \ShopEngine\Base\Widget { |
| 10 | |
| 11 | public function config() { |
| 12 | return new ShopEngine_View_Single_Product_Config(); |
| 13 | } |
| 14 | |
| 15 | protected function register_controls() { |
| 16 | $this->start_controls_section( |
| 17 | 'shopengine_settings_section', |
| 18 | [ |
| 19 | 'label' => esc_html__('Button', 'shopengine'), |
| 20 | 'tab' => Controls_Manager::TAB_STYLE, |
| 21 | ] |
| 22 | ); |
| 23 | |
| 24 | $this->add_control( |
| 25 | 'shopengine_button_title', |
| 26 | [ |
| 27 | 'label' => esc_html__('Button Title', 'shopengine'), |
| 28 | 'type' => Controls_Manager::TEXT, |
| 29 | 'default' => esc_html__('View Full Info', 'shopengine') |
| 30 | ] |
| 31 | ); |
| 32 | |
| 33 | $this->add_control( |
| 34 | 'shopengine_button_align', |
| 35 | [ |
| 36 | 'label' => esc_html__('Button Alignment', 'shopengine'), |
| 37 | 'type' => Controls_Manager::CHOOSE, |
| 38 | 'options' => [ |
| 39 | 'left' => [ |
| 40 | 'title' => esc_html__('Left', 'shopengine'), |
| 41 | 'icon' => 'eicon-text-align-left', |
| 42 | ], |
| 43 | 'center' => [ |
| 44 | 'title' => esc_html__('Center', 'shopengine'), |
| 45 | 'icon' => 'eicon-text-align-center', |
| 46 | ], |
| 47 | 'right' => [ |
| 48 | 'title' => esc_html__('Right', 'shopengine'), |
| 49 | 'icon' => 'eicon-text-align-right', |
| 50 | ], |
| 51 | ], |
| 52 | 'prefix_class' => 'elementor-align-', |
| 53 | 'selectors' => [ |
| 54 | '{{WRAPPER}} .shopengine-view-single-product .view-single-product' => 'text-align: {{VALUE}};', |
| 55 | '.rtl {{WRAPPER}}.elementor-align-right .shopengine-view-single-product .view-single-product' => 'text-align: left;', |
| 56 | '.rtl {{WRAPPER}}.elementor-align-left .shopengine-view-single-product .view-single-product' => 'text-align: right;', |
| 57 | ], |
| 58 | ] |
| 59 | ); |
| 60 | |
| 61 | $this->add_group_control( |
| 62 | Group_Control_Typography::get_type(), |
| 63 | [ |
| 64 | 'name' => 'shopengine_typography_primary', |
| 65 | 'label' => esc_html__('Typography', 'shopengine'), |
| 66 | 'exclude' => ['letter_spacing','font_style', 'text_style', 'text_decoration'], |
| 67 | 'fields_options' => [ |
| 68 | 'typography' => [ |
| 69 | 'default' => 'custom', |
| 70 | ], |
| 71 | 'font_weight' => [ |
| 72 | 'default' => '600', |
| 73 | ], |
| 74 | 'font_size' => [ |
| 75 | 'label' => esc_html__('Font Size (px)', 'shopengine'), |
| 76 | 'size_units' => ['px'], |
| 77 | 'default' => [ |
| 78 | 'size' => '15', |
| 79 | 'unit' => 'px', |
| 80 | ], |
| 81 | ], |
| 82 | 'line_height' => [ |
| 83 | 'size_units' => ['px'], |
| 84 | 'label' => 'Line Height (px)', |
| 85 | 'responsive' => false, |
| 86 | ] |
| 87 | ], |
| 88 | 'selector' => '{{WRAPPER}} .shopengine-view-single-product .button', |
| 89 | ] |
| 90 | ); |
| 91 | |
| 92 | $this->start_controls_tabs('shopengine_button_tabs_style'); |
| 93 | |
| 94 | $this->start_controls_tab( |
| 95 | 'shopengine_button_tabnormal', |
| 96 | [ |
| 97 | 'label' => esc_html__('Normal', 'shopengine'), |
| 98 | ] |
| 99 | ); |
| 100 | |
| 101 | $this->add_control( |
| 102 | 'shopengine_button_text_color', |
| 103 | [ |
| 104 | 'label' => esc_html__('Text Color', 'shopengine'), |
| 105 | 'type' => Controls_Manager::COLOR, |
| 106 | 'alpha' => false, |
| 107 | 'default' => '#ffffff', |
| 108 | 'selectors' => [ |
| 109 | '{{WRAPPER}} .shopengine-view-single-product .button' => 'color: {{VALUE}} !important;', |
| 110 | ], |
| 111 | ] |
| 112 | ); |
| 113 | |
| 114 | $this->add_control( |
| 115 | 'shopengine_button_text_bg_color', |
| 116 | [ |
| 117 | 'label' => esc_html__('Background Color', 'shopengine'), |
| 118 | 'type' => Controls_Manager::COLOR, |
| 119 | 'alpha' => false, |
| 120 | 'default' => '#101010', |
| 121 | 'selectors' => [ |
| 122 | '{{WRAPPER}} .shopengine-view-single-product .button' => 'background-color: {{VALUE}} !important;', |
| 123 | ], |
| 124 | ] |
| 125 | ); |
| 126 | |
| 127 | |
| 128 | $this->add_group_control( |
| 129 | Group_Control_Border::get_type(), |
| 130 | [ |
| 131 | 'name' => 'shopengine_input_border', |
| 132 | 'label' => esc_html__('Border', 'shopengine'), |
| 133 | 'fields_options' => [ |
| 134 | 'border' => [ |
| 135 | 'default' => 'solid', |
| 136 | 'responsive' => false, |
| 137 | 'selectors' => [ |
| 138 | '{{WRAPPER}} .shopengine-view-single-product .button' => 'border-style: {{VALUE}} !important;', |
| 139 | ], |
| 140 | ], |
| 141 | |
| 142 | 'width' => [ |
| 143 | 'label' => esc_html__('Border Width', 'shopengine'), |
| 144 | 'default' => [ |
| 145 | 'top' => '1', |
| 146 | 'right' => '1', |
| 147 | 'bottom' => '1', |
| 148 | 'left' => '1', |
| 149 | 'unit' => 'px', |
| 150 | ], |
| 151 | 'selectors' => [ |
| 152 | '{{WRAPPER}} .shopengine-view-single-product .button' => 'border-width: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important;', |
| 153 | '.rtl {{WRAPPER}} .shopengine-view-single-product .button' => 'border-width: {{TOP}}{{UNIT}} {{LEFT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{RIGHT}}{{UNIT}} !important;', |
| 154 | ], |
| 155 | 'responsive' => false, |
| 156 | ], |
| 157 | |
| 158 | 'color' => [ |
| 159 | 'label' => esc_html__('Border Color', 'shopengine'), |
| 160 | 'alpha' => false, |
| 161 | 'responsive' => false, |
| 162 | 'selectors' => [ |
| 163 | '{{WRAPPER}} .shopengine-view-single-product .button' => 'border-color: {{VALUE}} !important;', |
| 164 | ], |
| 165 | ], |
| 166 | |
| 167 | ], |
| 168 | ] |
| 169 | ); |
| 170 | |
| 171 | $this->end_controls_tab(); |
| 172 | |
| 173 | $this->start_controls_tab( |
| 174 | 'shopengine_button_tab_button_hover', |
| 175 | [ |
| 176 | 'label' => esc_html__('Hover', 'shopengine'), |
| 177 | ] |
| 178 | ); |
| 179 | |
| 180 | $this->add_control( |
| 181 | 'shopengine_button_hover_color', |
| 182 | [ |
| 183 | 'label' => esc_html__('Text Color', 'shopengine'), |
| 184 | 'type' => Controls_Manager::COLOR, |
| 185 | 'default' => '#ffffff', |
| 186 | 'alpha' => false, |
| 187 | 'selectors' => [ |
| 188 | '{{WRAPPER}} .shopengine-view-single-product .button:hover' => 'color: {{VALUE}} !important;', |
| 189 | ], |
| 190 | ] |
| 191 | ); |
| 192 | |
| 193 | |
| 194 | $this->add_control( |
| 195 | 'shopengine_button_hover_bg_color', |
| 196 | [ |
| 197 | 'label' => esc_html__('Background Color', 'shopengine'), |
| 198 | 'type' => Controls_Manager::COLOR, |
| 199 | 'default' => '#000000', |
| 200 | 'alpha' => false, |
| 201 | 'selectors' => [ |
| 202 | '{{WRAPPER}} .shopengine-view-single-product .button:hover' => 'background-color: {{VALUE}} !important;', |
| 203 | ], |
| 204 | ] |
| 205 | ); |
| 206 | |
| 207 | |
| 208 | $this->add_group_control( |
| 209 | Group_Control_Border::get_type(), |
| 210 | [ |
| 211 | 'name' => 'shopengine_input_border_hover', |
| 212 | 'label' => esc_html__('Border', 'shopengine'), |
| 213 | 'fields_options' => [ |
| 214 | 'border' => [ |
| 215 | 'default' => 'solid', |
| 216 | 'responsive' => false, |
| 217 | 'selectors' => [ |
| 218 | '{{WRAPPER}} .shopengine-view-single-product .button:hover' => 'border-style: {{VALUE}} !important;', |
| 219 | ], |
| 220 | ], |
| 221 | |
| 222 | 'width' => [ |
| 223 | 'label' => esc_html__('Border Width', 'shopengine'), |
| 224 | 'default' => [ |
| 225 | 'top' => '1', |
| 226 | 'right' => '1', |
| 227 | 'bottom' => '1', |
| 228 | 'left' => '1', |
| 229 | 'unit' => 'px', |
| 230 | ], |
| 231 | 'selectors' => [ |
| 232 | '{{WRAPPER}} .shopengine-view-single-product .button:hover' => 'border-width: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important;', |
| 233 | '.rtl {{WRAPPER}} .shopengine-view-single-product .button:hover' => 'border-width: {{TOP}}{{UNIT}} {{LEFT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{RIGHT}}{{UNIT}} !important;', |
| 234 | ], |
| 235 | 'responsive' => false, |
| 236 | ], |
| 237 | |
| 238 | 'color' => [ |
| 239 | 'label' => esc_html__('Border Color', 'shopengine'), |
| 240 | 'alpha' => false, |
| 241 | 'responsive' => false, |
| 242 | 'selectors' => [ |
| 243 | '{{WRAPPER}} .shopengine-view-single-product .button:hover' => 'border-color: {{VALUE}} !important;', |
| 244 | ], |
| 245 | ], |
| 246 | |
| 247 | ], |
| 248 | ] |
| 249 | ); |
| 250 | |
| 251 | $this->end_controls_tab(); |
| 252 | $this->end_controls_tabs(); |
| 253 | |
| 254 | $this->add_control( |
| 255 | 'shopengine_button_border_radius', |
| 256 | [ |
| 257 | 'label' => esc_html__('Border Radius', 'shopengine'), |
| 258 | 'type' => Controls_Manager::DIMENSIONS, |
| 259 | 'size_units' => ['px'], |
| 260 | 'default' => [ |
| 261 | 'unit' => 'px', |
| 262 | 'top' => 3, |
| 263 | 'right' => 3, |
| 264 | 'bottom' => 3, |
| 265 | 'left' => 3, |
| 266 | 'isLinked' => true |
| 267 | ], |
| 268 | 'separator' => 'before', |
| 269 | 'selectors' => [ |
| 270 | '{{WRAPPER}} .shopengine-view-single-product .button' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important;', |
| 271 | '.rtl {{WRAPPER}} .shopengine-view-single-product .button' => 'border-radius: {{TOP}}{{UNIT}} {{LEFT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{RIGHT}}{{UNIT}} !important;', |
| 272 | ], |
| 273 | ] |
| 274 | ); |
| 275 | |
| 276 | $this->add_control( |
| 277 | 'shopengine_button_text_padding', |
| 278 | [ |
| 279 | 'label' => esc_html__('Padding', 'shopengine'), |
| 280 | 'type' => Controls_Manager::DIMENSIONS, |
| 281 | 'size_units' => ['px'], |
| 282 | 'default' => [ |
| 283 | 'top' => '15', |
| 284 | 'right' => '20', |
| 285 | 'bottom' => '16', |
| 286 | 'left' => '20', |
| 287 | 'unit' => 'px', |
| 288 | 'isLinked' => false, |
| 289 | ], |
| 290 | 'selectors' => [ |
| 291 | '{{WRAPPER}} .shopengine-view-single-product .button' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 292 | '.rtl {{WRAPPER}} .shopengine-view-single-product .button' => 'padding: {{TOP}}{{UNIT}} {{LEFT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{RIGHT}}{{UNIT}};', |
| 293 | ], |
| 294 | ] |
| 295 | ); |
| 296 | |
| 297 | $this->add_group_control( |
| 298 | Group_Control_Box_Shadow::get_type(), |
| 299 | [ |
| 300 | 'name' => 'shopengine_button_box_shadow_group', |
| 301 | 'selector' => '{{WRAPPER}} .shopengine-view-single-product .button', |
| 302 | ] |
| 303 | ); |
| 304 | |
| 305 | $this->end_controls_section(); |
| 306 | } |
| 307 | |
| 308 | protected function screen() { |
| 309 | $settings = $this->get_settings_for_display(); |
| 310 | $product = Products::instance()->get_product(get_post_type()); |
| 311 | ?> |
| 312 | <div class="shopengine-view-single-product"> |
| 313 | <p class="view-single-product"> |
| 314 | <a title="<?php esc_html_e('View Product Full Details','shopengine')?>" class="button" href="<?php echo esc_url($product->get_permalink()); ?>"> |
| 315 | <?php echo esc_html($settings['shopengine_button_title']);?> |
| 316 | </a> |
| 317 | </p> |
| 318 | </div> |
| 319 | <?php |
| 320 | } |
| 321 | } |
| 322 |