Exemplo n.º 1
0
 function do_add_to_cart()
 {
     $form_validate = TRUE;
     $item_id = intval(STInput::request('item_id', ''));
     if ($item_id <= 0 || get_post_type($item_id) != 'st_rental') {
         STTemplate::set_message(__('This rental is not available.', ST_TEXTDOMAIN), 'danger');
         $form_validate = FALSE;
         return false;
     }
     $check_in = STInput::request('start', '');
     if (empty($check_in)) {
         STTemplate::set_message(__('The check in field is not empty.', ST_TEXTDOMAIN), 'danger');
         $form_validate = FALSE;
         return false;
     }
     $check_in = TravelHelper::convertDateFormat($check_in);
     $check_out = STInput::request('end', '');
     if (empty($check_out)) {
         STTemplate::set_message(__('The check out field is not empty.', ST_TEXTDOMAIN), 'danger');
         $form_validate = FALSE;
         return false;
     }
     $check_out = TravelHelper::convertDateFormat($check_out);
     $today = date('m/d/Y');
     $booking_period = get_post_meta($item_id, 'rentals_booking_period', true);
     if (empty($booking_period) || $booking_period <= 0) {
         $booking_period = 0;
     }
     $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');
         $form_validate = FALSE;
         return false;
     }
     if ($period < $booking_period) {
         STTemplate::set_message(sprintf(__('This rental allow minimum booking is %d day(s)', ST_TEXTDOMAIN), $booking_period), 'danger');
         $form_validate = FALSE;
         return false;
     }
     $adult_number = intval(STInput::request('adult_number', ''));
     $child_number = intval(STInput::request('child_number', ''));
     $max_adult = intval(get_post_meta($item_id, 'rental_max_adult', true));
     $max_children = intval(get_post_meta($item_id, 'rental_max_children', true));
     if ($adult_number > $max_adult) {
         STTemplate::set_message(sprintf(__('A maximum number of adult(s): %d', ST_TEXTDOMAIN), $max_adult), 'danger');
         $form_validate = FALSE;
         return false;
     }
     if ($child_number > $max_children) {
         STTemplate::set_message(sprintf(__('A maximum number of children: %d', ST_TEXTDOMAIN), $max_children), 'danger');
         $form_validate = FALSE;
         return false;
     }
     $number_room = intval(get_post_meta($item_id, 'rental_number', true));
     $check_in_tmp = date('Y-m-d', strtotime($check_in));
     $check_out_tmp = date('Y-m-d', strtotime($check_out));
     if (!RentalHelper::check_day_cant_order($item_id, $check_in_tmp, $check_out_tmp, 1)) {
         STTemplate::set_message(sprintf(__('This rental is not available from %s to %s.', ST_TEXTDOMAIN), $check_in_tmp, $check_out_tmp), 'danger');
         $pass_validate = FALSE;
         return false;
     }
     if (!RentalHelper::_check_room_available($item_id, $check_in_tmp, $check_out_tmp, 1)) {
         STTemplate::set_message(__('This rental is not available.', ST_TEXTDOMAIN), 'danger');
         $pass_validate = FALSE;
         return false;
     }
     $item_price = STPrice::getRentalPriceOnlyCustomPrice($item_id, strtotime($check_in), strtotime($check_out));
     $extras = STInput::request('extra_price', array());
     $numberday = TravelHelper::dateDiff($check_in, $check_out);
     $extra_price = STPrice::getExtraPrice($extras, 1, $numberday);
     $price_sale = STPrice::getSalePrice($item_id, $item_price, strtotime($check_in), strtotime($check_out));
     $discount_rate = STPrice::get_discount_rate($item_id, strtotime($check_in));
     $data = array('item_price' => $item_price, 'ori_price' => $price_sale + $extra_price, 'check_in' => $check_in, 'check_out' => $check_out, 'adult_number' => $adult_number, 'child_number' => $child_number, 'extras' => $extras, 'extra_price' => $extra_price, 'commission' => TravelHelper::get_commission(), 'discount_rate' => $discount_rate);
     if ($form_validate) {
         $form_validate = apply_filters('st_rental_add_cart_validate', $form_validate);
     }
     if ($form_validate) {
         STCart::add_cart($item_id, 1, $item_price, $data);
     }
     return $form_validate;
 }
Exemplo n.º 2
0
 function _add_booking()
 {
     if (!check_admin_referer('shb_action', 'shb_field')) {
         die;
     }
     $data = $this->_check_validate();
     if (is_array($data) && count($data)) {
         extract($data);
         $order = array('post_title' => __('Order', ST_TEXTDOMAIN) . ' - ' . date(get_option('date_format')) . ' @ ' . date(get_option('time_format')), 'post_type' => 'st_order', 'post_status' => 'publish');
         $order_id = wp_insert_post($order);
         if ($order_id) {
             $check_out_field = STCart::get_checkout_fields();
             if (!empty($check_out_field)) {
                 foreach ($check_out_field as $field_name => $field_desc) {
                     update_post_meta($order_id, $field_name, STInput::post($field_name));
                 }
             }
             $id_user = get_current_user_id();
             update_post_meta($order_id, 'id_user', $id_user);
             update_post_meta($order_id, 'payment_method', 'st_submit_form');
             $item_price = STPrice::getRentalPriceOnlyCustomPrice($item_id, strtotime($check_in), strtotime($check_out));
             $numberday = TravelHelper::dateDiff($check_in, $check_out);
             $origin_price = $item_price;
             //Extra price
             $extras = STInput::request('extra_price', array());
             $extra_price = STPrice::getExtraPrice($extras, $room_num_search, $numberday);
             $sale_price = STPrice::getSalePrice($item_id, $item_price, strtotime($check_in), strtotime($check_out));
             $price_with_tax = STPrice::getPriceWithTax($sale_price + $extra_price);
             $deposit_money['data'] = array();
             $deposit_money = STPrice::getDepositData($item_id, $deposit_money);
             $deposit_price = STPrice::getDepositPrice($deposit_money['data']['deposit_money'], $price_with_tax, 0);
             if (isset($deposit_money['data']['deposit_money'])) {
                 $total_price = $deposit_price;
             } else {
                 $total_price = $price_with_tax;
             }
             $data_prices = array('origin_price' => $origin_price, 'sale_price' => $sale_price, 'coupon_price' => 0, 'price_with_tax' => $price_with_tax, 'total_price' => $total_price, 'deposit_price' => $deposit_price);
             $item_data = array('item_number' => 1, 'item_id' => $item_id, 'item_price' => $item_price, 'check_in' => $check_in, 'check_out' => $check_out, 'adult_number' => $adult_number, 'child_number' => $child_number, 'total_price' => $total_price, 'data_prices' => $data_prices, 'deposit_money' => $deposit_money['data']['deposit_money'], 'booking_by' => 'admin', 'st_tax' => STPrice::getTax(), 'st_tax_percent' => STPrice::getTax(), 'status' => $_POST['status'], 'currency' => TravelHelper::get_current_currency('symbol'), 'currency_rate' => TravelHelper::get_current_currency('rate'), 'extras' => $extras, 'extra_price' => $extra_price, 'commission' => TravelHelper::get_commission());
             foreach ($item_data as $val => $value) {
                 update_post_meta($order_id, $val, $value);
             }
             if (TravelHelper::checkTableDuplicate('st_rental')) {
                 global $wpdb;
                 $table = $wpdb->prefix . 'st_order_item_meta';
                 $g_post = get_post($item_id);
                 $partner_id = $g_post ? $g_post->post_author : '';
                 global $sitepress;
                 if ($sitepress) {
                     $post_type = get_post_type($st_booking_id);
                     if ($post_type == 'st_hotel') {
                         $post_type = 'hotel_room';
                         $id = $room_id;
                     } else {
                         $id = $st_booking_id;
                     }
                     $lang_code = $sitepress->get_default_language();
                     $origin_id = icl_object_id($id, $post_type, true, $lang_code);
                 } else {
                     $origin_id = $st_booking_id;
                 }
                 $data = array('order_item_id' => $order_id, 'type' => 'normal_booking', 'check_in' => $check_in, 'check_out' => $check_out, 'st_booking_post_type' => 'st_rental', 'st_booking_id' => $item_id, 'adult_number' => $adult_number, 'child_number' => $child_number, 'check_in_timestamp' => strtotime($check_in), 'check_out_timestamp' => strtotime($check_out), 'room_num_search' => $room_num_search, 'user_id' => $id_user, 'status' => $_POST['status'], 'wc_order_id' => $order_id, 'partner_id' => $partner_id, 'created' => get_the_date('Y-m-d', $order_id), 'total_order' => $total_price, 'commission' => TravelHelper::get_commission(), 'origin_id' => $origin_id);
                 $wpdb->insert($table, $data);
             }
             do_action('st_booking_success', $order_id);
             //Check email
             $user_name = STInput::post('st_email');
             $user_id = username_exists($user_name);
             if (!$user_id and email_exists($user_name) == false) {
                 $random_password = wp_generate_password($length = 12, $include_standard_special_chars = false);
                 $userdata = array('user_login' => $user_name, 'user_pass' => $random_password, 'user_email' => $user_name, 'first_name' => STInput::post('st_first_name'), 'last_name' => STInput::post('st_last_name'));
                 $user_id = wp_insert_user($userdata);
                 wp_new_user_notification($user_id);
             }
             STCart::send_mail_after_booking($order_id, true);
             STCart::send_email_confirm($order_id);
             wp_safe_redirect(self::$booking_page);
         }
     }
 }
Exemplo n.º 3
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;
 }