PluginProbe
WPPizza – A Restaurant Plugin / 3.20
WPPizza – A Restaurant Plugin v3.20
trunk 2.16.11.28 3.19 3.19.1 3.19.2 3.19.3 3.19.4 3.19.5 3.19.6 3.19.7 3.19.7.1 3.19.7.2 3.19.7.3 3.19.7.4 3.19.8 3.19.8.1 3.19.8.2 3.19.8.3 3.19.9 3.20 3.20.1
wppizza / classes / modules / mod.order_settings.order_update.php

mod.order_settings.order_update.php in WPPizza – A Restaurant Plugin 3.20, at classes/modules/mod.order_settings.order_update.php

466 lines 20.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WPPIZZA_MODULE_ORDER_SETTINGS_ORDER_UPDATE Class
4 *
5 * @package WPPIZZA
6 * @subpackage WPPIZZA_MODULE_ORDER_SETTINGS_ORDER_UPDATE
7 * @copyright Copyright (c) 2015, Oliver Bach
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 3.0
10 *
11 */
12 if ( ! defined( 'ABSPATH' ) ) exit;/*Exit if accessed directly*/
13
14
15 /************************************************************************************************************************
16 *
17 *
18 *
19 *
20 *
21 *
22 ************************************************************************************************************************/
23 class WPPIZZA_MODULE_ORDER_SETTINGS_ORDER_UPDATE{
24
25 private $settings_page = 'order_settings';/* which admin subpage (identified there by this->class_key) are we adding this to */
26
27 private $section_key = 'order_update';/* must be unique */
28
29
30 function __construct() {
31 /**********************************************************
32 [add settings to admin]
33 ***********************************************************/
34 if(is_admin()){
35 /* add admin options settings page*/
36 add_filter('wppizza_filter_settings_sections_'.$this->settings_page.'', array($this, 'admin_options_settings'), 60, 5);
37 /* add admin options settings page fields */
38 add_action('wppizza_admin_settings_section_fields_'.$this->settings_page.'', array($this, 'admin_options_fields_settings'), 10, 5);
39 /**add default options **/
40 add_filter('wppizza_filter_setup_default_options', array( $this, 'options_default'));
41 /**validate options**/
42 add_filter('wppizza_filter_options_validate', array( $this, 'options_validate'), 10, 2 );
43 }
44 /****************************************************
45 * allow for cart increase via input boxes
46 ****************************************************/
47 add_filter('wppizza_filter_order_item_header_markup', array( $this, 'cart_increase_header'), 10, 8 );
48 add_filter('wppizza_filter_order_item_columns', array( $this, 'cart_increase'), 10, 8 );
49 /****************************************************
50 * output spinner input order page: add to pages if/as enabled
51 *****************************************************/
52 add_filter('wppizza_filter_order_item_header_markup', array( $this, 'wppizza_order_form_item_quantity_update_header'),100, 3);/** replace header th with update th **/
53 add_filter('wppizza_filter_order_item_columns', array( $this, 'wppizza_order_form_item_quantity_input'),100, 8);/** replace quantity column with input**/
54 }
55
56 /*******************************************************************************************************************************************************
57 *
58 *
59 *
60 * [frontend filters]
61 *
62 *
63 *
64 ********************************************************************************************************************************************************/
65 /**********************************************************************************
66 * header columns pages (order, confirmation , thank you, user order history )
67 **********************************************************************************/
68 function cart_increase_header($markup_header, $txt, $type){
69
70 global $wppizza_options;
71 // 'gettotals' used in minicart full order info
72 if(($type == 'cart' || $type == 'gettotals') ){//&& !empty($wppizza_options['order_settings']['cart_increase'])
73
74 if($wppizza_options['order_settings']['menu_item_remove_button'] == 'left'){
75 /* just to eliminate some possible undefined notices */
76 if(!isset($markup_header['thead_th_quantity'])){
77 $markup_header['thead_th_quantity']='';
78 }
79 $markup_header['thead_th_quantity'] = '<th class="'.WPPIZZA_PREFIX.'-item-delete-th"></th>' . $markup_header['thead_th_quantity'];
80 }
81
82 /* add empty header dummy cell */
83 if($wppizza_options['order_settings']['menu_item_remove_button'] == 'right'){
84 $markup_header['item_th_delete']= '<th class="'.WPPIZZA_PREFIX.'-item-delete-th"></th>';
85 }
86 }
87
88 return $markup_header;
89 }
90
91 function cart_increase($menu_item_columns, $key , $item, $items, $item_count, $order, $txt, $type){
92 global $wppizza_options;
93 if($type == 'cart' || $type == 'gettotals'){ // 'gettotals' used in minicart full order info
94 /**
95 add quantity as imputs
96 **/
97 if(!empty($wppizza_options['order_settings']['cart_increase'])){
98 $menu_item_columns['item_td_quantity'] = '';
99
100 /** add delete button left **/
101 if($wppizza_options['order_settings']['menu_item_remove_button'] == 'left'){
102 $menu_item_columns['item_td_quantity'] .= '<td class="'.WPPIZZA_PREFIX.'-item-delete">';
103 $menu_item_columns['item_td_quantity'] .= '<input type="button" id="'.WPPIZZA_PREFIX.'-cart-'.$key.'" class="'.WPPIZZA_PREFIX.'-delete-from-cart" title="'.$txt['remove_from_cart'].'" value="x" />';
104 $menu_item_columns['item_td_quantity'] .= '</td>';
105 }
106
107 /* quanity (input/spinner) or plain */
108 $menu_item_columns['item_td_quantity'] .= '<td class="'.WPPIZZA_PREFIX.'-item-quantity">';
109 if($type == 'cart'){//spinner in cart only. there's simply not enough space in minicart details
110 $menu_item_columns['item_td_quantity'] .= '<input type="number" size="3" step="1" min="0" autocomplete="off" onmousewheel id="'.WPPIZZA_PREFIX.'-cart-modify-'.$key.'" class="'.WPPIZZA_PREFIX.'-cart-mod" name="'.WPPIZZA_PREFIX.'-cart-mod-'.$key.'" value="'.$item['quantity'].'" />';
111 }else{
112 //minicart. spinner specifically enabled
113 if(!empty($wppizza_options['order_settings']['cart_increase_minicart'])){
114 $menu_item_columns['item_td_quantity'] .= '<input type="number" size="3" step="1" min="0" autocomplete="off" onmousewheel id="'.WPPIZZA_PREFIX.'-minicart-modify-'.$key.'" class="'.WPPIZZA_PREFIX.'-cart-mod" name="'.WPPIZZA_PREFIX.'-cart-mod-'.$key.'" value="'.$item['quantity'].'" />';
115 }else{
116 $menu_item_columns['item_td_quantity'] .= $item['quantity'];
117 }
118 }
119 $menu_item_columns['item_td_quantity'] .= '</td>';
120
121
122 /** add delete button right **/
123 if($wppizza_options['order_settings']['menu_item_remove_button'] == 'right'){
124 $menu_item_columns['item_td_delete'] = '';
125 $menu_item_columns['item_td_delete'] .= '<td class="'.WPPIZZA_PREFIX.'-item-delete">';
126 $menu_item_columns['item_td_delete'] .= '<input type="button" id="'.WPPIZZA_PREFIX.'-cart-'.$key.'" class="'.WPPIZZA_PREFIX.'-delete-from-cart" title="'.$txt['remove_from_cart'].'" value="x" />';
127 $menu_item_columns['item_td_delete'] .= '</td>';
128 }
129
130 }else{
131 /** append [x] delete before unless spicifically set off too **/
132 $menu_item_columns['item_td_quantity'] = '';
133
134 /** add delete button left **/
135 if($wppizza_options['order_settings']['menu_item_remove_button'] == 'left'){
136 $menu_item_columns['item_td_quantity'] .= '<td class="'.WPPIZZA_PREFIX.'-item-delete">';
137 $menu_item_columns['item_td_quantity'] .= '<input type="button" id="'.WPPIZZA_PREFIX.'-cart-'.$key.'" class="'.WPPIZZA_PREFIX.'-delete-from-cart" title="'.$txt['remove_from_cart'].'" value="x" />';
138 $menu_item_columns['item_td_quantity'] .= '</td>';
139 }
140
141 /* plain quanity */
142 $menu_item_columns['item_td_quantity'] .= '<td class="'.WPPIZZA_PREFIX.'-item-quantity">';
143 $menu_item_columns['item_td_quantity'] .= ''.$item['quantity'].'';
144 $menu_item_columns['item_td_quantity'] .= '</td>';
145
146
147 /** add delete button right **/
148 if($wppizza_options['order_settings']['menu_item_remove_button'] == 'right'){
149 $menu_item_columns['item_td_delete'] = '';
150 $menu_item_columns['item_td_delete'] .= '<td class="'.WPPIZZA_PREFIX.'-item-delete">';
151 $menu_item_columns['item_td_delete'] .= '<input type="button" id="'.WPPIZZA_PREFIX.'-cart-'.$key.'" class="'.WPPIZZA_PREFIX.'-delete-from-cart" title="'.$txt['remove_from_cart'].'" value="x" />';
152 $menu_item_columns['item_td_delete'] .= '</td>';
153 }
154 }
155 }
156 return $menu_item_columns;
157 }
158
159 /**********************************************************************************
160 * header columns pages (order, confirmation , thank you, user order history )
161 **********************************************************************************/
162 function wppizza_order_form_item_quantity_update_header($markup_header, $txt, $type){
163 global $wppizza_options;
164 /* skip if not enabled and only on orderpage*/
165 if($type!='orderpage'){
166 return $markup_header;
167 }
168
169 /* replace quantity header (diffenet classname) and adding empty delete th too */
170 if(!empty($wppizza_options['order_settings']['order_page_quantity_change'])){
171 $markup_header['thead_th_quantity'] = '<th class="'.WPPIZZA_PREFIX.'-item-update-th">'.$txt['itemised_label_quantity'].'</th>';/* table cell */
172 }else{
173
174 /*
175 splice delete button th before (non-editable) quantity th if set to left
176 and no quantity input
177 */
178 if($wppizza_options['order_settings']['menu_item_remove_button'] == 'left'){
179 $splice['thead_th_delete'] = '<th class="'.WPPIZZA_PREFIX.'-item-delete-th"></th>';/* table cell */
180 $markup_header = wppizza_array_splice($markup_header, $splice, 0);
181 }
182
183 }
184
185 /*
186 add delete button th - right
187 */
188 if($wppizza_options['order_settings']['menu_item_remove_button'] == 'right'){
189 $markup_header['thead_th_delete'] = '<th class="'.WPPIZZA_PREFIX.'-item-delete-th"></th>';/* table cell */
190 }
191
192
193 return $markup_header;
194 }
195 /**********************************************************************************
196 * item columns pages (order, confirmation, thank you, user order history )
197 **********************************************************************************/
198 function wppizza_order_form_item_quantity_input($item_column, $key , $item, $cart, $item_count, $order_id, $txt, $type){
199 global $wppizza_options;
200 /* skip if not enabled and ONLY on orderpage*/
201 if($type!='orderpage'){
202 return $item_column;
203 }
204
205 /* replace quantity text with selectable input */
206 if(!empty($wppizza_options['order_settings']['order_page_quantity_change']) ){
207
208 $item_column['item_td_quantity'] ='';
209 $item_column['item_td_quantity'] .='<td class="'.WPPIZZA_PREFIX.'-item-update">';
210 // use for delete button on left
211 if($wppizza_options['order_settings']['menu_item_remove_button'] == 'left'){
212 $item_column['item_td_quantity'] .= '<input type="button" id="'.WPPIZZA_PREFIX.'-cart-'.$key.'" class="'.WPPIZZA_PREFIX.'-delete-from-cart" title="'.$txt['remove_from_cart'].'" value="x" />';
213 }
214
215 $item_column['item_td_quantity'] .= '<input type="number" size="1" step="1" min="0" autocomplete="off" onmousewheel id="'.WPPIZZA_PREFIX.'-qkey-'.$key.'" name="'.WPPIZZA_PREFIX.'-cart-mod-'.$key.'" class="'.WPPIZZA_PREFIX.'-item-qupdate" value="'.$item['quantity'].'" />';
216
217
218 $item_column['item_td_quantity'] .='</td>';
219
220 }else{
221
222 // use for delete button on left
223 if($wppizza_options['order_settings']['menu_item_remove_button'] == 'left'){
224
225 /*
226 create delete button
227 */
228 $splice['thead_th_delete'] ='';
229 $splice['thead_th_delete'] .= '<td class="'.WPPIZZA_PREFIX.'-item-delete">';
230 $splice['thead_th_delete'] .= '<input type="button" id="'.WPPIZZA_PREFIX.'-cart-'.$key.'" class="'.WPPIZZA_PREFIX.'-delete-from-cart" title="'.$txt['remove_from_cart'].'" value="x" />';
231 $splice['thead_th_delete'] .= '</td>';
232 /*
233 splice before (non-editable) quantity th
234 */
235 $item_column = wppizza_array_splice($item_column, $splice, 0);
236
237
238 }
239
240 }
241
242
243
244 /*
245 add delete button - right
246 */
247 if($wppizza_options['order_settings']['menu_item_remove_button'] == 'right'){
248 $item_column['item_td_delete']='';
249 $item_column['item_td_delete'] .='<td class="'.WPPIZZA_PREFIX.'-item-delete">';
250 $item_column['item_td_delete'] .= '<input type="button" id="'.WPPIZZA_PREFIX.'-cart-'.$key.'" class="'.WPPIZZA_PREFIX.'-delete-from-cart" title="'.$txt['remove_from_cart'].'" value="x" />';
251 $item_column['item_td_delete'] .='</td>';
252 }
253
254
255 return $item_column;
256 }
257 /*******************************************************************************************************************************************************
258 *
259 *
260 *
261 * [add admin page options]
262 *
263 *
264 *
265 ********************************************************************************************************************************************************/
266
267 /*------------------------------------------------------------------------------
268 #
269 #
270 # [settings page]
271 #
272 #
273 ------------------------------------------------------------------------------*/
274
275 /*------------------------------------------------------------------------------
276 # [settings section - setting page]
277 # @since 3.0
278 # @return array()
279 ------------------------------------------------------------------------------*/
280 function admin_options_settings($settings, $sections, $fields, $inputs, $help){
281
282 /*section*/
283 if($sections){
284 $settings['sections'][$this->section_key] = __('Item and Cart Updates and Amendments', 'wppizza-admin');
285 }
286
287 /*help*/
288 if($help){
289 $settings['help'][$this->section_key][] = array(
290 'label'=>__('Item and Cart Updates', 'wppizza-admin'),
291 'description'=>array(
292 __('Set required options using the settings available', 'wppizza-admin')
293 )
294 );
295 }
296
297 /*fields*/
298 if($fields){
299 $field = 'cart_increase';
300 $settings['fields'][$this->section_key][$field] = array( __('*Cart* items update', 'wppizza-admin') , array(
301 'value_key'=>$field,
302 'option_key'=>$this->settings_page,
303 'label'=>__('Enable increase/decrease of items in cart via input field/textbox', 'wppizza-admin'),
304 'description'=>array()
305 ));
306
307 $field = 'cart_increase_minicart';
308 $settings['fields'][$this->section_key][$field] = array( __('*MiniCart* items update', 'wppizza-admin') , array(
309 'value_key'=>$field,
310 'option_key'=>$this->settings_page,
311 'label'=>__('Enable increase/decrease of items in the MiniCart (if used) via input field/textbox (*Cart* items update must be enabled)', 'wppizza-admin'),
312 'description'=>array()
313 ));
314
315 $field = 'order_page_quantity_change';
316 $settings['fields'][$this->section_key][$field] = array( __('*Order Form* items update', 'wppizza-admin') , array(
317 'value_key'=>$field,
318 'option_key'=>$this->settings_page,
319 'label'=>__('Enable increase/decrease of items in order form via input field/textbox', 'wppizza-admin'),
320 'description'=>array()
321 ));
322
323 $field = 'order_page_quantity_change_style';
324 $settings['fields'][$this->section_key][$field] = array( __('Items update style', 'wppizza-admin') , array(
325 'value_key'=>$field,
326 'option_key'=>$this->settings_page,
327 'label'=>__('Which style would you like to use for the quantity change input fields', 'wppizza-admin'),
328 'description'=>array()
329 ));
330
331 $field = 'menu_item_remove_button';
332 $settings['fields'][$this->section_key][$field] = array( __('Enable "remove" button too', 'wppizza-admin') , array(
333 'value_key'=>$field,
334 'option_key'=>$this->settings_page,
335 'label'=>__('Additionally enables a distinct button to remove/delete an item from cart', 'wppizza-admin'),
336 'description'=>array()
337 ));
338
339
340 $field = 'empty_cart_button';
341 $settings['fields'][$this->section_key][$field] = array( __('Enable "empty cart" button', 'wppizza-admin') , array(
342 'value_key'=>$field,
343 'option_key'=>$this->settings_page,
344 'label'=>__('Additionally add a distinct "empty cart" button alongside the "checkout" button', 'wppizza-admin'),
345 'description'=>array()
346 ));
347 }
348
349 return $settings;
350 }
351 /*------------------------------------------------------------------------------
352 # [output option fields - setting page]
353 # @since 3.0
354 # @return array()
355 ------------------------------------------------------------------------------*/
356 function admin_options_fields_settings($wppizza_options, $options_key, $field, $label, $description){
357
358 if($field=='cart_increase'){
359 print'<label>';
360 echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />";
361 print'' . $label . '';
362 print'</label>';
363 print'' . $description . '';
364 }
365
366 if($field=='cart_increase_minicart'){
367 print'<label>';
368 echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />";
369 print'' . $label . '';
370 print'</label>';
371 print'' . $description . '';
372 }
373
374 if($field=='order_page_quantity_change'){
375 print'<label>';
376 echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />";
377 print'' . $label . '';
378 print'</label>';
379 print'' . $description . '';
380 }
381
382 if($field=='order_page_quantity_change_style'){
383 print'<label>';
384 echo "<select name='".WPPIZZA_SLUG."[".$options_key."][order_page_quantity_change_style]' class='wppizza_".$field."'>";
385 foreach(wppizza_ui_styles() as $k=>$style){
386 echo "<option value='".$style."' ".selected($wppizza_options[$options_key]['order_page_quantity_change_style'],$style,false).">".$style."</option>";
387 }
388 echo "<option value='' ".selected($wppizza_options[$options_key]['order_page_quantity_change_style'],'',false).">".__('a (themeroller) style is already loaded / I provide my own style', 'wppizza-admin')."</option>";
389 echo "</select>";
390 print'' . $label . '';
391 print'</label>';
392 }
393
394 if($field=='menu_item_remove_button'){
395 print'<label>';
396 echo "<select id='".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' class='wppizza_".$field."'>";
397 echo "<option value='off' ".selected($wppizza_options[$options_key][$field],"off",false).">".__('off', 'wppizza-admin')."</option>";
398 echo "<option value='left' ".selected($wppizza_options[$options_key][$field],"left",false).">".__('left', 'wppizza-admin')."</option>";
399 echo "<option value='right' ".selected($wppizza_options[$options_key][$field],"right",false).">".__('right', 'wppizza-admin')."</option>";
400 echo "</select>";
401 print'' . $label . '';
402 print'</label>';
403 print'' . $description . '';
404 }
405
406 if($field=='empty_cart_button'){
407 print'<label>';
408 echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />";
409 print'' . $label . '';
410 print'</label>';
411 print'' . $description . '';
412 }
413
414 }
415
416 /****************************************************************
417 *
418 * [insert default option on install]
419 * $parameter $options array() | filter passing on filtered options
420 * @since 3.0
421 * @return array()
422 *
423 ****************************************************************/
424 function options_default($options){
425 $options[$this->settings_page]['cart_increase'] = true;
426 $options[$this->settings_page]['cart_increase_minicart'] = false;
427 $options[$this->settings_page]['order_page_quantity_change'] = true;
428 $options[$this->settings_page]['menu_item_remove_button'] = 'right';
429 //$options[$this->settings_page]['order_page_quantity_change_left'] = false;
430 $options[$this->settings_page]['order_page_quantity_change_style'] = 'smoothness';
431 $options[$this->settings_page]['empty_cart_button'] = true;
432
433 return $options;
434 }
435
436 /*------------------------------------------------------------------------------
437 # [validate options on save/update]
438 #
439 # @since 3.0
440 # @return array()
441 ------------------------------------------------------------------------------*/
442 function options_validate($options, $input){
443 /**make sure we get the full array on install/update**/
444 if ( empty( $_POST['_wp_http_referer'] ) ) {
445 return $input;
446 }
447 if(isset($_POST[''.WPPIZZA_SLUG.'_'.$this->settings_page.''])){
448 $options[$this->settings_page]['cart_increase'] = !empty($input[$this->settings_page]['cart_increase']) ? true : false;
449 $options[$this->settings_page]['cart_increase_minicart'] = !empty($input[$this->settings_page]['cart_increase_minicart']) ? true : false;
450 $options[$this->settings_page]['order_page_quantity_change'] = !empty($input[$this->settings_page]['order_page_quantity_change']) ? true : false;
451 //$options[$this->settings_page]['order_page_quantity_change_left'] = !empty($input[$this->settings_page]['order_page_quantity_change_left']) ? true : false;
452 $options[$this->settings_page]['menu_item_remove_button'] = in_array($input[$this->settings_page]['menu_item_remove_button'],array('off','left','right')) ? $input[$this->settings_page]['menu_item_remove_button'] : 'off';
453 $options[$this->settings_page]['order_page_quantity_change_style']=wppizza_validate_string($input[$this->settings_page]['order_page_quantity_change_style']);
454 $options[$this->settings_page]['empty_cart_button'] = !empty($input[$this->settings_page]['empty_cart_button']) ? true : false;
455 }
456
457 return $options;
458 }
459 }
460 /***************************************************************
461 *
462 * [ini]
463 *
464 ***************************************************************/
465 $WPPIZZA_MODULE_ORDER_SETTINGS_ORDER_UPDATE = new WPPIZZA_MODULE_ORDER_SETTINGS_ORDER_UPDATE();
466 ?>