public function _checkout_form_validate()
 {
     $cart = STCart::get_carts();
     if (is_array($cart) && count($cart)) {
         $cart_hotel = ValidateNormalCheckout::get_cart_data($cart, 'st_hotel');
         $validate_hotel = ValidateNormalCheckout::_validate_cart_hotel($cart_hotel);
         if (!$validate_hotel) {
             $message = $_SESSION['flash_validate_checkout'];
             STTemplate::set_message($message);
             return false;
         }
         $cart_rental = ValidateNormalCheckout::get_cart_data($cart, 'st_rental');
         $validate_rental = ValidateNormalCheckout::_validate_cart_rental($cart_rental);
         if (!$validate_rental) {
             $message = $_SESSION['flash_validate_checkout'];
             STTemplate::set_message($message);
             return false;
         }
     }
     return true;
 }
Пример #2
0
 /**
  * Validate if order is available to show booking infomation
  *
  * @since 1.0.8
  *
  * */
 function success_page_validate()
 {
     $order_code = STInput::get('order_code');
     $order_token_code = STInput::get('order_token_code');
     if ($order_token_code) {
         $order_code = STOrder::get_order_id_by_token($order_token_code);
     }
     $status = get_post_meta($order_code, 'status', true);
     $result = true;
     if ($status == 'incomplete') {
         // try to check payment complete
         $paypal = new STPaypal();
         $r = $paypal->check_completePurchase($order_code);
         if ($r) {
             if (isset($r['status'])) {
                 if ($r['status']) {
                     $result = true;
                     update_post_meta($order_code, 'status', 'complete');
                     $status = 'complete';
                     do_action('st_email_after_booking', $order_code);
                     do_action('st_booking_submit_form_success', $order_code);
                 } elseif (isset($r['message']) and $r['message']) {
                     $result = false;
                     STTemplate::set_message($r['message'], 'danger');
                 }
                 if (isset($r['redirect_url']) and $r['redirect_url']) {
                     echo "<script>window.location.href='" . $r['redirect_url'] . "'</script>";
                     die;
                 }
             }
         }
     }
     if ($status == 'incomplete') {
         $result = false;
         STTemplate::set_message(__("Sorry! Your payment is incomplete."));
     }
     return $result;
 }
Пример #3
0
 /**
  * @since 1.0.9
  **/
 function activity_add_to_cart()
 {
     if (STInput::get('action') == 'activity_add_to_cart') {
         $item_id = STInput::get('item_id');
         $number = STInput::get('number');
         $discount = STInput::get('discount');
         if (!empty($discount)) {
             $price = STInput::get('price');
             $price = $price - $price * ($discount / 100);
             $data = array('discount' => $discount, 'price_old' => STInput::get('price'), 'price_sale' => $price);
         } else {
             $price = STInput::get('price');
         }
         $data['check_in'] = STInput::get('check_in');
         $data['check_out'] = STInput::get('check_out');
         $data['type_price'] = STInput::request('type_price');
         if ($data['type_price'] == 'people_price') {
             $prices = self::get_price_person($item_id);
             $data['adult_price'] = $prices['adult'];
             $data['child_price'] = $prices['child'];
             $data['discount'] = $prices['discount'];
             $data['adult_number'] = STInput::request('adult_number', 1);
             $data['child_number'] = STInput::request('children_number', 0);
         }
         /* Check booking period */
         $today = strtotime(date('m/d/Y'));
         $check_out = strtotime(STInput::get('check_out'));
         //$period = STDate::date_diff($today,$check_in);
         $expired = $today - $check_out;
         if ($expired >= 0) {
             STTemplate::set_message(__('This activity has expired', ST_TEXTDOMAIN), 'danger');
             return;
         } else {
             STCart::add_cart($item_id, $number, $price, $data);
             $link = STCart::get_cart_link();
             wp_safe_redirect($link);
             die;
         }
     }
 }
Пример #4
0
 function do_add_to_cart()
 {
     $pass_validate = true;
     $item_id = STInput::request('item_id', '');
     if ($item_id <= 0 || get_post_type($item_id) != 'st_holidays') {
         STTemplate::set_message(__('This holiday is not available..', ST_TEXTDOMAIN), 'danger');
         $pass_validate = false;
         return false;
     }
     $number = 1;
     $adult_number = intval(STInput::request('adult_number', 1));
     $child_number = intval(STInput::request('child_number', 0));
     $infant_number = intval(STInput::request('infant_number', 0));
     $data['adult_number'] = $adult_number;
     $data['child_number'] = $child_number;
     $data['infant_number'] = $infant_number;
     $max_number = intval(get_post_meta($item_id, 'max_people', true));
     $type_holiday = get_post_meta($item_id, 'type_holiday', true);
     $data['type_holiday'] = $type_holiday;
     $today = date('Y-m-d');
     $check_in = STInput::request('check_in', '');
     $check_out = STInput::request('check_out', '');
     if (!$check_in || !$check_out) {
         STTemplate::set_message(__('Select a holiday in the calendar above.', ST_TEXTDOMAIN), 'danger');
         $pass_validate = FALSE;
         return false;
     }
     $compare = TravelHelper::dateCompare($today, $check_in);
     if ($compare < 0) {
         STTemplate::set_message(__('This holiday has expired', ST_TEXTDOMAIN), 'danger');
         $pass_validate = false;
         return false;
     }
     $booking_period = intval(get_post_meta($item_id, 'holidays_booking_period', true));
     $period = TravelHelper::dateDiff($today, $check_in);
     if ($period < $booking_period) {
         STTemplate::set_message(sprintf(__('This holiday allow minimum booking is %d day(s)', ST_TEXTDOMAIN), $booking_period), 'danger');
         $pass_validate = false;
         return false;
     }
     if ($adult_number + $child_number + $infant_number > $max_number) {
         STTemplate::set_message(sprintf(__('Max of people for this holiday is %d people', ST_TEXTDOMAIN), $max_number), 'danger');
         $pass_validate = FALSE;
         return false;
     }
     $holiday_available = HolidayHelper::checkAvailableHoliday($item_id, strtotime($check_in), strtotime($check_out));
     if (!$holiday_available) {
         STTemplate::set_message(__('The check in, check out day is not invalid or this holiday not available.', ST_TEXTDOMAIN), 'danger');
         $pass_validate = FALSE;
         return false;
     }
     $free_people = intval(get_post_meta($item_id, 'max_people', true));
     $result = HolidayHelper::_get_free_peple($item_id, strtotime($check_in), strtotime($check_out));
     if (is_array($result) && count($result)) {
         $free_people = intval($result['free_people']);
     }
     if ($free_people < $adult_number + $child_number + $infant_number) {
         STTemplate::set_message(sprintf(__('This holiday only vacant %d people', ST_TEXTDOMAIN), $free_people), 'danger');
         $pass_validate = FALSE;
         return false;
     }
     $data_price = STPrice::getPriceByPeopleHoliday($item_id, strtotime($check_in), strtotime($check_out), $adult_number, $child_number, $infant_number);
     $total_price = $data_price['total_price'];
     $sale_price = STPrice::getSaleHolidaySalePrice($item_id, $total_price, $type_holiday, strtotime($check_in));
     $data['check_in'] = date('m/d/Y', strtotime($check_in));
     $data['check_out'] = date('m/d/Y', strtotime($check_out));
     $people_price = STPrice::getPeoplePrice($item_id, strtotime($check_in), strtotime($check_out));
     $data = wp_parse_args($data, $people_price);
     $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'] = STPrice::get_discount_rate($item_id, strtotime($check_in));
     if ($pass_validate) {
         $data['duration'] = $type_holiday == 'daily_holiday' ? floatval(get_post_meta($item_id, 'duration_day', true)) : '';
         if ($pass_validate) {
             STCart::add_cart($item_id, $number, $sale_price, $data);
         }
     }
     return $pass_validate;
 }
 /**
  * Check if a gateway is allow to show the booking infomation by gived gateway id
  *
  * @param $id: GateWay Name
  *
  * @result bool
  *
  * @since 1.0.8
  *
  * */
 static function gateway_success_page_validate($id = false)
 {
     $all = self::get_payment_gateways();
     if (isset($all[$id])) {
         $value = $all[$id];
         if (method_exists($value, 'get_name')) {
             return $value->success_page_validate();
         }
     } else {
         STTemplate::set_message(__('Sorry! Your Payment Gateway is not valid', ST_TEXTDOMAIN), 'danger');
     }
 }
Пример #6
0
 function _add_cart_check_available($post_id = false, $data = array())
 {
     if (!$post_id or get_post_status($post_id) != 'publish') {
         STTemplate::set_message(__('Rental doese not exists', ST_TEXTDOMAIN), 'danger');
         return false;
     }
     $validator = new STValidate();
     $validator->set_rules('start', __('Check in', ST_TEXTDOMAIN), 'required');
     $validator->set_rules('end', __('Check out', ST_TEXTDOMAIN), 'required');
     if (!$validator->run()) {
         STTemplate::set_message($validator->error_string(), 'danger');
         return false;
     }
     $check_in = date('Y-m-d H:i:s', strtotime(STInput::post('start')));
     $check_out = date('Y-m-d H:i:s', strtotime(STInput::post('end')));
     if (!$this->_is_slot_available($post_id, $check_in, $check_out)) {
         STTemplate::set_message(__('Sorry! This rental is not available.', ST_TEXTDOMAIN), 'danger');
         return false;
     }
     return true;
 }
Пример #7
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;
 }
Пример #8
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_hotel') {
         STTemplate::set_message(__('This hotel is not available.', ST_TEXTDOMAIN), 'danger');
         $pass_validate = FALSE;
         return false;
     }
     $room_id = intval(STInput::request('room_id', ''));
     if ($room_id <= 0 || get_post_type($room_id) != 'hotel_room') {
         STTemplate::set_message(__('This room is not available.', ST_TEXTDOMAIN), 'danger');
         $pass_validate = FALSE;
         return false;
     }
     $check_in = STInput::request('check_in', '');
     if (empty($check_in)) {
         STTemplate::set_message(__('Date is invalid', ST_TEXTDOMAIN), 'danger');
         $pass_validate = FALSE;
         return false;
     }
     $check_in = TravelHelper::convertDateFormat($check_in);
     $check_out = STInput::request('check_out', '');
     if (empty($check_out)) {
         STTemplate::set_message(__('Date is invalid', ST_TEXTDOMAIN), 'danger');
         $pass_validate = FALSE;
         return false;
     }
     $check_out = TravelHelper::convertDateFormat($check_out);
     $room_num_search = intval(STInput::request('room_num_search', ''));
     if ($room_num_search <= 0) {
         $room_num_search = 1;
     }
     $adult_number = intval(STInput::request('adult_number', ''));
     if ($adult_number <= 0) {
         $adult_number = 1;
     }
     $child_number = intval(STInput::request('child_number', ''));
     if ($child_number <= 0) {
         $child_number = 0;
     }
     $checkin_ymd = date('Y-m-d', strtotime($check_in));
     $checkout_ymd = date('Y-m-d', strtotime($check_out));
     if (!HotelHelper::check_day_cant_order($room_id, $checkin_ymd, $checkout_ymd, $room_num_search)) {
         STTemplate::set_message(sprintf(__('This room is not available from %s to %s.', ST_TEXTDOMAIN), $checkin_ymd, $checkout_ymd), 'danger');
         $pass_validate = FALSE;
         return false;
     }
     if (!HotelHelper::_check_room_available($room_id, $checkin_ymd, $checkout_ymd, $room_num_search)) {
         STTemplate::set_message(__('This room is not available.', ST_TEXTDOMAIN), 'danger');
         $pass_validate = FALSE;
         return false;
     }
     if (strtotime($check_out) - strtotime($check_in) <= 0) {
         STTemplate::set_message(__('The check-out is later than the check-in.', ST_TEXTDOMAIN), 'danger');
         $pass_validate = FALSE;
         return false;
     }
     $num_room = intval(get_post_meta($room_id, 'number_room', true));
     $adult = intval(get_post_meta($room_id, 'adult_number', true));
     $children = intval(get_post_meta($room_id, 'children_number', true));
     if ($room_num_search > $num_room) {
         STTemplate::set_message(__('Max of rooms are incorrect.', ST_TEXTDOMAIN), 'danger');
         $pass_validate = FALSE;
         return false;
     }
     if ($adult_number > $adult) {
         STTemplate::set_message(sprintf(__('Max of adults is %d people.', ST_TEXTDOMAIN), $adult), 'danger');
         $pass_validate = FALSE;
         return false;
     }
     if ($child_number > $children) {
         STTemplate::set_message(__('Number of children in the room are incorrect.', ST_TEXTDOMAIN), 'danger');
         $pass_validate = FALSE;
         return false;
     }
     $today = date('m/d/Y');
     $period = TravelHelper::dateDiff($today, $check_in);
     $booking_min_day = intval(get_post_meta($item_id, 'min_book_room', true));
     $compare = TravelHelper::dateCompare($today, $check_in);
     $booking_period = get_post_meta($item_id, 'hotel_booking_period', true);
     if (empty($booking_period) || $booking_period <= 0) {
         $booking_period = 0;
     }
     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 ($period < $booking_period) {
         STTemplate::set_message(sprintf(__('This hotel allow minimum booking is %d day(s)', ST_TEXTDOMAIN), $booking_period), 'danger');
         $pass_validate = FALSE;
         return false;
     }
     if ($booking_min_day and $booking_min_day > TravelHelper::dateDiff($check_in, $check_out)) {
         STTemplate::set_message(sprintf(__('Please booking at least %d day(s)', ST_TEXTDOMAIN), $booking_min_day), 'danger');
         $pass_validate = false;
         return false;
     }
     $item_price = floatval(get_post_meta($room_id, 'price', true));
     // Extra price added in the new version 1.1.9
     $extras = STInput::request('extra_price', array());
     $numberday = TravelHelper::dateDiff($check_in, $check_out);
     $extra_price = STPrice::getExtraPrice($extras, $room_num_search, $numberday);
     $sale_price = STPrice::getRoomPrice($room_id, strtotime($check_in), strtotime($check_out), $room_num_search);
     $discount_rate = STPrice::get_discount_rate($room_id, strtotime($check_in));
     $data = array('item_price' => $item_price, 'ori_price' => $sale_price + $extra_price, 'check_in' => $check_in, 'check_out' => $check_out, 'room_num_search' => $room_num_search, 'room_id' => $room_id, 'adult_number' => $adult_number, 'child_number' => $child_number, 'extras' => $extras, 'extra_price' => $extra_price, 'commission' => TravelHelper::get_commission(), 'discount_rate' => $discount_rate);
     if ($pass_validate) {
         $pass_validate = apply_filters('st_hotel_add_cart_validate', $pass_validate, $data);
     }
     if ($pass_validate) {
         STCart::add_cart($item_id, $room_num_search, $sale_price + $extra_price, $data);
     }
     return $pass_validate;
 }
Пример #9
0
 function do_add_to_cart()
 {
     $pass_validate = true;
     $item_id = STInput::request('item_id');
     $number = STInput::request('number');
     $discount = STInput::request('discount');
     $price = STInput::request('price');
     if (!empty($discount)) {
         $price_sale = $price - $price * ($discount / 100);
         $data = array('discount' => $discount, 'price_sale' => $price_sale);
     }
     $data['check_in'] = STInput::request('check_in');
     $data['check_out'] = STInput::request('check_out');
     $data['type_tour'] = STInput::request('type_tour');
     $data['type_price'] = STInput::request('type_price');
     if ($data['type_price'] == 'people_price') {
         $prices = self::get_price_person($item_id);
         $data['adult_price'] = $prices['adult'];
         $data['child_price'] = $prices['child'];
         $data['discount'] = $prices['discount'];
         $data['adult_number'] = STInput::request('adult_number', 1);
         $data['child_number'] = STInput::request('children_number', 0);
     }
     $data['duration'] = STInput::request('duration');
     $type_tour = STInput::request('type_tour');
     $today = strtotime(date('m/d/Y', time()));
     if ($type_tour == 'daily_tour') {
         $check_in = strtotime(TravelHelper::convertDateFormat(STInput::request('check_in')));
     } else {
         $check_in = strtotime(get_post_meta($item_id, 'check_in', true));
     }
     $booking_period = intval(get_post_meta($item_id, 'tours_booking_period', true));
     $period = STDate::date_diff($today, $check_in);
     $expired = $check_in - $today;
     if ($type_tour == 'daily_tour') {
         if ($booking_period && $period < $booking_period) {
             STTemplate::set_message(sprintf(__('Booking is only accepted %d day(s) before today.', ST_TEXTDOMAIN), $booking_period), 'danger');
             return;
         }
     } else {
         if ($expired < 0) {
             STTemplate::set_message(__('This tour has expired', ST_TEXTDOMAIN), 'danger');
             $pass_validate = false;
             return;
         }
     }
     if ($pass_validate) {
         $pass_validate = apply_filters('st_tour_add_cart_validate', $pass_validate, $data);
     }
     if ($pass_validate) {
         STCart::add_cart($item_id, $number, $price, $data);
     }
     return $pass_validate;
 }
Пример #10
0
 /**
  * @since 1.0.9
  * @update 1.1.3
  **/
 function do_add_to_cart()
 {
     $pass_validate = true;
     $data_price_cars = json_decode(str_ireplace("\\", '', STInput::request('data_price_cars')));
     $data_price_items = json_decode(str_ireplace("\\", '', STInput::request('data_price_items')));
     $selected_equipments = json_decode(str_ireplace("\\", '', STInput::request('selected_equipments')));
     $discount = STInput::request('discount');
     $price_unit = STInput::request('price');
     $price_old = STInput::request('price_old');
     $item_id = STInput::request('item_id');
     $number = 1;
     $price_total = STInput::request('data_price_total');
     $check_in = $data_price_cars->date_time->pick_up_date . ' ' . $data_price_cars->date_time->pick_up_time;
     $check_in = date('Y-m-d H:i:s', strtotime($check_in));
     $check_out = $data_price_cars->date_time->drop_off_date . ' ' . $data_price_cars->date_time->drop_off_time;
     $check_out = date('Y-m-d H:i:s', strtotime($check_out));
     $data = array('data_price_cars' => $data_price_cars, 'data_price_items' => $data_price_items, 'discount' => $discount, 'price_old' => $price_old, 'check_in' => STInput::request('check_in'), 'check_in_timestamp' => STInput::request('check_in_timestamp'), 'check_out' => STInput::request('check_out'), 'check_out_timestamp' => STInput::request('check_out_timestamp'), 'price_total' => $price_total, 'price_unit' => self::get_price_unit(), 'selected_equipments' => $selected_equipments);
     // Validate required field
     $change_location_date_box = $this->get_search_fields_box();
     $field_types = $this->get_search_fields_name();
     if (!empty($change_location_date_box)) {
         $message = '';
         foreach ($change_location_date_box as $key => $value) {
             if (isset($field_types[$value['field_atrribute']]) and $value['is_required'] == 'on') {
                 $field_name = isset($field_types[$value['field_atrribute']]['field_name']) ? $field_types[$value['field_atrribute']]['field_name'] : false;
                 if ($field_name) {
                     if (is_array($field_name)) {
                         foreach ($field_name as $v) {
                             if (!STInput::request($v)) {
                                 $message .= sprintf(__('%s is required', ST_TEXTDOMAIN), $value['title']) . '<br>';
                                 $pass_validate = false;
                             }
                         }
                     } elseif (is_string($field_name)) {
                         if (!STInput::request($field_name)) {
                             $message .= sprintf(__('%s is required', ST_TEXTDOMAIN), $value['title']) . '<br>';
                             $pass_validate = false;
                         }
                     }
                 }
             }
         }
         if ($message) {
             $message = substr($message, 0, -4);
             STTemplate::set_message($message, 'danger');
         }
     }
     $is_required_country = st()->get_option('is_required_country', 'off');
     if ($is_required_country == 'on') {
         if (STInput::request('county_pick_up') != STInput::request('county_drop_off') or !STInput::request('county_drop_off') or !STInput::request('county_pick_up')) {
             STTemplate::set_message(__('Pick-up and Drop-off are not in the same country. Please re-check it.', ST_TEXTDOMAIN), 'danger');
             $pass_validate = false;
         }
     }
     $today = strtotime(date('m/d/Y', time()));
     $check_in_unix = strtotime(TravelHelper::convertDateFormat($data_price_cars->date_time->pick_up_date));
     $booking_period = intval(get_post_meta($item_id, 'cars_booking_period', true));
     $period = STDate::date_diff($today, $check_in_unix);
     $var = $check_in_unix - $today;
     if ($var < 0) {
         STTemplate::set_message(__('You can not set check-in date in the past'), 'danger');
         $pass_validate = false;
     } else {
         if ($booking_period && $period < $booking_period) {
             STTemplate::set_message(sprintf(__('Booking is only accepted %d day(s) before today.', ST_TEXTDOMAIN), $booking_period), 'danger');
             $pass_validate = false;
         }
     }
     if (!$this->_is_slot_available($item_id, $check_in, $check_out)) {
         STTemplate::set_message(__('Sorry! This Car is not available.', ST_TEXTDOMAIN), 'danger');
         $pass_validate = false;
     }
     //if($pickup)
     // Allow to be filtered
     $pass_validate = apply_filters('st_car_add_cart_validate', $pass_validate, $item_id, $number, $price_unit, $data);
     if ($pass_validate) {
         STCart::add_cart($item_id, $number, $price_unit, $data);
     }
     return $pass_validate;
 }
Пример #11
0
 /**
  *
  *
  * @return Bool
  *
  * */
 static function validate_checkout_fields()
 {
     $fields = self::get_checkout_fields();
     $result = true;
     $validator = new STValidate();
     if (is_array($fields) and !empty($fields)) {
         foreach ($fields as $key => $value) {
             $default = array('label' => '', 'placeholder' => '', 'class' => array('form-control'), 'type' => 'text', 'size' => 6, 'icon' => '', 'validate' => '');
             $value = wp_parse_args($value, $default);
             if ($value['validate']) {
                 $validator->set_rules($key, $value['label'], $value['validate']);
             }
         }
     }
     $result = $validator->run();
     if (!$result) {
         STTemplate::set_message($validator->error_string(), 'danger');
     }
     return $result;
 }
Пример #12
0
 /**
  * @since 1.0.9
  * @update 1.1.3
  **/
 function do_add_to_cart()
 {
     $pass_validate = true;
     $item_id = STInput::request('item_id', '');
     if ($item_id <= 0 || get_post_type($item_id) != 'st_cars') {
         STTemplate::set_message(__('This car is not available.', ST_TEXTDOMAIN), 'danger');
         $pass_validate = FALSE;
         return false;
     }
     $number = 1;
     // Validate required field
     if (!isset($_POST['booking_by']) || $_POST['booking_by'] != 'partner') {
         $change_location_date_box = $this->get_search_fields_box();
         $field_types = $this->get_search_fields_name();
         if (!empty($change_location_date_box)) {
             $message = '';
             foreach ($change_location_date_box as $key => $value) {
                 if (isset($field_types[$value['field_atrribute']]) and $value['is_required'] == 'on') {
                     $field_name = isset($field_types[$value['field_atrribute']]['field_name']) ? $field_types[$value['field_atrribute']]['field_name'] : false;
                     if ($field_name) {
                         if (is_array($field_name)) {
                             foreach ($field_name as $v) {
                                 if (!STInput::request($v)) {
                                     $message .= sprintf(__('%s is required', ST_TEXTDOMAIN), $value['title']) . '<br>';
                                     $pass_validate = false;
                                 }
                             }
                         } elseif (is_string($field_name)) {
                             if (!STInput::request($field_name)) {
                                 $message .= sprintf(__('%s is required', ST_TEXTDOMAIN), $value['title']) . '<br>';
                                 $pass_validate = false;
                             }
                         }
                     }
                 }
             }
             if ($message) {
                 $message = substr($message, 0, -4);
                 STTemplate::set_message($message, 'danger');
             }
         }
     }
     $check_in = '';
     $check_in_n = '';
     $check_in_time = '';
     if (isset($_REQUEST['pick-up-date']) && !empty($_REQUEST['pick-up-date'])) {
         $check_in = TravelHelper::convertDateFormat($_REQUEST['pick-up-date']);
         $check_in_n = $check_in;
     }
     if (isset($_REQUEST['pick-up-time']) && !empty($_REQUEST['pick-up-time'])) {
         $check_in .= ' ' . $_REQUEST['pick-up-time'];
         $check_in_time = $_REQUEST['pick-up-time'];
     }
     $check_in = date('Y-m-d H:i:s', strtotime($check_in));
     $check_out = '';
     $check_out_n = '';
     $check_out_time = '';
     if (isset($_REQUEST['drop-off-date']) && !empty($_REQUEST['drop-off-date'])) {
         $check_out = TravelHelper::convertDateFormat($_REQUEST['drop-off-date']);
         $check_out_n = $check_out;
     }
     if (isset($_REQUEST['drop-off-time']) && !empty($_REQUEST['drop-off-time'])) {
         $check_out .= ' ' . $_REQUEST['drop-off-time'];
         $check_out_time = $_REQUEST['drop-off-time'];
     }
     $check_out = date('Y-m-d H:i:s', strtotime($check_out));
     $location_id_pick_up = STInput::request('location_id_pick_up', '');
     $location_id_drop_off = STInput::request('location_id_drop_off', '');
     if (isset($_REQUEST['location_id_pick_up']) && !empty($_REQUEST['location_id_pick_up']) && isset($_REQUEST['location_id_drop_off']) && !empty($_REQUEST['location_id_drop_off'])) {
         $location_id_pick_up = intval(STInput::request('location_id_pick_up', '0'));
         $location_id_drop_off = intval(STInput::request('location_id_drop_off', '0'));
         $pickup_country = get_post_meta($location_id_pick_up, 'location_country', true);
         $dropoff_country = get_post_meta($location_id_drop_off, 'location_country', true);
         if (!$pickup_country) {
             STTemplate::set_message(__('The \'country\' field not set for the \'' . get_the_title($location_id_pick_up) . '\'', ST_TEXTDOMAIN), 'danger');
             $pass_validate = false;
             return false;
         }
         if (!$dropoff_country) {
             STTemplate::set_message(__('The \'country\' field not set for \'' . get_the_title($location_id_drop_off) . '\'', ST_TEXTDOMAIN), 'danger');
             $pass_validate = false;
             return false;
         }
         if ($pickup_country != $dropoff_country) {
             STTemplate::set_message(__('The country is not same', ST_TEXTDOMAIN), 'danger');
             $pass_validate = false;
             return false;
         }
     }
     $today = date('m/d/Y');
     $booking_period = intval(get_post_meta($item_id, 'cars_booking_period', true));
     $booking_min_day = intval(get_post_meta($item_id, 'cars_booking_min_day', true));
     $booking_min_hour = intval(get_post_meta($item_id, 'cars_booking_min_hour', true));
     if (empty($booking_period) || $booking_period <= 0) {
         $booking_period = 0;
     }
     $check_in_timestamp = '';
     $check_out_timestamp = '';
     if (!empty($check_in_n) && !empty($check_out_n)) {
         $period = TravelHelper::dateDiff($today, $check_in_n);
         $compare = TravelHelper::dateCompare($today, $check_in_n);
         $check_in_timestamp = strtotime($check_in);
         $check_out_timestamp = strtotime($check_out);
         if ($check_in_timestamp - $check_out_timestamp >= 0) {
             STTemplate::set_message(__('The drop off datetime is later than the pick up datetime.', ST_TEXTDOMAIN), 'danger');
             $pass_validate = false;
             return false;
         }
         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 ($period < $booking_period) {
             STTemplate::set_message(sprintf(__('This car allow minimum booking is %d day(s)', ST_TEXTDOMAIN), $booking_period), 'danger');
             $pass_validate = false;
             return false;
         }
         $unit = st()->get_option('cars_price_unit', 'day');
         if ($unit == 'day' and $booking_min_day and $booking_min_day > self::get_date_diff($check_in_timestamp, $check_out_timestamp)) {
             STTemplate::set_message(sprintf(__('Please booking at least %d day(s)', ST_TEXTDOMAIN), $booking_min_day), 'danger');
             $pass_validate = false;
             return false;
         }
         if ($unit == 'hour' and $booking_min_hour and $booking_min_hour > self::get_date_diff($check_in_timestamp, $check_out_timestamp)) {
             STTemplate::set_message(sprintf(__('Please booking at least %d hour(s)', ST_TEXTDOMAIN), $booking_min_hour), 'danger');
             $pass_validate = false;
             return false;
         }
     }
     if ($check_in_timestamp > 0 && $check_out_timestamp > 0) {
         if (!CarHelper::_get_car_cant_order_by_id($item_id, $check_in_timestamp, $check_out_timestamp)) {
             STTemplate::set_message(__('This car is full order', ST_TEXTDOMAIN), 'danger');
             $pass_validate = false;
             return false;
         }
     }
     $selected_equipments = json_decode(str_ireplace("\\", '', STInput::request('selected_equipments', '')));
     $info_price = STCars::get_info_price($item_id, strtotime($check_in), strtotime($check_out));
     $price_unit = $info_price['price'];
     $item_price = floatval(get_post_meta($item_id, 'cars_price', true));
     $price_equipment = STPrice::getPriceEuipmentCar($selected_equipments, $check_in_timestamp, $check_out_timestamp);
     $sale_price = STPrice::getSaleCarPrice($item_id, $item_price, strtotime($check_in), strtotime($check_out));
     $car_sale_price = STPrice::get_car_price_by_number_of_day_or_hour($item_id, $item_price, strtotime($check_in), strtotime($check_out));
     $discount_rate = STPrice::get_discount_rate($item_id, strtotime($check_in));
     $numberday = $numberday = STCars::get_date_diff(strtotime($check_in), strtotime($check_out), st()->get_option('cars_price_unit', 'day'));
     $data = array('check_in' => $check_in_n, 'check_out' => $check_out_n, 'check_in_time' => $check_in_time, 'check_out_time' => $check_out_time, 'check_in_timestamp' => strtotime($check_in), 'check_out_timestamp' => strtotime($check_out), 'location_id_pick_up' => $location_id_pick_up, 'location_id_drop_off' => $location_id_drop_off, 'pick_up' => get_the_title($location_id_pick_up), 'drop_off' => get_the_title($location_id_drop_off), 'ori_price' => $sale_price + $price_equipment, 'item_price' => $item_price, 'sale_price' => $car_sale_price, 'numberday' => $numberday, 'price_equipment' => $price_equipment, 'data_equipment' => $selected_equipments, 'commission' => TravelHelper::get_commission(), 'discount_rate' => $discount_rate);
     $pass_validate = apply_filters('st_car_add_cart_validate', $pass_validate, $item_id, $number, $price_unit, $data);
     if ($pass_validate) {
         STCart::add_cart($item_id, $number, $price_equipment + $sale_price, $data);
     }
     return $pass_validate;
 }
Пример #13
0
 function do_add_to_cart($array = array())
 {
     $pass_validate = TRUE;
     $default = array('item_id' => '', 'number_room' => 1, 'price' => '', 'data_price' => '', 'check_in' => '', 'check_out' => '', 'room_num_search' => '', 'room_id' => '', 'adult_num' => 1, 'child_num' => 0);
     $array = wp_parse_args($array, $default);
     extract($array);
     $data = array('check_in' => $check_in, 'check_out' => $check_out, 'data_price' => $data_price, 'currency' => TravelHelper::get_default_currency('symbol'), 'room_num_search' => $room_num_search, 'room_id' => $room_id, 'room_data' => array(), 'adult_num' => $adult_num, 'child_num' => $child_num);
     if (empty($check_in)) {
         STTemplate::set_message(__('Date is invalid', ST_TEXTDOMAIN), 'danger');
         $pass_validate = FALSE;
     }
     if (empty($check_out)) {
         STTemplate::set_message(__('Date is invalid', ST_TEXTDOMAIN), 'danger');
         $pass_validate = FALSE;
     }
     $num_room = intval(get_post_meta($room_id, 'number_room', true));
     $adult = intval(get_post_meta($room_id, 'adult_number', true));
     $children = intval(get_post_meta($room_id, 'children_number', true));
     if ($room_num_search > $num_room) {
         STTemplate::set_message(__('Max of rooms are incorrect.', ST_TEXTDOMAIN), 'danger');
         $pass_validate = FALSE;
     }
     if ($adult_num > $adult) {
         STTemplate::set_message(__('Number of adults in the room are incorrect.', ST_TEXTDOMAIN), 'danger');
         $pass_validate = FALSE;
     }
     if ($child_num > $children) {
         STTemplate::set_message(__('Number of children in the room are incorrect.', ST_TEXTDOMAIN), 'danger');
         $pass_validate = FALSE;
     }
     if (!$this->_is_slot_available($room_id, $check_in, $check_out)) {
         STTemplate::set_message(__('Sorry! This Room is not available.', ST_TEXTDOMAIN), 'danger');
         $pass_validate = FALSE;
     }
     $today = date('m/d/Y');
     $booking_period = $this->is_booking_period($item_id, $today, $check_in);
     if ($booking_period) {
         STTemplate::set_message(sprintf(__('Booking is only accepted %d day(s) before today.', ST_TEXTDOMAIN), $booking_period), 'danger');
         $pass_validate = FALSE;
     }
     if ($pass_validate) {
         $pass_validate = apply_filters('st_hotel_add_cart_validate', $pass_validate, $array);
     }
     if ($pass_validate) {
         STCart::add_cart($item_id, $number_room, $price, $data);
     }
     return $pass_validate;
 }