Plugin Directory

Changeset 1599175


Ignore:
Timestamp:
02/19/2017 07:38:55 PM (9 years ago)
Author:
robby.roboter
Message:

Discount

Location:
redi-restaurant-reservation/branches/discount
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • redi-restaurant-reservation/branches/discount/js/restaurant.js

    r1557008 r1599175  
    361361                                            + (b['Available'] ? '' : ' title="' + redi_restaurant_reservation.tooltip + '"') + ' class="redi-restaurant-time-button button ' + (b['Available'] ? '' : 'disabled') + '" value="' + b['StartTimeISO'] + '" ' +
    362362                                            ' ' + (b['Select'] ? 'select="select"' : '') + '>'
    363                                             + b['StartTime'] + '</button>';
     363                                            + b['StartTime']+
     364                                            (b['Discount'] === null ? '' : ' <br/> Discount' + b['Discount'] + ' % ') +
     365                                            '</button>';
    364366                                        if (b['Available']) {
    365367                                            all_busy = false;
  • redi-restaurant-reservation/branches/discount/redi-restaurant-reservation.php

    r1596498 r1599175  
    881881        }
    882882
     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
    883944        public function shortcode( $atts ) {
    884945            if ( is_array( $atts ) && is_array( $this->options ) ) {
     
    9961057            $startDate                = date( $date_format, $reservationStartTime );
    9971058            $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);
    9991062
    10001063            $minPersons         = $this->GetOption( 'MinPersons', 1 );
     
    10581121                    )
    10591122                );
     1123
    10601124                $hide_clock = true;
    10611125            }
     
    13241388
    13251389            if ( $timeshiftmode === 'byshifts' ) {
     1390                $discounts = self::getDiscount(date('d.m.Y', $startTimeInt), date('l', $startTimeInt));
     1391
    13261392                $query['alternativeTime'] = $alternativeTime;
    13271393                switch ( $alternativeTime ) {
     
    13431409                                    $q->StartTime    = self::format_time( $q->StartTime, $time_lang, $time_format );
    13441410                                    $q->EndTime      = date( $time_format, strtotime( $q->EndTime ) );
     1411                                    $q->Discount     = self::getMaxDiscount($discounts, $q->StartTime);
    13451412                                }
    13461413                            }
Note: See TracChangeset for help on using the changeset viewer.