Пример #1
0
 function do_add_to_cart()
 {
     $pass_validate = true;
     $item_id = intval(STInput::request('item_id', ''));
     if ($item_id <= 0 || get_post_type($item_id) != 'st_activity') {
         STTemplate::set_message(__('This activity is not available..', ST_TEXTDOMAIN), 'danger');
         $pass_validate = false;
         return false;
     }
     $number = 1;
     $type_activity = STInput::request('type_activity', 'specific_date');
     $adult_number = intval(STInput::request('adult_number', 1));
     $child_number = intval(STInput::request('child_number', 0));
     $infant_number = intval(STInput::request('infant_number', 0));
     $max_number = intval(get_post_meta($item_id, 'max_people', true));
     $today = date('Y-m-d');
     if ($adult_number + $child_number + $infant_number > $max_number) {
         STTemplate::set_message(sprintf(__('Max of people for this activity is %d people', ST_TEXTDOMAIN), $max_number), 'danger');
         $pass_validate = FALSE;
         return false;
     }
     if ($type_activity == 'specific_date') {
         $check_in = TravelHelper::convertDateFormat(STInput::request('check_in', ''));
         $check_out = TravelHelper::convertDateFormat(STInput::request('check_out', ''));
         if (empty($check_in)) {
             STTemplate::set_message(__('The check in field is not empty.', ST_TEXTDOMAIN), 'danger');
             $pass_validate = false;
             return false;
         }
         if (empty($check_out)) {
             STTemplate::set_message(__('The check out field is not empty.', ST_TEXTDOMAIN), 'danger');
             $pass_validate = false;
             return false;
         }
         $compare = TravelHelper::dateCompare($today, $check_in);
         if ($compare < 0) {
             STTemplate::set_message(__('This activity has expired', ST_TEXTDOMAIN), 'danger');
             $pass_validate = false;
             return false;
         }
         $people = $adult_number + $child_number + $child_number;
         $result = ActivityHelper::_get_free_peple_special($item_id, $check_in, $check_out);
         $free_people = intval(get_post_meta($item_id, 'max_people', true));
         if (is_array($result) && count($result)) {
             $free_people = intval($result['free_people']);
         }
         if ($free_people < $people) {
             STTemplate::set_message(sprintf(__('This activity only vacant %d people', ST_TEXTDOMAIN), $free_people), 'danger');
             $pass_validate = false;
             return false;
         }
         $data['check_in'] = date('m/d/Y', strtotime($check_in));
         $data['check_out'] = date('m/d/Y', strtotime($check_out));
     } elseif ($type_activity == 'daily_activity') {
         $check_in = STInput::request('check_in', '');
         if (empty($check_in)) {
             STTemplate::set_message(__('The check in field is not empty.', ST_TEXTDOMAIN), 'danger');
             $pass_validate = false;
             return false;
         }
         $check_in = TravelHelper::convertDateFormat($check_in);
         $check_in = date('Y-m-d', strtotime($check_in));
         $duration = intval(get_post_meta($item_id, 'duration', true));
         $check_out = $duration >= 2 ? strtotime('+ ' . $duration . ' days', strtotime($check_in)) : strtotime('+ ' . $duration . ' day', strtotime($check_in));
         $check_out = date('Y-m-d', $check_out);
         $booking_period = intval(get_post_meta($item_id, 'activity_booking_period', true));
         $period = TravelHelper::dateDiff($today, $check_in);
         $compare = TravelHelper::dateCompare($today, $check_in);
         if ($compare < 0) {
             STTemplate::set_message(__('You can not set check-in date in the past', ST_TEXTDOMAIN), 'danger');
             $pass_validate = false;
             return false;
         }
         if ($booking_period && $booking_period > $period) {
             STTemplate::set_message(sprintf(__('This activity allow minimum booking is %d day(s)', ST_TEXTDOMAIN), $booking_period), 'danger');
             $pass_validate = false;
             return false;
         }
         $people = $adult_number + $child_number + $child_number;
         $result = ActivityHelper::_get_free_peple_daily($item_id, $check_in);
         $free_people = intval(get_post_meta($item_id, 'max_people', true));
         if (is_array($result) && count($result)) {
             $free_people = intval($result['free_people']);
         }
         if ($free_people < $people) {
             STTemplate::set_message(sprintf(__('This activity only vacant %d people', ST_TEXTDOMAIN), $free_people), 'danger');
             $pass_validate = false;
             return false;
         }
         $data['duration'] = $duration;
     }
     $data['adult_number'] = $adult_number;
     $data['child_number'] = $child_number;
     $data['infant_number'] = $infant_number;
     $data['check_in'] = date('m/d/Y', strtotime($check_in));
     $data['check_out'] = date('m/d/Y', strtotime($check_out));
     $data['type_activity'] = $type_activity;
     $data_price = STPrice::getPriceByPeople($item_id, strtotime($check_in), strtotime($check_out), $adult_number, $child_number, $infant_number);
     $total_price = $data_price['total_price'];
     $sale_price = STPrice::getSaleTourSalePrice($item_id, $total_price, $type_activity, strtotime($check_in));
     $discount_rate = STPrice::get_discount_rate($item_id, strtotime($check_in));
     $data['adult_price'] = floatval(get_post_meta($item_id, 'adult_price', true));
     $data['child_price'] = floatval(get_post_meta($item_id, 'child_price', true));
     $data['infant_price'] = floatval(get_post_meta($item_id, 'infant_price', true));
     $data['ori_price'] = $sale_price;
     $data['currency'] = TravelHelper::get_current_currency('symbol');
     $data['currency_rate'] = TravelHelper::get_current_currency('rate');
     $data['currency_pos'] = TravelHelper::get_current_currency('booking_currency_pos');
     $data['commission'] = TravelHelper::get_commission();
     $data['data_price'] = $data_price;
     $data['discount_rate'] = $discount_rate;
     if ($pass_validate) {
         $pass_validate = apply_filters('st_activity_add_cart_validate', $pass_validate);
     }
     if ($pass_validate) {
         STCart::add_cart($item_id, $number, $sale_price, $data);
     }
     return $pass_validate;
 }
Пример #2
0
 function check_validate()
 {
     $data = array();
     $order_item_id = STInput::request('order_item_id', '');
     $st_first_name = STInput::request('st_first_name', '');
     if (empty($st_first_name)) {
         STAdmin::set_message(__('The firstname field is not empty.', ST_TEXTDOMAIN), 'danger');
         return false;
     }
     $st_last_name = STInput::request('st_last_name', '');
     if (empty($st_last_name)) {
         STAdmin::set_message(__('The lastname field is not empty.', ST_TEXTDOMAIN), 'danger');
         return false;
     }
     $st_email = STInput::request('st_email', '');
     if (empty($st_email)) {
         STAdmin::set_message(__('The email field is not empty.', ST_TEXTDOMAIN), 'danger');
         return false;
     }
     $st_phone = STInput::request('st_phone', '');
     if (empty($st_phone)) {
         STAdmin::set_message(__('The phone field is not empty.', ST_TEXTDOMAIN), 'danger');
         return false;
     }
     if (STInput::request('section', '') != 'edit_order_item') {
         $item_id = intval(STInput::request('item_id', ''));
         if ($item_id <= 0 || get_post_type($item_id) != 'st_activity') {
             STAdmin::set_message(__('The activity field is not empty.', ST_TEXTDOMAIN), 'danger');
             return false;
         }
         $type_activity = STInput::request('type_activity', 'daily_activity');
         $today = date('Y-m-d');
         $check_in = STInput::request('check_in', '');
         if (empty($check_in)) {
             STAdmin::set_message(__('The check in field is not empty.', ST_TEXTDOMAIN), 'danger');
             return false;
         }
         $check_in = date('Y-m-d', strtotime($check_in));
         $check_out = STInput::request('check_out', '');
         if (empty($check_out)) {
             STAdmin::set_message(__('The check out field is not empty.', ST_TEXTDOMAIN), 'danger');
             return false;
         }
         $check_out = date('Y-m-d', strtotime($check_out));
         $adult_number = intval(STInput::request('adult_number', 1));
         $child_number = intval(STInput::request('child_number', 0));
         $infant_number = intval(STInput::request('infant_number', 0));
         $max_number = intval(get_post_meta($item_id, 'max_people', true));
         if ($adult_number + $child_number + $infant_number > $max_number) {
             STAdmin::set_message(sprintf(__('Max of people for this activity is %d people', ST_TEXTDOMAIN), $max_number), 'danger');
             return false;
         }
         if ($type_activity == 'daily_activity') {
             $booking_period = intval(get_post_meta($item_id, 'activity_booking_period', true));
             $period = TravelHelper::dateDiff($today, $check_in);
             $compare = TravelHelper::dateCompare($today, $check_in);
             if ($compare < 0) {
                 STAdmin::set_message(__('You can not set check-in date in the past', ST_TEXTDOMAIN), 'danger');
                 return false;
             }
             if ($booking_period && $booking_period > $period) {
                 STAdmin::set_message(sprintf(__('This activity allow minimum booking is %d day(s)', ST_TEXTDOMAIN), $booking_period), 'danger');
                 return false;
             }
             $people = $adult_number + $child_number + $infant_number;
             $result = ActivityHelper::_get_free_peple_daily($item_id, $check_in, $order_item_id);
             $free_people = intval(get_post_meta($item_id, 'max_people', true));
             if (is_array($result) && count($result)) {
                 $free_people = intval($result['free_people']);
             }
             if ($free_people < $people) {
                 STAdmin::set_message(sprintf(__('This activity only vacant %d people', ST_TEXTDOMAIN), $free_people), 'danger');
                 return false;
             }
             $duration = get_post_meta($item_id, 'duration', true);
             $data['duration'] = $duration;
         } elseif ($type_activity == 'specific_date') {
             $compare = TravelHelper::dateCompare($today, $check_in);
             if ($compare < 0) {
                 STAdmin::set_message(__('This activity has expired', ST_TEXTDOMAIN), 'danger');
                 return false;
             }
             $people = $adult_number + $child_number + $infant_number;
             $result = ActivityHelper::_get_free_peple_special($item_id, $check_in, $check_out, $order_item_id);
             $free_people = intval(get_post_meta($item_id, 'max_people', true));
             if (is_array($result) && count($result)) {
                 $free_people = intval($result['free_people']);
             }
             if ($free_people < $people) {
                 STAdmin::set_message(sprintf(__('This activity only vacant %d people', ST_TEXTDOMAIN), $free_people), 'danger');
                 return false;
             }
         }
         $data['item_id'] = $item_id;
         $data['order_item_id'] = $order_item_id;
         $data['check_in'] = date('m/d/Y', strtotime($check_in));
         $data['check_out'] = date('m/d/Y', strtotime($check_out));
         $data['adult_number'] = $adult_number;
         $data['child_number'] = $child_number;
         $data['infant_number'] = $infant_number;
         $data['type_activity'] = $type_activity;
         $data['adult_price'] = floatval(get_post_meta($item_id, 'adult_price', true));
         $data['child_price'] = floatval(get_post_meta($item_id, 'child_price', true));
         $data['infant_price'] = floatval(get_post_meta($item_id, 'infant_price', true));
     }
     return $data;
 }