product-stock.php
276 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Elementor; |
| 4 | |
| 5 | use ShopEngine\Widgets\Products; |
| 6 | |
| 7 | defined('ABSPATH') || exit; |
| 8 | |
| 9 | class ShopEngine_Product_Stock extends \ShopEngine\Base\Widget |
| 10 | { |
| 11 | |
| 12 | public function config() { |
| 13 | return new ShopEngine_Product_Stock_Config(); |
| 14 | } |
| 15 | |
| 16 | protected function stock_types() { |
| 17 | return [ |
| 18 | 'in_stock' => esc_html__('In Stock', 'shopengine'), |
| 19 | 'out_of_stock' => esc_html__('Out of Stock', 'shopengine'), |
| 20 | 'available_on_backorder' => esc_html__('Available on Backorder', 'shopengine'), |
| 21 | ]; |
| 22 | } |
| 23 | |
| 24 | |
| 25 | protected function register_controls() { |
| 26 | /** |
| 27 | * Section: Product Stock |
| 28 | */ |
| 29 | $this->start_controls_section( |
| 30 | 'shopengine_pstock_settings', |
| 31 | [ |
| 32 | 'label' => esc_html__('Product Stock', 'shopengine'), |
| 33 | 'tab' => Controls_Manager::TAB_CONTENT, |
| 34 | ] |
| 35 | ); |
| 36 | $this->add_control( |
| 37 | 'shopengine_pstock_stock_type', |
| 38 | [ |
| 39 | 'label' => esc_html__('Type', 'shopengine'), |
| 40 | 'type' => Controls_Manager::SELECT, |
| 41 | 'options' => $this->stock_types(), |
| 42 | 'default' => 'in_stock', |
| 43 | ] |
| 44 | ); |
| 45 | |
| 46 | $this->add_control( |
| 47 | 'shopengine_pstock_stock_warning', |
| 48 | [ |
| 49 | 'type' => Controls_Manager::RAW_HTML, |
| 50 | 'raw' => esc_html__('Note: This is just a demonstration of how a different stock will look in the frontend.', 'shopengine'), |
| 51 | 'content_classes' => 'elementor-panel-alert elementor-panel-alert-info', |
| 52 | 'separator' => 'after', |
| 53 | ] |
| 54 | ); |
| 55 | |
| 56 | $this->add_responsive_control( |
| 57 | 'shopengine_pstock_alignment', |
| 58 | \ShopEngine\Utils\Controls_Helper::get_alignment_conf( |
| 59 | 'shopengine-stock-align-', |
| 60 | '', |
| 61 | [ |
| 62 | '{{WRAPPER}} .shopengine-product-stock' => 'text-align: {{VALUE}};', |
| 63 | '.rtl {{WRAPPER}}.shopengine-stock-align-left .shopengine-product-stock' => 'text-align:right;', |
| 64 | '.rtl {{WRAPPER}}.shopengine-stock-align-right .shopengine-product-stock' => 'text-align:left;', |
| 65 | ] |
| 66 | ) |
| 67 | ); |
| 68 | |
| 69 | $this->add_group_control( |
| 70 | Group_Control_Typography::get_type(), |
| 71 | array( |
| 72 | 'name' => 'shopengine_pstock_typography', |
| 73 | 'label' => esc_html__('Typography', 'shopengine'), |
| 74 | 'selector' => '{{WRAPPER}} .shopengine-product-stock p', |
| 75 | 'exclude' => ['text_decoration', 'letter_spacing'], |
| 76 | 'fields_options' => [ |
| 77 | 'typography' => [ |
| 78 | 'default' => 'custom', |
| 79 | ], |
| 80 | 'font_family' => [ |
| 81 | 'default' => '', |
| 82 | ], |
| 83 | 'font_weight' => [ |
| 84 | 'default' => '500', |
| 85 | ], |
| 86 | 'font_size' => [ |
| 87 | 'label' => esc_html__('Font Size (px)', 'shopengine'), |
| 88 | 'default' => [ |
| 89 | 'size' => '14', |
| 90 | 'unit' => 'px' |
| 91 | ], |
| 92 | 'size_units' => ['px'], |
| 93 | ], |
| 94 | 'text_transform' => [ |
| 95 | 'default' => 'uppercase', |
| 96 | ], |
| 97 | 'line_height' => [ |
| 98 | 'label' => esc_html__('Line Height (px)', 'shopengine'), |
| 99 | 'default' => [ |
| 100 | 'size' => '17', |
| 101 | 'unit' => 'px', |
| 102 | ], |
| 103 | 'size_units' => ['px'], |
| 104 | 'tablet_default' => [ |
| 105 | 'unit' => 'px', |
| 106 | ], |
| 107 | 'mobile_default' => [ |
| 108 | 'unit' => 'px', |
| 109 | ], |
| 110 | ], |
| 111 | ], |
| 112 | ) |
| 113 | ); |
| 114 | |
| 115 | $this->end_controls_section(); |
| 116 | |
| 117 | |
| 118 | /** |
| 119 | * Section: In Stock |
| 120 | */ |
| 121 | $this->start_controls_section( |
| 122 | 'shopengine_pstock_in_stock_section', |
| 123 | array( |
| 124 | 'label' => esc_html__('In Stock', 'shopengine'), |
| 125 | 'tab' => Controls_Manager::TAB_CONTENT, |
| 126 | ) |
| 127 | ); |
| 128 | |
| 129 | $this->add_control( |
| 130 | 'shopengine_pstock_in_stock_icon', |
| 131 | [ |
| 132 | 'label' => esc_html__('Icon', 'shopengine'), |
| 133 | 'type' => Controls_Manager::ICONS, |
| 134 | 'default' => [ |
| 135 | 'value' => 'fas fa-check-circle', |
| 136 | 'library' => 'fa-solid', |
| 137 | ], |
| 138 | ] |
| 139 | ); |
| 140 | |
| 141 | $this->add_control( |
| 142 | 'shopengine_pstock_in_stock_color', |
| 143 | [ |
| 144 | 'label' => esc_html__('Color', 'shopengine'), |
| 145 | 'type' => Controls_Manager::COLOR, |
| 146 | 'default' => '#169543', |
| 147 | 'selectors' => [ |
| 148 | '{{WRAPPER}} .shopengine-product-stock .in-stock' => 'color: {{VALUE}};', |
| 149 | '{{WRAPPER}} .shopengine-product-stock .in-stock svg' => 'fill: {{VALUE}};', |
| 150 | ], |
| 151 | ] |
| 152 | ); |
| 153 | |
| 154 | $this->end_controls_section(); |
| 155 | |
| 156 | |
| 157 | /** |
| 158 | * Section: Out of Stock |
| 159 | */ |
| 160 | $this->start_controls_section( |
| 161 | 'shopengine_pstock_out_of_stock_section', |
| 162 | array( |
| 163 | 'label' => esc_html__('Out of Stock', 'shopengine'), |
| 164 | 'tab' => Controls_Manager::TAB_CONTENT, |
| 165 | ) |
| 166 | ); |
| 167 | $this->add_control( |
| 168 | 'shopengine_pstock_out_of_stock_icon', |
| 169 | [ |
| 170 | 'label' => esc_html__('Icon', 'shopengine'), |
| 171 | 'type' => Controls_Manager::ICONS, |
| 172 | 'default' => [ |
| 173 | 'value' => 'fas fa-times-circle', |
| 174 | 'library' => 'fa-solid', |
| 175 | ], |
| 176 | ] |
| 177 | ); |
| 178 | |
| 179 | $this->add_control( |
| 180 | 'shopengine_pstock_out_of_stock_color', |
| 181 | [ |
| 182 | 'label' => esc_html__('Color', 'shopengine'), |
| 183 | 'type' => Controls_Manager::COLOR, |
| 184 | 'default' => '#d9534f', |
| 185 | 'selectors' => [ |
| 186 | '{{WRAPPER}} .shopengine-product-stock .out-of-stock' => 'color: {{VALUE}};', |
| 187 | '{{WRAPPER}} .shopengine-product-stock .out-of-stock svg' => 'fill: {{VALUE}};', |
| 188 | ], |
| 189 | ] |
| 190 | ); |
| 191 | |
| 192 | $this->end_controls_section(); |
| 193 | |
| 194 | |
| 195 | /** |
| 196 | * Section: Available on Backorder |
| 197 | */ |
| 198 | $this->start_controls_section( |
| 199 | 'sshopengine_pstock_available_on_backorder_section', |
| 200 | array( |
| 201 | 'label' => esc_html__('Available on Backorder', 'shopengine'), |
| 202 | 'tab' => Controls_Manager::TAB_CONTENT, |
| 203 | ) |
| 204 | ); |
| 205 | $this->add_control( |
| 206 | 'shopengine_pstock_available_on_backorder_icon', |
| 207 | [ |
| 208 | 'label' => esc_html__('Icon', 'shopengine'), |
| 209 | 'type' => Controls_Manager::ICONS, |
| 210 | 'default' => [ |
| 211 | 'value' => 'fas fa-shopping-cart', |
| 212 | 'library' => 'fa-solid', |
| 213 | ], |
| 214 | ] |
| 215 | ); |
| 216 | |
| 217 | $this->add_control( |
| 218 | 'shopengine_pstock_available_on_backorder_color', |
| 219 | [ |
| 220 | 'label' => esc_html__('Color', 'shopengine'), |
| 221 | 'type' => Controls_Manager::COLOR, |
| 222 | 'default' => '#ee9800', |
| 223 | 'selectors' => [ |
| 224 | '{{WRAPPER}} .shopengine-product-stock .available-on-backorder' => 'color: {{VALUE}};', |
| 225 | '{{WRAPPER}} .shopengine-product-stock .available-on-backorder svg' => 'fill: {{VALUE}};', |
| 226 | ], |
| 227 | ] |
| 228 | ); |
| 229 | |
| 230 | $this->end_controls_section(); |
| 231 | } |
| 232 | |
| 233 | public function _get_product($p_type) { |
| 234 | |
| 235 | global $product; |
| 236 | |
| 237 | if($p_type == 'product') { |
| 238 | $product = wc_get_product(); |
| 239 | } else { |
| 240 | $product = ''; |
| 241 | } |
| 242 | |
| 243 | return $product; |
| 244 | } |
| 245 | |
| 246 | public function _get_icon($icon) { |
| 247 | |
| 248 | if($icon) { |
| 249 | ob_start(); |
| 250 | \Elementor\Icons_Manager::render_icon($icon, ['aria-hidden' => 'true']); |
| 251 | $icon = ob_get_clean(); |
| 252 | } else { |
| 253 | $icon = ''; |
| 254 | } |
| 255 | |
| 256 | return $icon; |
| 257 | } |
| 258 | |
| 259 | /** |
| 260 | * Render widget output on the frontend. |
| 261 | * |
| 262 | * Written in PHP and used to generate the final HTML. |
| 263 | * |
| 264 | * @since 1.0.0 |
| 265 | * @access protected |
| 266 | */ |
| 267 | protected function screen() { |
| 268 | |
| 269 | $settings = $this->get_settings_for_display(); |
| 270 | |
| 271 | $tpl = Products::instance()->get_widget_template($this->get_name()); |
| 272 | |
| 273 | include $tpl; |
| 274 | } |
| 275 | } |
| 276 |