Changeset 1599175
- Timestamp:
- 02/19/2017 07:38:55 PM (9 years ago)
- Location:
- redi-restaurant-reservation/branches/discount
- Files:
-
- 2 edited
-
js/restaurant.js (modified) (1 diff)
-
redi-restaurant-reservation.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
redi-restaurant-reservation/branches/discount/js/restaurant.js
r1557008 r1599175 361 361 + (b['Available'] ? '' : ' title="' + redi_restaurant_reservation.tooltip + '"') + ' class="redi-restaurant-time-button button ' + (b['Available'] ? '' : 'disabled') + '" value="' + b['StartTimeISO'] + '" ' + 362 362 ' ' + (b['Select'] ? 'select="select"' : '') + '>' 363 + b['StartTime'] + '</button>'; 363 + b['StartTime']+ 364 (b['Discount'] === null ? '' : ' <br/> Discount' + b['Discount'] + ' % ') + 365 '</button>'; 364 366 if (b['Available']) { 365 367 all_busy = false; -
redi-restaurant-reservation/branches/discount/redi-restaurant-reservation.php
r1596498 r1599175 881 881 } 882 882 883 public function ArrayKeysLowercase($array){ 884 $return =[]; 885 foreach ($array as $key=>$value){ 886 $return[strtolower($key)] = $value; 887 } 888 return $return; 889 } 890 891 private function getMaxDiscount($discounts, $time){ 892 893 $all_discounts = []; 894 if(isset($discounts['time'][$time])){ 895 $all_discounts[] = $discounts['time'][$time]; 896 } 897 if(isset($discounts['dayofweek'])){ 898 $all_discounts[] = $discounts['dayofweek']; 899 } 900 if(isset($discounts['date'])){ 901 $all_discounts[] = $discounts['date']; 902 } 903 return (!empty($all_discounts)) ? max($all_discounts) : null; 904 } 905 906 private function getDiscount($date, $dayofweek) 907 { 908 $posts = get_posts(array( 909 'post_status' => 'publish', 910 'post_type' => 'discount', 911 'meta_query' => array( 912 'relation' => 'OR', 913 array( 914 'key' => 'dayofweek', 915 'value' => $dayofweek, 916 ), 917 array( 918 'key' => 'date', 919 'value' => $date, 920 ), 921 array( 922 'key' => 'time', 923 'compare' => 'EXISTS' 924 ) 925 ) 926 )); 927 $discounts = []; 928 foreach ($posts as $post) { 929 930 $custom_fields = self::ArrayKeysLowercase(get_post_custom($post->ID)); 931 if (isset($custom_fields['time'])) { 932 $discounts['time'][$custom_fields['time'][0]][] = $custom_fields['discount'][0]; 933 } 934 if (isset($custom_fields['date'])) { 935 $discounts['date'][] = $custom_fields['discount'][0]; 936 } 937 if (isset($custom_fields['dayofweek'])) { 938 $discounts['dayofweek'][] = $custom_fields['discount'][0]; 939 } 940 } 941 return $discounts; 942 } 943 883 944 public function shortcode( $atts ) { 884 945 if ( is_array( $atts ) && is_array( $this->options ) ) { … … 996 1057 $startDate = date( $date_format, $reservationStartTime ); 997 1058 $startDateISO = date( 'Y-m-d', $reservationStartTime ); 998 $startTime = mktime( date( 'G', $reservationStartTime ), 0, 0, 0, 0, 0 ); 1059 1060 $discounts = self::getDiscount(date('d.m.Y', $reservationStartTime), date('l', $reservationStartTime)); 1061 $startTime = mktime(date('G', $reservationStartTime), 0, 0, 0, 0, 0); 999 1062 1000 1063 $minPersons = $this->GetOption( 'MinPersons', 1 ); … … 1058 1121 ) 1059 1122 ); 1123 1060 1124 $hide_clock = true; 1061 1125 } … … 1324 1388 1325 1389 if ( $timeshiftmode === 'byshifts' ) { 1390 $discounts = self::getDiscount(date('d.m.Y', $startTimeInt), date('l', $startTimeInt)); 1391 1326 1392 $query['alternativeTime'] = $alternativeTime; 1327 1393 switch ( $alternativeTime ) { … … 1343 1409 $q->StartTime = self::format_time( $q->StartTime, $time_lang, $time_format ); 1344 1410 $q->EndTime = date( $time_format, strtotime( $q->EndTime ) ); 1411 $q->Discount = self::getMaxDiscount($discounts, $q->StartTime); 1345 1412 } 1346 1413 }
Note: See TracChangeset
for help on using the changeset viewer.